PDA

View Full Version : Item enchant function. mangos/trintiy



Wise
13-01-13, 11:30 PM
Hello ladies! Well i wrote a enchant item function. Because personally i hate all other enchant npc's so i made my own.

Here is the function i use for applying enchants to players:



void Player::EnchantItem(uint32 spellid, uint8 slot)
{
Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
if (!pItem)
{
SendChatMessage("%s[Enchant NPC]%s Your item could not be enchanted, there aer no item equipped in the specifified slot.",MSG_COLOR_MAGENTA,MSG_COLOR_WHITE);
return;
}
SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
if (!spellInfo)
{
SendChatMessage("Invalid spellid %u report to devs",spellid);
return;
}
uint32 enchantid = spellInfo->EffectMiscValue[0];
if (!enchantid)
{
SendChatMessage("Invalid enchantid %u report to devs", enchantid);
return;
}

if (!((1 << pItem->GetProto()->SubClass) & spellInfo->EquippedItemSubClassMask) &&
!((1 << pItem->GetProto()->InventoryType) & spellInfo->EquippedItemInventoryTypeMask))
{
SendChatMessage("%s[Enchant NPC]%s Your item could not be enchanted, wrong item type equipped",MSG_COLOR_MAGENTA,MSG_COLOR_WHITE);
return;
}

ApplyEnchantment(pItem, PERM_ENCHANTMENT_SLOT, false);
pItem->SetEnchantment(PERM_ENCHANTMENT_SLOT, enchantid, 0, 0);
ApplyEnchantment(pItem, PERM_ENCHANTMENT_SLOT, true);
SendChatMessage("%s[Enchant NPC]%s Your item was enchanted successfully!",MSG_COLOR_MAGENTA,MSG_COLOR_WHITE);
}


for mangos 2.4.3:
https://gist.github.com/4526158


Hope you enjoyed it, and as always. Have a a nice day!

Credits to LilleCarl