I don't know if anyone knows this, but a method was added to BaseCreature a while back. Its called SetWearable. I'll show examples shortly. Most scripts use AddItem method to equip items on NPC's and monsters. This is wrong. Most client crashes are caused by mobiles having multiple items added to a specific layer. You could use EquipItem method, however if it returns false, that item will be leaked onto the internal map unless it is handled properly. Using the SetWearable method will automatically handle layer conflicts, and even has some handy arguments for making the item movable and setting the hue.
So, using the first method while just passing in the item, and any conflicts will be removed to make room for the new item.
So, in conclusion, STOP USING ADDITEM for equipping equipment on NPCs/Monsters!!!
Code:
public virtual void SetWearable(Item item)
{
SetWearable(item, -1, 0.0, true);
}
public virtual void SetWearable(Item item, int hue)
{
SetWearable(item, hue, 0.0, true);
}
public virtual void SetWearable(Item item, double dropChance)
{
SetWearable(item, -1, dropChance, true);
}
public virtual void SetWearable(Item item, int hue, double dropChance)
{
SetWearable(item, hue, dropChance, true);
}
public virtual void SetWearable(Item item, bool removeConflicting)
{
SetWearable(item, -1, 0.0, true);
}
public virtual void SetWearable(Item item, int hue, bool removeConflicting)
{
SetWearable(item, hue, 0.0, true);
}
public virtual void SetWearable(Item item, double dropChance, bool removeConflicting)
{
SetWearable(item, -1, dropChance, true);
}
public virtual void SetWearable(Item item, int hue, double dropChance, bool removeConflicting)
{
if (!EquipItem(item))
{
if (removeConflicting)
{
Item i = FindItemOnLayer(item.Layer);
if (i != null)
{
if (Backpack == null)
i.Delete();
else
PackItem(i);
}
if (!EquipItem(item))
{
if (Backpack == null)
item.Delete();
else
PackItem(item);
}
}
else
{
if (Backpack == null)
item.Delete();
else
PackItem(item);
}
}
if (hue > -1)
item.Hue = hue;
item.Movable = dropChance > Utility.RandomDouble();
}
So, using the first method while just passing in the item, and any conflicts will be removed to make room for the new item.
So, in conclusion, STOP USING ADDITEM for equipping equipment on NPCs/Monsters!!!