Resource icon

3.3.5 TC List Inventory Command 1.0

Lists Players Inventory

Kearu

Divine
Divine
Rep
1
0
0
Rep
1
Vouches
0
0
0
Vouches
0
Posts
139
Likes
81
2 YEARS
2 YEARS OF SERVICE
LEVEL 3 120 XP
Kearu submitted a new resource:

3.3.5 TC List Inventory Command - Lists Players Inventory

This is written for TC 3.3.5, may work on other cores but might need some tweaking.
Lists a characters Inventory, if character is online it will list (Equipment, Bag slots, Bank Slots and Currencies). If offline, it will also list Key Ring Slots since I didn't really see a need for it.

Type ".list inventory" while targeting a player, or ".list inventory <name>" without the <>. Works with Command Console but I was lazy and didn't have it add the Item Entry for...

Read more about this resource...
 

RedLine

Divine
Divine
RedLine Rep
0
0
0
Rep
0
RedLine Vouches
0
0
0
Vouches
0
Posts
74
Likes
28
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 4 205 XP
I think I was the first one to test this:TriKool:
 
Liked By 1 member :

Etox

Gamer | Noob
Divine
Etox Rep
4
0
0
Rep
4
Etox Vouches
0
0
0
Vouches
0
Posts
198
Likes
165
2 YEARS
2 YEARS OF SERVICE
LEVEL 5 70 XP
Really nice! Good job c:
 

JadaDev

reaper-wow.com
Legend
JadaDev Rep
5
0
0
Rep
5
JadaDev Vouches
0
0
0
Vouches
0
Posts
514
Likes
509
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 11 100 XP
This is actually amazing, good job man!
 

splicho

Emudevs Founder
Administrator
splicho Rep
6
0
0
Rep
6
splicho Vouches
3
0
0
Vouches
3
Posts
985
Likes
1,421
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 248 85 XP

Tommy

Staff
Staff
Tommy Rep
1
0
0
Rep
1
Tommy Vouches
0
0
0
Vouches
0
Posts
185
Likes
101
2 YEARS
2 YEARS OF SERVICE
LEVEL 6 310 XP
Great release!
 

Darksoke

Well-known member
Darksoke Rep
1
0
0
Rep
1
Darksoke Vouches
0
0
0
Vouches
0
Posts
58
Likes
69
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 2 50 XP
You can save a bit of memory if the player is online in just a couple lines

Well for this loop you can use any of the following starting points 0, EQUIPMENT_SLOT_START or PLAYER_SLOT_START;

C++:
for (uint8 i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_BAG_0; i++) {
    if (Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i)) {
        // Do your stuff using player->GetItemCount(uint32 item, bool inBankAlso = false, Item* skipItem = nullptr)
        // item->GetEntry() to get the item entry and the rest is kinda self explanatory
    }
}
 
Liked By 2 members :

Kearu

Divine
Divine
Rep
1
0
0
Rep
1
Vouches
0
0
0
Vouches
0
Posts
139
Likes
81
2 YEARS
2 YEARS OF SERVICE
LEVEL 3 120 XP
You can save a bit of memory if the player is online in just a couple lines

Well for this loop you can use any of the following starting points 0, EQUIPMENT_SLOT_START or PLAYER_SLOT_START;

C++:
for (uint8 i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_BAG_0; i++) {
    if (Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i)) {
        // Do your stuff using player->GetItemCount(uint32 item, bool inBankAlso = false, Item* skipItem = nullptr)
        // item->GetEntry() to get the item entry and the rest is kinda self explanatory
    }
}

The issue with using player->GetItemCount() would be I would either have to store each items entry that I find so it doesn't get reported for each stack of that item. But I can remove a few of the for loops and just use 3 instead, since it doesn't list the items inside bags in the bank or inventory. Just would run into the same issue of having a ton of if statements to determine the location which isn't really needed but I kind of like it. I greatly appreciate the feedback, I did end up changing how it gets the item by position, since (Bag, Ctr) is much easier to read and more understandable then (Bag << 8) | Ctr)). Have also added the Entry of Items for Console Output.
 

Reloac

