Difference between revisions of "OnPlayerUnequipItem"

From NWN Lexicon
Jump to: navigation, search
(Created page with "=OnPlayerUnEquipItem= Fires whenever a PC unequips an item. Can be useful for creating truly cursed items that can't even be unequipped. <br /> ====Trigger==== PC ...")
 
Line 25: Line 25:
 
====Example====
 
====Example====
  
<font color="#007f00">// PC can't take off any cursed necklaces, Ever. *evil grin*
+
<nwscript>
  </font>
+
// PC can't take off any cursed necklaces, Ever. *evil grin*
  <font color="#007f00">// Note: It is best, no, normally required, that the item that cannot
+
   
  </font><font color="#007f00">// be unequipped to be cursed. This means a PC cannot drop it
+
  // Note: It is best, no, normally required, that the item that cannot
  </font><font color="#007f00">// from thier inventory slot, right onto the ground, and thus the  
+
  // be unequipped to be cursed. This means a PC cannot drop it
  </font><font color="#007f00">// script fail.
+
  // from thier inventory slot, right onto the ground, and thus the  
  </font>
+
  // script fail.
  <font color="#0000ff">void</font> main()
+
   
 +
  void main()
 
  {
 
  {
     <font color="#007f00">// Get the objects for use with this event.
+
     // Get the objects for use with this event.
</font>    <font color="#0000ff">object</font> oPC=GetPCItemLastUnequippedBy();
+
    object oPC=GetPCItemLastUnequippedBy();
     <font color="#0000ff">object</font> oItem=GetPCItemLastUnequipped();
+
     object oItem=GetPCItemLastUnequipped();
 
   
 
   
     <font color="#007f00">// This could be a tag check, but does need to check it is an neck
+
     // This could be a tag check, but does need to check it is an neck
</font>    <font color="#007f00">// item, so it can be equipped to the right slot.
+
    // item, so it can be equipped to the right slot.
</font>    <font color="#0000ff">if</font> (GetItemCursedFlag(oItem) &amp;&amp;
+
    if (GetItemCursedFlag(oItem) &amp;&amp;
 
         GetBaseItemType(oItem) == BASE_ITEM_AMULET)
 
         GetBaseItemType(oItem) == BASE_ITEM_AMULET)
 
     {
 
     {
Line 47: Line 48:
 
     }
 
     }
 
  }
 
  }
 +
</nwscript>
  
 
====See Also====
 
====See Also====

Revision as of 21:54, 25 August 2012

OnPlayerUnEquipItem

Fires whenever a PC unequips an item. Can be useful for creating truly cursed items that can't even be unequipped.


Trigger

PC unequips an item (prior to the item actually being unequipped).


Function(s)

GetItemPossessor(oItem) Returns who holds the item that was unequipped


Remarks

With Hordes of the Underdark, BioWare has introduced a generic tag based system covering all of the module related item events. View the scripts x2_mod_def_equ, x2_mod_def_unequ, x2_mod_def_unaqu, x2_mod_def_aqu, x2_mod_def_act, and IN PARTICULAR, x2_it_example for more information if you wish to use the BioWare way of doing it. It is unknown by the Lexicon's authors, at this time, if the system is available on non-Hordes of the Underdark installations. By using GetItemPossessor(oItem) you can check several things in this event. Firstly, if the PC dropped it or not, secondly, if he just sold it straight out of his inventory slot, and thirdly, if it is in barter (if the items location is invalid, and the possessor invalid, it is in a barter screen - in limbo). Of course, if the possessor is still the PC, then he just moved it into his inventory. Because of how you can drop items/sell items right from slots, the only way to force a PC to never unequip an item is to make sure it has the cursed flag set (so it cannot be sold, or moved out of a creatures inventory). This means any ActionEquipItem()'s will pass sucessfully.


Example

 // PC can't take off any cursed necklaces, Ever. *evil grin*
 
 // Note: It is best, no, normally required, that the item that cannot
 // be unequipped to be cursed. This means a PC cannot drop it
 // from thier inventory slot, right onto the ground, and thus the 
 // script fail.
 
 void main()
 {
     // Get the objects for use with this event.
     object oPC=GetPCItemLastUnequippedBy();
     object oItem=GetPCItemLastUnequipped();
 
     // This could be a tag check, but does need to check it is an neck
     // item, so it can be equipped to the right slot.
     if (GetItemCursedFlag(oItem) &amp;&amp;
         GetBaseItemType(oItem) == BASE_ITEM_AMULET)
     {
         AssignCommand(oPC, ClearAllActions());
         AssignCommand(oPC, ActionEquipItem(oItem, INVENTORY_SLOT_NECK));
     }
 }

See Also

functions: 

GetPCItemLastUnequippedBy()