Jump to content

Home

script : give item to a NPC in the right slot


jrc24

Recommended Posts

Hi

 

with script,

 

How can I give item to a NPC and put this item in the right slot (hand, head or arm...) ?

 

I know :

 

int nSlot = (number_of_slot)

object oNPC=GetObjectByTag("npc_name");

object oItem=GetObjectByTag("item_name");

 

I try CreateItemOnObject and ActionEquipItem with no success

 

Please can you tell me how must I use this functions if it is the right functions

 

thanks

Link to comment
Share on other sites

The functions that start with "Action" do not have a parameter of oNPC in them (they are assumed to work on OBJECT_SELF). So to get them to work on oNPC you have to use the AssignCommand function.

 

It sounds like you were very close though.

 

void main() {
int nSlot = INVENTORY_SLOT_RIGHTWEAPON;
object  oNPC=GetObjectByTag("npc_name");
object  oItem=GetObjectByTag("item_name");
CreateItemOnObject("item_name",oNPC);
AssignCommand(oNPC,ActionEquipItem(oItem, nSlot));
}

Link to comment
Share on other sites

ok I write that :

 

void main() {

int nSlot = (4);

object oNPC=GetObjectByTag("Zaalbar");

object oItem=GetObjectByTag("my_item_name");

CreateItemOnObject("my_item_name", oNPC);

AssignCommand(oNPC, ActionEquipItem(oItem, nSlot));

}

 

result :

 

I get my item in general inventory but not in Zaalbar hand

 

if you see what could be the problem, thanks

Link to comment
Share on other sites

Make sure you use: "int nSlot = INVENTORY_SLOT_RIGHTWEAPON;" instead of "int nSlot = (4);"

 

TK102's script should respond to 99.9% of the needs. However, depending on what you want to do, this can be another possibility:

If your npc is already equipped with an item that you want to replace definitely (you will loose the old item), try:

void main()
{
  object  oNPC=GetObjectByTag("npc_name");
  object oOldobject =  GetItemInSlot(INVENTORY_SLOT_RIGHTWEAPON,OBJECT_SELF);
   object oNewobject = CreateItemOnObject("my_item_name",OBJECT_SELF);
   if (GetIsObjectValid (oOldobject))
       {
       DestroyObject(oOldobject);
       }

AssignCommand(oNPC,ActionEquipItem(oNewobject,INVENTORY_SLOT_RIGHTWEAPON,TRUE));

}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...