diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index 010ee06f6..e9740a71d 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -469,6 +469,7 @@ SET(gm_commands gm_commands/reloadworld.cpp gm_commands/reloadworldrules.cpp gm_commands/reloadzps.cpp + gm_commands/removeitem.cpp gm_commands/repop.cpp gm_commands/resetaa.cpp gm_commands/resetaa_timer.cpp diff --git a/zone/command.cpp b/zone/command.cpp index e4167b167..815336719 100755 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -305,6 +305,7 @@ int command_init(void) command_add("reloadtitles", "- Reload player titles from the database", AccountStatus::GMLeadAdmin, command_reloadtitles) || command_add("reloadworld", "[0|1] - Clear quest cache (0 - no repop, 1 - repop)", AccountStatus::Max, command_reloadworld) || command_add("reloadzps", "- Reload zone points from database", AccountStatus::GMLeadAdmin, command_reloadzps) || + command_add("removeitem", "[Item ID] [Amount] - Removes the specified Item ID by Amount from you or your player target's inventory (Amount defaults to 1 if not used)", AccountStatus::GMAdmin, command_removeitem) || command_add("repop", "[delay] - Repop the zone with optional delay", AccountStatus::GMAdmin, command_repop) || command_add("resetaa", "- Resets a Player's AA in their profile and refunds spent AA's to unspent, may disconnect player.", AccountStatus::GMMgmt, command_resetaa) || command_add("resetaa_timer", "Command to reset AA cooldown timers.", AccountStatus::GMMgmt, command_resetaa_timer) || diff --git a/zone/command.h b/zone/command.h index 0abb1ae7c..9ff50140f 100644 --- a/zone/command.h +++ b/zone/command.h @@ -226,6 +226,7 @@ void command_reloadtraps(Client *c, const Seperator *sep); void command_reloadworld(Client *c, const Seperator *sep); void command_reloadworldrules(Client *c, const Seperator *sep); void command_reloadzps(Client *c, const Seperator *sep); +void command_removeitem(Client *c, const Seperator *sep); void command_repop(Client *c, const Seperator *sep); void command_resetaa(Client *c, const Seperator *sep); void command_resetaa_timer(Client *c, const Seperator *sep); diff --git a/zone/gm_commands/removeitem.cpp b/zone/gm_commands/removeitem.cpp new file mode 100644 index 000000000..6285e65d4 --- /dev/null +++ b/zone/gm_commands/removeitem.cpp @@ -0,0 +1,85 @@ +#include "../client.h" + +void command_removeitem(Client *c, const Seperator *sep) +{ + int arguments = sep->argnum; + if (!arguments || !sep->IsNumber(1)) { + c->Message(Chat::White, "Usage: #removeitem [Item ID] [Amount]"); + return; + } + + Client *target = c; + if (c->GetTarget() && c->GetTarget()->IsClient()) { + target = c->GetTarget()->CastToClient(); + } + + auto target_string = ( + c == target ? + "yourself" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ); + + auto item_id = std::stoi(sep->arg[1]); + if (!database.GetItem(item_id)) { + c->Message( + Chat::White, + fmt::format( + "Item ID {} could not be found.", + item_id + ).c_str() + ); + return; + } + + auto item_link = database.CreateItemLink(item_id); + auto amount = sep->IsNumber(2) ? std::stoul(sep->arg[2]) : 1; + auto item_count = target->CountItem(item_id); + if (item_count) { + if (item_count >= amount) { + target->RemoveItem(item_id, amount); + + c->Message( + Chat::White, + fmt::format( + "Removed {} {} ({}) from {}.", + amount, + item_link, + item_id, + target_string + ).c_str() + ); + } else { + target->RemoveItem(item_id, item_count); + + c->Message( + Chat::White, + fmt::format( + "Removed {} {} ({}) from {} because {} did not have {} {} ({}).", + item_count, + item_link, + item_id, + target_string, + c == target ? "you" : "they", + amount, + item_link, + item_id + ).c_str() + ); + } + } else { + c->Message( + Chat::White, + fmt::format( + "Could not find any {} ({}) to delete from {}.", + database.CreateItemLink(item_id), + item_id, + target_string + ).c_str() + ); + } +} +