mirror of
https://github.com/EQEmu/Server.git
synced 2026-09-01 11:36:36 +00:00
[Commands] Add #countitem Command. (#1842)
* [Commands] Add #countitem Command. - Add #countitem [Item ID] command to count an item by ID on yourself or your player/NPC target. * Cleanup.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
#include "../client.h"
|
||||
|
||||
void command_countitem(Client *c, const Seperator *sep)
|
||||
{
|
||||
int arguments = sep->argnum;
|
||||
if (!arguments || !sep->IsNumber(1)) {
|
||||
c->Message(Chat::White, "Usage: #countitem [Item ID]");
|
||||
return;
|
||||
}
|
||||
|
||||
Mob* target = c;
|
||||
if (
|
||||
c->GetTarget() &&
|
||||
(
|
||||
c->GetTarget()->IsClient() ||
|
||||
c->GetTarget()->IsNPC()
|
||||
)
|
||||
) {
|
||||
target = c->GetTarget();
|
||||
}
|
||||
|
||||
auto item_id = std::stoul(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;
|
||||
}
|
||||
|
||||
uint16 item_count = 0;
|
||||
if (target->IsClient()) {
|
||||
item_count = target->CastToClient()->CountItem(item_id);
|
||||
} else if (target->IsNPC()) {
|
||||
item_count = target->CastToNPC()->CountItem(item_id);
|
||||
}
|
||||
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"{} {} {} {}.",
|
||||
(
|
||||
c == target ?
|
||||
"You" :
|
||||
fmt::format(
|
||||
"{} ({})",
|
||||
target->GetCleanName(),
|
||||
target->GetID()
|
||||
)
|
||||
),
|
||||
c == target ? "have" : "has",
|
||||
(
|
||||
item_count ?
|
||||
std::to_string(item_count) :
|
||||
"no"
|
||||
),
|
||||
database.CreateItemLink(item_id)
|
||||
).c_str()
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user