Difference between revisions of "GetItemInSlot"

From NWN Lexicon
Jump to: navigation, search
(Example)
Line 1: Line 1:
 
+
{{DISPLAYTITLE:FunctionName(object, int)}}__NOTOC__
 
 
 
 
 
 
=GetItemInSlot(int, object)=
 
 
 
 
Retrieve the item in a given inventory slot of a creature.
 
Retrieve the item in a given inventory slot of a creature.
 
 
<nwscript>
 
<nwscript>
 
object GetItemInSlot(
 
object GetItemInSlot(
Line 16: Line 10:
 
====Parameters====
 
====Parameters====
  
''nInventorySlot''
+
;nInventorySlot
 
+
:[[ inventory_slot | INVENTORY_SLOT_* ]]
[[ inventory_slot | INVENTORY_SLOT_* ]]
+
;oCreature
 
+
:Target creature. (Default: OBJECT_SELF)
''oCreature''
 
 
 
Target creature. (Default: OBJECT_SELF)
 
 
 
<br />
 
  
 
====Description====
 
====Description====
  
Returns the object which is in oCreature's specified inventory slot (nInventorySlot). <br /> Returns OBJECT_INVALID if oCreature is not a valid creature or there is no item in nInventorySlot.
+
Returns the object which is in oCreature's specified inventory slot (nInventorySlot).
  
<br /><br />
+
Returns OBJECT_INVALID if oCreature is not a valid creature or there is no item in nInventorySlot.
  
 
====Remarks====
 
====Remarks====
  
Remember that the INVENTORY_SLOT_* constants are actually integers from 0 to 17 (or, if Bioware ever decides to add more slots, 0 to NUM_INVENTORY_SLOTS - 1). Thus, you can create a for loop to cycle through somebody's equipped items. See codesample.
+
Remember that the INVENTORY_SLOT_* constants are actually integers from 0 to 17 (or, if Bioware ever decides to add more slots, 0 to NUM_INVENTORY_SLOTS - 1). Thus, you can create a for loop to cycle through somebody's equipped items. See example.
  
<br />
+
Also while creature weapons and items cannot be seen in the UI (even by DMs) they can still be equipped - and even used - by players, especially the "Creature Armor" one commonly used to store "permanent" effects.
  
 
====Version====
 
====Version====
Line 49: Line 38:
 
void main()
 
void main()
 
{
 
{
object oPC=GetEnteringObject();
+
    object oPC=GetEnteringObject();
if (!GetIsPC(oPC)) return;
+
    if(!GetIsPC(oPC)) return;
  
object oItem;
+
    object oItem;
int nSlot;
+
    int nSlot;
  
for (nSlot=0; nSlot < NUM_INVENTORY_SLOTS; nSlot++)
+
    for (nSlot=0; nSlot < NUM_INVENTORY_SLOTS; nSlot++)
  {
+
    {
  oItem=GetItemInSlot(nSlot, oPC);
+
        oItem=GetItemInSlot(nSlot, oPC);
  
  //unequip if valid
+
        //unequip if valid
  if (GetIsObjectValid(oItem))
+
      if(GetIsObjectValid(oItem))
      AssignCommand(oPC, ActionUnequipItem(oItem));
+
          AssignCommand(oPC, ActionUnequipItem(oItem));
  }
+
    }
 
}
 
}
 
</nwscript>
 
</nwscript>

Revision as of 23:34, 13 September 2020

Retrieve the item in a given inventory slot of a creature.

object GetItemInSlot(
    int nInventorySlot,
    object oCreature = OBJECT_SELF
);

Parameters

nInventorySlot
INVENTORY_SLOT_*
oCreature
Target creature. (Default: OBJECT_SELF)

Description

Returns the object which is in oCreature's specified inventory slot (nInventorySlot).

Returns OBJECT_INVALID if oCreature is not a valid creature or there is no item in nInventorySlot.

Remarks

Remember that the INVENTORY_SLOT_* constants are actually integers from 0 to 17 (or, if Bioware ever decides to add more slots, 0 to NUM_INVENTORY_SLOTS - 1). Thus, you can create a for loop to cycle through somebody's equipped items. See example.

Also while creature weapons and items cannot be seen in the UI (even by DMs) they can still be equipped - and even used - by players, especially the "Creature Armor" one commonly used to store "permanent" effects.

Version

1.32

Example

//Strip entering player to the bone
 
void main()
{
    object oPC=GetEnteringObject();
    if(!GetIsPC(oPC)) return;
 
    object oItem;
    int nSlot;
 
    for (nSlot=0; nSlot < NUM_INVENTORY_SLOTS; nSlot++)
    {
        oItem=GetItemInSlot(nSlot, oPC);
 
        //unequip if valid
       if(GetIsObjectValid(oItem))
           AssignCommand(oPC, ActionUnequipItem(oItem));
    }
}

See Also

functions: 

GetBaseItemType

constants: 

INVENTORY_SLOT_* Constants



 author: Jason Harris, editor: Lilac Soul, additional contributor(s): Lilac Soul