OnPlayerUnequipItem

From NWN Lexicon
Jump to: navigation, search

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:

  1. If the PC dropped it or not.
  2. If he just sold it straight out of his inventory slot.
  3. If it is in barter (if the item's 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 creature's inventory). This means any ActionEquipItem()'s will pass successfully.

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 their 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 a neck
    // item, so it can be equipped to the right slot.
    if (GetItemCursedFlag(oItem) &&
        GetBaseItemType(oItem) == BASE_ITEM_AMULET)
    {
        AssignCommand(oPC, ClearAllActions());
        AssignCommand(oPC, ActionEquipItem(oItem, INVENTORY_SLOT_NECK));
    }
}

See Also

functions:  GetPCItemLastUnequippedBy()