[Question] Auto Equipped

Hi guys, i have a little question, How can set when a character is created is automatically equip an object? for example a set pve or set pvp?

thx /emoticons/default_biggrin.png

Use the equip methods in C++

This is the EquipItem method from eluna. You can use the same C++ functions.

https://github.com/ElunaLuaEngine/Source/blob/master/src/server/LuaEngine/UnitMethods.h#L2923

Note that the first case in the if statement is used if you have an item entry

the second part is used if you have an item object.

Both use player->EquipItem(dest, item, true)

You can use this sort of code to equip each piece to each slot.
I assume you only need the new entry part

    uint16 eDest;
    InventoryResult msg = CanEquipNewItem(NULL_SLOT, eDest, titem_id, false);
    if (msg != EQUIP_ERR_OK)
        break;

    Item* item = EquipNewItem(eDest, titem_id, true);
    AutoUnequipOffhandIfNeed();

This is taken from the core.

You can’t without DBC hacking, which we do not support client side DBC hacking. Although, it might be possible to make a script using the onplayercreate, or onplayerenterworld, or whatever hook.

It doesnt require client side DBC editing I think. If I remember correctly, the start outfit used to be in the DB.

Now it is loaded from DBCs. You can modify the core to use DB again or modify the serverside DBCs. Or just hardcode the sets.

… or the on char create script…

Just add the items to Playercreateinfo_item table. It will not display until after you create the character and you go to character select screen. It will show there though, and of course, in game. No need for scripts or complicated core edits.

You can use 0 for all in one column, but not 2…

Example:

REPLACE INTO playercreateinfo_item (race, class, itemid, amount) VALUES(0, 6, 34652, 1);
REPLACE INTO playercreateinfo_item (race, class, itemid, amount) VALUES(0, 6, 34657, 1);
REPLACE INTO playercreateinfo_item (race, class, itemid, amount) VALUES(0, 6, 34655, 1);
REPLACE INTO playercreateinfo_item (race, class, itemid, amount) VALUES(0, 6, 34659, 1);
REPLACE INTO playercreateinfo_item (race, class, itemid, amount) VALUES(0, 6, 34650, 1);
REPLACE INTO playercreateinfo_item (race, class, itemid, amount) VALUES(0, 6, 34653, 1);
REPLACE INTO playercreateinfo_item (race, class, itemid, amount) VALUES(0, 6, 34649, 1);
REPLACE INTO playercreateinfo_item (race, class, itemid, amount) VALUES(0, 6, 34651, 1);
REPLACE INTO playercreateinfo_item (race, class, itemid, amount) VALUES(0, 6, 34656, 1);
REPLACE INTO playercreateinfo_item (race, class, itemid, amount) VALUES(0, 6, 34648, 1);
REPLACE INTO playercreateinfo_item (race, class, itemid, amount) VALUES(0, 6, 34658, 1);
REPLACE INTO playercreateinfo_item (race, class, itemid, amount) VALUES(0, 6, 38147, 1);

0 for all Races, 6 for DK, the next is Item Id, and 1 as ammount… (unless you want them to have more than 1)…

Just find the Id’s of the set you want, and define what class should have it.

Here is a table referance…

– CLASSMask ID Name
– 1 1 Warrior
– 2 2 Paladin
– 4 3 Hunter
– 8 4 Rogue
– 16 5 Priest
– 32 6 Death Knight
– 64 7 Shaman
– 128 8 Mage
– 256 9 Warlock
– 512 10 Unused
– 1024 11 Druid
– 2048 12 Necromancer

–RACEMask ID Name
– 1 1 Human
– 2 2 Orc
– 4 3 Dwarf
– 8 4 Night Elf
– 16 5 Undead
– 32 6 Tauren
– 64 7 Gnome
– 128 8 Troll
– 256 9 Goblin
– 512 10 Blood Elf
– 1024 11 Draenei
– 2048 12 Fel Orc
– 4096 13 Naga
– 8192 14 Broken
– 16384 15 Skeleton
– 32768 16 Vrykul
– 65536 17 Tuskarr
– 131072 18 Forest Troll
– 262144 19 Taunka
– 524288 20 Northrend Skeleton
– 1048576 21 Ice Troll
– 2097152 22 Worgen (4.x)

