• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] 3.3.5 On PvP Kill script

Status
Not open for further replies.

sean

Emulation Addict
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.
 

Kaev

Super Moderator
NotHawthorne did something like this in his ShardLua scripts, 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.
 

Tommy

Founder
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..
 

Rochet2

Moderator / Eluna Dev
Get all equipped items in a vector.
Use urand to get a random index from the vector and use that item.

Practice:
Code:
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))
            items.push_back(equippedItem);
    }

    // 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
    }
}
 

sean

Emulation Addict
Thanks for the replies everyone! I got it to work the way I wanted it to using Rochet2's script :RpS_biggrin:
 
Status
Not open for further replies.
Top