Skip to content

Make an NPC use an item

sarevok57sarevok57 Member Posts: 5,975
so i can't figure out how to make an NPC wear an item that the player has given them

so far everything else works, the quest completes, the NPC gets the outfit, but i dont know how to make it so the NPC puts the outfit on after the quest completes

anyone have some insight?

Comments

  • ProlericProleric Member Posts: 1,281
    edited July 2019
    DelayCommand(0.5, AssignCommand(oNPC, ActionEquipItem(oArmor, INVENTORY_SLOT_CHEST)));
    

    The delay isn't always necessary, but can help if the item or the NPC are recently spawned.

    As with all NPC actions, there is a risk that it might be cancelled by AI, especially if the NPC is an associate.

    That can be prevented using SetCommandable (see Example Note 2).
  • sarevok57sarevok57 Member Posts: 5,975
    when would i insert this script? during the dialogue in which i give the NPC this item?

    and what would i EXACTLY need to type into the script field for this to work?

    NPC tag: NW_ELFMAGE005

    item tag: NW_CLOTH003

    i tried putting in:

    void main()
    {
    DelayCommand(0.5, AssignCommand(NW_ELFMAGE005, ActionEquipItem(NW_CLOTH003, INVENTORY_SLOT_CHEST)));
    }

    but that didn't work it says:
    2019-07-05 3:15:57 AM: Error. 'leena009' did not compile.
    leena009.nss(3): ERROR: VARIABLE DEFINED WITHOUT TYPE
  • ProlericProleric Member Posts: 1,281
    You're right, you can put it in the script in which you give the item.

    I'd recommend doing a scripting primer, maybe the one in the Lexicon and/or Tarot Redhand's tutorials on the Vault.

    In essence, your script is failing because you're using constants (tags) where nwscript expects to see object variables.

    One approach in conversation with the NPC is as follows:
    void main()
    {
      object oNPC = OBJECT_SELF;
      object oPC  = GetPCSpeaker();
      object oArmor = GetItemPossessedBy(oPC, "NW_CLOTH003");
      ActionTakeItem(oPC, oArmor);
      DelayCommand(0.5, AssignCommand(oNPC, ActionEquipItem(oArmor, INVENTORY_SLOT_CHEST)));
    }
    

    The delay and assigned command in the last line might be redundant in this special case.

    Equally, if the NPC were not speaking to the PC, you'd have to use GetObjectByTag to set oNPC, and assign the ActionTakeItem to them.
  • sarevok57sarevok57 Member Posts: 5,975
    @Proleric ah excellent that above script worked as intended that you very much for the assistance :)
Sign In or Register to comment.