[Commands] Cleanup #getvariable Command. (#2100)

- Cleanup messages and logic.
This commit is contained in:
Kinglykrab 2022-05-03 23:05:02 -04:00 committed by GitHub
parent b2b87ea4e0
commit e08afb1234
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 6 deletions

View File

@ -192,7 +192,7 @@ int command_init(void)
command_add("gearup", "Developer tool to quickly equip a character", AccountStatus::GMMgmt, command_gearup) ||
command_add("gender", "[0/1/2] - Change your or your target's gender to male/female/neuter", AccountStatus::Guide, command_gender) ||
command_add("getplayerburiedcorpsecount", "- Get your or your target's total number of buried player corpses.", AccountStatus::GMAdmin, command_getplayerburiedcorpsecount) ||
command_add("getvariable", "[varname] - Get the value of a variable from the database", AccountStatus::GMMgmt, command_getvariable) ||
command_add("getvariable", "[Variable Name] - Get the value of a variable from the database", AccountStatus::GMMgmt, command_getvariable) ||
command_add("ginfo", "- get group info on target.", AccountStatus::ApprenticeGuide, command_ginfo) ||
command_add("giveitem", "[itemid] [charges] - Summon an item onto your target's cursor. Charges are optional.", AccountStatus::GMMgmt, command_giveitem) ||
command_add("givemoney", "[Platinum] [Gold] [Silver] [Copper] - Gives specified amount of money to you or your player target", AccountStatus::GMMgmt, command_givemoney) ||

View File

@ -2,12 +2,30 @@
void command_getvariable(Client *c, const Seperator *sep)
{
std::string tmp;
if (database.GetVariable(sep->argplus[1], tmp)) {
c->Message(Chat::White, "%s = %s", sep->argplus[1], tmp.c_str());
std::string variable = sep->argplus[1];
if (variable.empty()) {
c->Message(Chat::White, "Usage: #getvariable [Variable Name]");
return;
}
else {
c->Message(Chat::White, "GetVariable(%s) returned false", sep->argplus[1]);
std::string message;
std::string value;
if (database.GetVariable(variable, value)) {
message = fmt::format(
"Variable {}: {}",
variable,
value
);
} else {
message = fmt::format(
"Variable '{}' does not exist.",
variable
);
}
c->Message(
Chat::White,
message.c_str()
);
}