It probably has more race/class combo’s than you need, but it should help. Add together if you want multiple types.

In other words… if yut want warrior and pallies to have a certain item… 1 for warrior 2 for pally so 3 for both…

Hope that helps ya.

The items are not equipped though…

Sure they are. You just have to wipe out the old items in playercreateinfo_item characters usually start with.

Hmm, need to test this.

It sounds really off since there is no slot column and the wiki doesnt say anything about equipping the items.

If there are for example 3 weapons, the core cant know which ones to use and just randomly pics one. That doesnt sound blizzlike at all, let alone userfriendly.

Also, there are no existing (old) items there. The existing equipped items come from the DBCs…

Dunno what to tell ya there… It works just fine for me, has ever since I can remember.

Example → Back to DK agian. Just added 2 weapons to PCI_Item… No other weapons in there for DK to start with. Starts with them, and Weilds them…

Edit –

I guess it is possible at one point over the years I modified the core to read from DB instead of DBC. I don’t remember doing that ever, but it’s possible.

When people are discussing CLEAN, UNMODIFIED TC, those without, should not chime in, except to say “I fixed that problem by modifying my server to do X”… Especially if you can’t even remember what changes you made.

I agree with Paradox on this. Either contribute the change so this could be pushed on to the clean environment or do not try to advert it please, because I go out a limb when I say that it seems more gloating than anything else.
Please, contribute what you changed, or do not show off. First one is honorable, second one would be sad.

I said it was “Possible” … Just giving a gracious way out really. I doubt I did edit anything; anything is possible though.

Just trying to help. No need to be pricks. Don’t worry, you won’t hear from me agian.

No, I was not a prick, I was trying to be reasonable. For example, I would have no idea how to do what you suggested. So what should I do ? That’s the problem. 95% or a bit less of the TrinityCore users have little to no experience with C++. What should these do ?

Eat dem cheesecakes /emoticons/default_rolleyes.gif

OT : Then I guess, you will find me in the scriptmobile…wait…what am I still doing here? TO THE SCRIPT MOBILE!!

Can you edit this function?

    // original items
    if (CharStartOutfitEntry const* oEntry = GetCharStartOutfitEntry(createInfo->Race, createInfo->Class, createInfo->Gender))
    {
        for (int j = 0; j < MAX_OUTFIT_ITEMS; ++j)
        {
            if (oEntry->ItemId[j] <= 0)
                continue;

            uint32 itemId = oEntry->ItemId[j];

            // just skip, reported in ObjectMgr::LoadItemTemplates
            ItemTemplate const* iProto = sObjectMgr->GetItemTemplate(itemId);
            if (!iProto)
                continue;

            // BuyCount by default
            uint32 count = iProto->BuyCount;

            // special amount for food/drink
            if (iProto->Class == ITEM_CLASS_CONSUMABLE && iProto->SubClass == ITEM_SUBCLASS_FOOD)
            {
                switch (iProto->Spells[0].SpellCategory)
                {
                    case SPELL_CATEGORY_FOOD:                                // food
                        count = getClass() == CLASS_DEATH_KNIGHT ? 10 : 4;
                        break;
                    case SPELL_CATEGORY_DRINK:                                // drink
                        count = 2;
                        break;
                }
                if (iProto->GetMaxStackSize() < count)
                    count = iProto->GetMaxStackSize();
            }
            StoreNewItemInBestSlots(itemId, count);
        }
    }

    for (PlayerCreateInfoItems::const_iterator item_id_itr = info->item.begin(); item_id_itr != info->item.end(); ++item_id_itr)
        StoreNewItemInBestSlots(item_id_itr->item_id, item_id_itr->item_amount);

    // bags and main-hand weapon must equipped at this moment
    // now second pass for not equipped (offhand weapon/shield if it attempt equipped before main-hand weapon)
    // or ammo not equipped in special bag
    for (uint8 i = INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END; i++)
    {
        if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
        {
            uint16 eDest;
            // equip offhand weapon/shield if it attempt equipped before main-hand weapon
            InventoryResult msg = CanEquipItem(NULL_SLOT, eDest, pItem, false);
            if (msg == EQUIP_ERR_OK)
            {
                RemoveItem(INVENTORY_SLOT_BAG_0, i, true);
                EquipItem(eDest, pItem, true);
            }
            // move other items to more appropriate slots (ammo not equipped in special bag)
            else
            {
                ItemPosCountVec sDest;
                msg = CanStoreItem(NULL_BAG, NULL_SLOT, sDest, pItem, false);
                if (msg == EQUIP_ERR_OK)
                {
                    RemoveItem(INVENTORY_SLOT_BAG_0, i, true);
                    pItem = StoreItem(sDest, pItem, true);
                }

                // if  this is ammo then use it
                msg = CanUseAmmo(pItem->GetEntry());
                if (msg == EQUIP_ERR_OK)
                    SetAmmo(pItem->GetEntry());
            }
        }
    }

