View Full Version : [SOLVED] 3.3.5 On PvP Kill script

02-12-2015, 07:09 AM
Hello. I have been trying to make this on pvp kill script where the victim spawns a chest that has an item from the victims equipped item slots. So far I was able to get the victim to spawn the chest upon death and even add a random piece of armor to the loot, but I can't figure out how to get a random item from one of the victims equipped slots and add it to the chests loot. If someone help out on how to go about this that would be great thanks.

02-12-2015, 07:23 AM
NotHawthorne did something like this in his ShardLua scripts (http://emudevs.com/showthread.php/3975-Shard-Lua-Old-School-MMORPG-Game-Rules!), but he used LUA for it.
But you can do it nearly as he did it: Get all the victims equipped items from the DB, randomize a number between (start item slot) and (end item slot) and add that item to the chest.

02-12-2015, 07:39 AM
I actually made this in C++ for my Zombie Server, but I lost all of my donator projects during server move awhile back. However, I did give Foereaper the script, maybe he still has it..

02-12-2015, 11:16 AM
Get all equipped items in a vector.
Use urand to get a random index from the vector and use that item.


void test(Player* player)
// all equipped items will be stored here
std::vector<Item*> items;

// loop all equipment slots
for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot)
// check if has item in slot
// if has, add to items
if (Item* equippedItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))

// Choose random item from the vector if its not empty
Item* chosen = NULL;
if (!items.empty())
chosen = items[urand(0, items.size() - 1)]; // min..max (inclusive), thus -1

// chosen is now the item picked randomly or NULL

if (chosen)
// Depending on how you handle looting, you should do this differently maybe.
// This is now destroying the original item
uint32 entry = chosen->GetEntry();
uint32 count = chosen->GetCount();
player->DestroyItemCount(chosen, count, true);

// use entry and count in loot

02-12-2015, 09:39 PM
Thanks for the replies everyone! I got it to work the way I wanted it to using Rochet2's script :RpS_biggrin: