Full Version : OnEquip Check?
xmlspawner >>Q&A >>OnEquip Check?


<< Prev | Next >>

Lord Hog Fred- 07-30-2006
Can I add generic attachments to players with names that can be checked against when equipping items?
Basically I want to add to an items script a check that looks if an attachment named "X" is on the player and if so allow them to equip it. If not then it won't allow the player to equip the item.
Any ideas on how I may go about doing this?

Thanks smile.gif,


ArteGordon- 07-30-2006
QUOTE (Lord Hog Fred @ July 30, 2006 05:17 pm)
Can I add generic attachments to players with names that can be checked against when equipping items?
Basically I want to add to an items script a check that looks if an attachment named "X" is on the player and if so allow them to equip it. If not then it won't allow the player to equip the item.
Any ideas on how I may go about doing this?

Thanks smile.gif,

yes. I generally use the XmlData attachment for that kind of generic thing.

To have an item check for it in the CanEquip method script, just add an override like this

CODE

       public override bool CanEquip(Mobile m)
       {
           if (XmlAttach.FindAttachment(m, typeof(XmlData), "X") == null)
           {
               // didnt find the XmlData attachment with that name on the mobile, so cant equip              
               return false;
           }

           return base.CanEquip(m);
       }


and you will need to add this to the beginning of the script

CODE

using Server.Engines.XmlSpawner2;

Lord Hog Fred- 07-30-2006
Ah thank you very much. the fact XmlSpawner allows this has just made my life so much easier smile.gif

Could I add the attachment "X" to a player via a deed or some other item when used?

ArteGordon- 07-30-2006
the attachments are very handy that way. Dont have to worry about ser/deser, and you can add or remove them any time you like.

ArteGordon- 07-30-2006
QUOTE (Lord Hog Fred @ July 30, 2006 06:10 pm)
Ah thank you very much. the fact XmlSpawner allows this has just made my life so much easier smile.gif

Could I add the attachment "X" to a player via a deed or some other item when used?

yes, to add an attachment like that via a script just add something like

CODE

XmlAttach.AttachTo(player, new XmlData("X"));


into whatever method you want, like OnDoubleClick or or OnUse