Fix for new: trintycore 01/07/2014

void InicirEquipado(Player* player){
// original items
if (CharStartOutfitEntry const* oEntry = GetCharStartOutfitEntry(player->getRace(), player->getClass(), player->getGender()))
{
for (int j = 0; j < MAX_OUTFIT_ITEMS; ++j)
{
if (oEntry->ItemId[j] <= 0)
continue;

		uint32 itemId = oEntry->ItemId[j];

		// just skip, reported in ObjectMgr::LoadItemTemplates
		ItemTemplate const* iProto = sObjectMgr->GetItemTemplate(itemId);
		if (!iProto)
			continue;

		// BuyCount by default
		uint32 count = iProto->BuyCount;

		// special amount for food/drink
		if (iProto->Class == ITEM_CLASS_CONSUMABLE && iProto->SubClass == ITEM_SUBCLASS_FOOD)
		{
			switch (iProto->Spells[0].SpellCategory)
			{
			case SPELL_CATEGORY_FOOD:                                // food
				count = player->getClass() == CLASS_DEATH_KNIGHT ? 10 : 4;
				break;
			case SPELL_CATEGORY_DRINK:                                // drink
				count = 2;
				break;
			}
			if (iProto->GetMaxStackSize() < count)
				count = iProto->GetMaxStackSize();
		}
		player->StoreNewItemInBestSlots(35015, 1);
		player->StoreNewItemInBestSlots(51541, 1);
		player->StoreNewItemInBestSlots(51542, 1);
	}
}
PlayerInfo const* info = sObjectMgr->GetPlayerInfo(player->getRace(), player->getClass());
for (PlayerCreateInfoItems::const_iterator item_id_itr = info->item.begin(); item_id_itr != info->item.end(); ++item_id_itr)
	player->StoreNewItemInBestSlots(item_id_itr->item_id, item_id_itr->item_amount);

// bags and main-hand weapon must equipped at this moment
// now second pass for not equipped (offhand weapon/shield if it attempt equipped before main-hand weapon)
// or ammo not equipped in special bag
for (uint8 i = INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END; i++)
{
	if (Item* pItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
	{
		uint16 eDest;
		// equip offhand weapon/shield if it attempt equipped before main-hand weapon
		InventoryResult msg = player->CanEquipItem(NULL_SLOT, eDest, pItem, false);
		if (msg == EQUIP_ERR_OK)
		{
			player->RemoveItem(INVENTORY_SLOT_BAG_0, i, true);
			player->EquipItem(eDest, pItem, true);
		}
		// move other items to more appropriate slots (ammo not equipped in special bag)
		else
		{
			ItemPosCountVec sDest;
			msg = player->CanStoreItem(NULL_BAG, NULL_SLOT, sDest, pItem, false);
			if (msg == EQUIP_ERR_OK)
			{
				player->RemoveItem(INVENTORY_SLOT_BAG_0, i, true);
				pItem = player->StoreItem(sDest, pItem, true);
			}

			// if  this is ammo then use it
			msg = player->CanUseAmmo(pItem->GetEntry());
			if (msg == EQUIP_ERR_OK)
				player->SetAmmo(pItem->GetEntry());
		}
	}
}

}

See problem: This adding the item several times in the Bag