[Commands] Cleanup #setfaction Command. (#1792)

- Cleanup message and logic.
- Doesn't allow you to use invalid faction IDs anymore.
This commit is contained in:
Kinglykrab 2021-11-21 10:11:03 -05:00 committed by GitHub
parent d73194c1f6
commit 51fb46556d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 11 deletions

View File

@ -323,7 +323,7 @@ int command_init(void)
command_add("setadventurepoints", "- Set your or your player target's available adventure points", AccountStatus::GMLeadAdmin, command_set_adventure_points) || command_add("setadventurepoints", "- Set your or your player target's available adventure points", AccountStatus::GMLeadAdmin, command_set_adventure_points) ||
command_add("setanim", "[Animation ID (IDs are 0 to 4)] - Set target's appearance to Animation ID", AccountStatus::GMMgmt, command_setanim) || command_add("setanim", "[Animation ID (IDs are 0 to 4)] - Set target's appearance to Animation ID", AccountStatus::GMMgmt, command_setanim) ||
command_add("setcrystals", "[value] - Set your or your player target's available radiant or ebon crystals", AccountStatus::GMAdmin, command_setcrystals) || command_add("setcrystals", "[value] - Set your or your player target's available radiant or ebon crystals", AccountStatus::GMAdmin, command_setcrystals) ||
command_add("setfaction", "[faction number] - Sets targeted NPC's faction in the database", AccountStatus::GMAreas, command_setfaction) || command_add("setfaction", "[Faction ID] - Sets targeted NPC's faction in the database", AccountStatus::GMAreas, command_setfaction) ||
command_add("setgraveyard", "[zone name] - Creates a graveyard for the specified zone based on your target's LOC.", AccountStatus::GMMgmt, command_setgraveyard) || command_add("setgraveyard", "[zone name] - Creates a graveyard for the specified zone based on your target's LOC.", AccountStatus::GMMgmt, command_setgraveyard) ||
command_add("setlanguage", "[language ID] [value] - Set your target's language skillnum to value", AccountStatus::Guide, command_setlanguage) || command_add("setlanguage", "[language ID] [value] - Set your target's language skillnum to value", AccountStatus::Guide, command_setlanguage) ||
command_add("setlsinfo", "[email] [password] - Set login server email address and password (if supported by login server)", AccountStatus::Steward, command_setlsinfo) || command_add("setlsinfo", "[email] [password] - Set login server email address and password (if supported by login server)", AccountStatus::Steward, command_setlsinfo) ||

View File

@ -2,19 +2,50 @@
void command_setfaction(Client *c, const Seperator *sep) void command_setfaction(Client *c, const Seperator *sep)
{ {
if ((sep->arg[1][0] == 0 || strcasecmp(sep->arg[1], "*") == 0) || int arguments = sep->argnum;
((c->GetTarget() == 0) || (c->GetTarget()->IsClient()))) { if (!arguments || !sep->IsNumber(1)) {
c->Message(Chat::White, "Usage: #setfaction [faction number]"); c->Message(Chat::White, "Usage: #setfaction [Faction ID]");
return;
}
if (
!c->GetTarget() ||
(
c->GetTarget() &&
c->GetTarget()->IsClient()
)
) {
c->Message(Chat::White, "You must target an NPC to use this command.");
return; return;
} }
auto npcTypeID = c->GetTarget()->CastToNPC()->GetNPCTypeID(); NPC* target = c->GetTarget()->CastToNPC();
c->Message(Chat::Yellow, "Setting NPC %u to faction %i", npcTypeID, atoi(sep->argplus[1])); auto npc_id = target->GetNPCTypeID();
auto faction_id = std::stoi(sep->arg[1]);
auto faction_name = content_db.GetFactionName(faction_id);
if (!faction_name.empty()) {
c->Message(
Chat::White,
fmt::format(
"Faction Changed | Name: {} ({}) Faction: {} ({}).",
target->GetCleanName(),
npc_id,
content_db.GetFactionName(faction_id),
faction_id
).c_str()
);
std::string query = StringFormat( std::string query = fmt::format(
"UPDATE npc_types SET npc_faction_id = %i WHERE id = %i", "UPDATE npc_types SET npc_faction_id = {} WHERE id = {}",
atoi(sep->argplus[1]), npcTypeID faction_id,
); npc_id
content_db.QueryDatabase(query); );
content_db.QueryDatabase(query);
} else {
c->Message(
Chat::White,
"Invalid Faction ID, please specify a valid Faction ID."
);
}
} }