- 163
- 2015
- 33
Trinitcore: C++ Fixing stackable item container bug
The bug:
Well basically if you have an item container such as a box of supplies or any other stackable item container for that matter, and you edit your database to make it stackable, a bug occurs.
For the sake of the guide i will be calling item container -> box
So when you stack a box in your bag and try to open it you will see that you only receive the contents of 1 box rather than the number of boxes you had stacked.
How to fix it:
Basically find loothandler.cpp in Trinitycore/src/server/game/Handlers/loothandler.cpp and open it up with a text editor and find the method:
Code:
void WorldSession:
oLootRelease(ObjectGuid lguid)
below this at the end of the method there is:
Code:
else
{
// Only delete item if no loot or money (unlooted loot is saved to db) or if it isn't an openable item
if (pItem->loot.isLooted() || !(proto->Flags & ITEM_PROTO_FLAG_OPENABLE))
player->DestroyItem(pItem->GetBagSlot(), pItem->GetSlot(), true);
}
Now change the above with:
Code:
else
{
pItem->m_lootGenerated = false;
pItem->loot.clear();
uint32 count = pItem->GetCount();
if (count > 1)
count = 1;
//Only delete item if no loot or money (unlooted loot is saved to db) or if it isn't an openable item
if (pItem->loot.isLooted() || !(proto->Flags & ITEM_PROTO_FLAG_OPENABLE))
player->DestroyItemCount(pItem, count, true);
//player->DestroyItem(pItem->GetBagSlot(), pItem->GetSlot(), true);
}
Explanation
Code:
pItem->m_lootGenerated = false;
Sets the bool loot generated to false meaning that once you have opened one box it will not stop generating loot for the rest of the boxes in the stack.
Code:
uint32 count = pItem->GetCount();
This saves how many boxes in variable count, followed by this we check to see if count is > 1 if it is we set it to 1 then after the next if condition is satisfied and we have looted it we then do this:
Code:
player->DestroyItemCount(pItem, count, true);
In order to delete only the amount of boxes that count specifies, so only 1 instead of deleting the whole stack which is what happend in the commented out method.
Recompile for changes to take effect and you're done.
Big thanks to sofos2 for the original release, all credits to him.
The bug:
Well basically if you have an item container such as a box of supplies or any other stackable item container for that matter, and you edit your database to make it stackable, a bug occurs.
For the sake of the guide i will be calling item container -> box
So when you stack a box in your bag and try to open it you will see that you only receive the contents of 1 box rather than the number of boxes you had stacked.
How to fix it:
Basically find loothandler.cpp in Trinitycore/src/server/game/Handlers/loothandler.cpp and open it up with a text editor and find the method:
Code:
void WorldSession:
below this at the end of the method there is:
Code:
else
{
// Only delete item if no loot or money (unlooted loot is saved to db) or if it isn't an openable item
if (pItem->loot.isLooted() || !(proto->Flags & ITEM_PROTO_FLAG_OPENABLE))
player->DestroyItem(pItem->GetBagSlot(), pItem->GetSlot(), true);
}
Now change the above with:
Code:
else
{
pItem->m_lootGenerated = false;
pItem->loot.clear();
uint32 count = pItem->GetCount();
if (count > 1)
count = 1;
//Only delete item if no loot or money (unlooted loot is saved to db) or if it isn't an openable item
if (pItem->loot.isLooted() || !(proto->Flags & ITEM_PROTO_FLAG_OPENABLE))
player->DestroyItemCount(pItem, count, true);
//player->DestroyItem(pItem->GetBagSlot(), pItem->GetSlot(), true);
}
Explanation
Code:
pItem->m_lootGenerated = false;
Sets the bool loot generated to false meaning that once you have opened one box it will not stop generating loot for the rest of the boxes in the stack.
Code:
uint32 count = pItem->GetCount();
This saves how many boxes in variable count, followed by this we check to see if count is > 1 if it is we set it to 1 then after the next if condition is satisfied and we have looted it we then do this:
Code:
player->DestroyItemCount(pItem, count, true);
In order to delete only the amount of boxes that count specifies, so only 1 instead of deleting the whole stack which is what happend in the commented out method.
Recompile for changes to take effect and you're done.
Big thanks to sofos2 for the original release, all credits to him.