[DE|EN] Rucksack - Backpack - Bag* Item::GetContainer(void)

Hallo,

versuche seit einiger Zeit den Rucksack auszulesen (Item* Player::GetItemByPos(uint8 bag, uint8 slot) const), jedoch finde ich den Standard-Rucksack mit den 16 Plätzen nicht…

Könnte mir da jemand weiterhelfen ?

Hello,

I’m trying since a while to get all the items from the backpack (Item* Player::GetItemByPos(uint8 bag, uint8 slot) const), sadly I’m unable to find the backpack with the 16 slots…

Could someone help me with it ?

Test code - for now just trying to get the Item pointer.

bool OnUse(Player *pUser, Item *pItem, const SpellCastTargets &pTarget) override
std::vector<std::pair<Bag*, Item*> > BagItemTestHolder;
for (int i = 0; i < 16; i++) //Guess
{
	Item *item = pUser->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
	BagItemTestHolder.push_back(std::make_pair(item ? item->GetContainer() : nullptr, item));
}
for (int i = 0; i < 4; i++) //Guess
{
	for (int j = 0; j < 255; j++) //Guess
	{
		Item *item = pUser->GetItemByPos(INVENTORY_SLOT_BAG_START + j, i);
		BagItemTestHolder.push_back(std::make_pair(item ? item->GetContainer() : nullptr, item));
	}
}

//[...]

uint32 counter = 0;
for (std::vector<std::pair<Bag*, Item*> >::iterator viItr = BagItemTestHolder.begin(); viItr != BagItemTestHolder.end(); ++viItr)
{
	if (viItr->second)
	{
		if (viItr->first)
		{
			ChatHandler(pUser->GetSession()).PSendSysMessage("Got a valid item in vector position %u", counter);
			ChatHandler(pUser->GetSession()).PSendSysMessage("Bag ID = %u   and   Item entry ID = %u", (*viItr).first->GetBagSlot(), (*viItr).second->GetEntry());
		}
	}
	++counter;
}

Try see this:

https://github.com/Rochet2/TrinityCore/blob/transmog/src/server/scripts/Custom/Transmog/Transmogrifier.cpp#L351L364

Backpack:

for (uint8 i = INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END; ++i) if(Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i)) item->doStuff();
Other bags:

for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i) if (Bag* bag = player->GetBagByPos(i)) for (uint32 j = 0; j < bag->GetBagSize(); ++j) if (Item* item = player->GetItemByPos(i, j)) item->doStuff();
For more see Player::GetItemByGUID

delete…

@Paradox

for (int i = 0; i < 16; i++)

I do know you will have problems trying to access 17 slots in a 16 slot bag…

You need to sleep more /emoticons/default_tongue.png .


Thank you Rochet, I also realized that the Backpack has no valid Bag*.