fix(Scripts/Command): Allow player name/guid in additem

This commit is contained in:
Kitzunu
2023-12-01 01:07:39 +01:00
parent 123bf37ee7
commit a8b57200b6
2 changed files with 16 additions and 18 deletions

View File

@@ -0,0 +1,2 @@
--
UPDATE `command` SET `help`='Syntax: .additem Optional(playerName/playerGUID) #itemID/[#itemName]/#itemLink #itemCount\r\nAdds the specified item to you, the selected character or the specifed character name/GUID.\r\nIf #itemCount is negative, you will remove #itemID.' WHERE `name`='additem';

View File

@@ -1661,7 +1661,7 @@ public:
return true;
}
static bool HandleAddItemCommand(ChatHandler* handler, ItemTemplate const* itemTemplate, Optional<int32> _count)
static bool HandleAddItemCommand(ChatHandler* handler, Optional<PlayerIdentifier> player, ItemTemplate const* itemTemplate, Optional<int32> _count)
{
if (!sObjectMgr->GetItemTemplate(itemTemplate->ItemId))
{
@@ -1674,22 +1674,21 @@ public:
int32 count = 1;
if (_count)
{
count = *_count;
}
if (!count)
{
count = 1;
}
Player* player = handler->GetSession()->GetPlayer();
Player* playerTarget = handler->getSelectedPlayer();
if (!player)
player = PlayerIdentifier::FromTargetOrSelf(handler);
if (!player)
return false;
Player* playerTarget = player->GetConnectedPlayer();
if (!playerTarget)
{
playerTarget = player;
}
return false;
// Subtract
if (count < 0)
@@ -1728,9 +1727,7 @@ public:
InventoryResult msg = playerTarget->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount);
if (msg != EQUIP_ERR_OK) // convert to possible store amount
{
count -= noSpaceForCount;
}
if (!count || dest.empty()) // can't add any
{
@@ -1741,12 +1738,13 @@ public:
Item* item = playerTarget->StoreNewItem(dest, itemId, true);
Player* p = handler->GetSession()->GetPlayer();
// remove binding (let GM give it to another player later)
if (player == playerTarget)
if (p == playerTarget)
{
for (auto const& itemPos : dest)
{
if (Item* item1 = player->GetItemByPos(itemPos.pos))
if (Item* item1 = p->GetItemByPos(itemPos.pos))
{
item1->SetBinding(false);
}
@@ -1755,18 +1753,16 @@ public:
if (count && item)
{
player->SendNewItem(item, count, false, true);
p->SendNewItem(item, count, false, true);
if (player != playerTarget)
if (p != playerTarget)
{
playerTarget->SendNewItem(item, count, true, false);
}
}
if (noSpaceForCount)
{
handler->PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
}
return true;
}