Active member
Reloac Rep
2
0
0
Rep
2
Reloac Vouches
0
0
0
Vouches
0
Posts
42
Likes
31
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 1 55 XP
Suggested changes: Untested
C++:
    static bool HandleListInventoryCommand(ChatHandler* handler, Optional<PlayerIdentifier> targetIdentifier)
    {
        if (!targetIdentifier)
            targetIdentifier = PlayerIdentifier::FromTarget(handler);
        if (!targetIdentifier)
        {
            handler->PSendSysMessage("Syntax: .list inventory [$playername]|nOutputs a list of character with $playername (or selected if name not provided) Inventory.");
            return true;
        }
       
        Player* target = targetIdentifier->GetConnectedPlayer();

        // check if target is ingame
        if (target)
        {
            std::string Output = target->GetSession()->GetPlayerInfo();

            for (uint8 i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_ITEM_END; i++)
                if (Item* pItem = target->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
                    handler->PSendSysMessage("%s%sx%u - %s", Output.c_str(), (handler->IsConsole() ? "[" + std::to_string(pItem->GetEntry()) + "] [" + pItem->GetTemplate()->Name1 + "]" : pItem->GetItemLink()), pItem->GetCount(), i >= INVENTORY_SLOT_BAG_END ? "Bag" : "Equipped");

            for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
                for (uint8 j = 0; j < MAX_BAG_SIZE; j++)
                    if (Item* pItem = target->GetItemByPos(((i << 8) | j)))
                        handler->PSendSysMessage("%s%sx%u - Bag", Output.c_str(), (handler->IsConsole() ? "[" + std::to_string(pItem->GetEntry()) + "] [" + pItem->GetTemplate()->Name1 + "]" : pItem->GetItemLink()), pItem->GetCount());

            for (uint8 i = BANK_SLOT_ITEM_START; i < BANK_SLOT_ITEM_END; i++)
                if (Item* pItem = target->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
                    handler->PSendSysMessage("%s%sx%u - Bank", Output.c_str(), (handler->IsConsole() ? "[" + std::to_string(pItem->GetEntry()) + "] [" + pItem->GetTemplate()->Name1 + "]" : pItem->GetItemLink()), pItem->GetCount());

            for (uint8 i = BANK_SLOT_BAG_START; i < BANK_SLOT_BAG_END; i++)
                if (Item* pItem = target->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
                {
                    handler->PSendSysMessage("%s%sx%u - Bank", Output.c_str(), (handler->IsConsole() ? "[" + std::to_string(pItem->GetEntry()) + "] [" + pItem->GetTemplate()->Name1 + "]" : pItem->GetItemLink()), pItem->GetCount());

                    for (uint8 j = 0; j < MAX_BAG_SIZE; j++)
                        if (Item* pItem2 = target->GetItemByPos(i, j))
                            handler->PSendSysMessage("%s%sx%u - Bank", Output.c_str(), (handler->IsConsole() ? "[" + std::to_string(pItem->GetEntry()) + "] [" + pItem2->GetTemplate()->Name1 + "]" : pItem2->GetItemLink()), pItem2->GetCount());
                }

            for (uint8 i = CURRENCYTOKEN_SLOT_START; i < CURRENCYTOKEN_SLOT_END; i++)
                if (Item* pItem = target->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
                    handler->PSendSysMessage("%s%sx%u - Currency", Output.c_str(), (handler->IsConsole() ? "[" + std::to_string(pItem->GetEntry()) + "][" + pItem->GetTemplate()->Name1 + "]" : pItem->GetItemLink()), pItem->GetCount());
        }
        else // otherwise db lookup
        {
            CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_INVENTORY);
            stmt->setUInt32(0, targetIdentifier->GetGUID().GetCounter());
            PreparedQueryResult queryResult = CharacterDatabase.Query(stmt);
            if (queryResult)
            {
                do
                {
                    Field* fields = queryResult->Fetch();

                    Item* item = nullptr;
                    ObjectGuid::LowType bagGuid  = fields[11].GetUInt32();
                    uint8  slot                  = fields[12].GetUInt8();
                    ObjectGuid::LowType itemGuid = fields[13].GetUInt32();
                    uint32 itemEntry             = fields[14].GetUInt32();

                    if (ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemEntry))
                    {
                        item = NewItemOrBag(proto);

                        if (!item->LoadFromDB(itemGuid, targetIdentifier->GetGUID(), fields, itemEntry))
                        {
                            delete item;
                            continue;
                        }

                        std::ostringstream ItemLink;
                        if (!handler->IsConsole())
                            ItemLink << item->GetItemLink();
                        else
                            ItemLink << "[" << itemEntry << "] [" << proto->Name1 << "]";

                        handler->PSendSysMessage("GUID %u: %s has %sx%u", targetIdentifier->GetGUID().GetCounter(), targetIdentifier->GetName().c_str(), ItemLink.str().c_str(), item->GetCount());
                        delete item;
                    }
                } while (queryResult->NextRow());
            }
            else
                handler->PSendSysMessage("Player %s not found, or doesn't have any items.", targetIdentifier->GetName().c_str());
        }

        return true;
    }
 

Reloac

Active member
Reloac Rep
2
0
0
Rep
2
Reloac Vouches
0
0
0
Vouches
0
Posts
42
Likes
31
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 1 55 XP
You can save a bit of memory if the player is online in just a couple lines

Well for this loop you can use any of the following starting points 0, EQUIPMENT_SLOT_START or PLAYER_SLOT_START;

C++:
for (uint8 i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_BAG_0; i++) {
    if (Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i)) {
        // Do your stuff using player->GetItemCount(uint32 item, bool inBankAlso = false, Item* skipItem = nullptr)
        // item->GetEntry() to get the item entry and the rest is kinda self explanatory
    }
}
How is this saving memory? GetItemCount searches everything again.
 
Liked By 1 member :

3,382

1,252

9,529

410

Top