PDA

View Full Version : script : give item to a NPC in the right slot


jrc24
06-30-2004, 03:32 AM
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

tk102
06-30-2004, 09:43 AM
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));
}

jrc24
06-30-2004, 07:14 PM
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

Darth333
06-30-2004, 07:31 PM
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_SE LF);
object oNewobject = CreateItemOnObject("my_item_name",OBJECT_SELF);
if (GetIsObjectValid (oOldobject))
{
DestroyObject(oOldobject);
}

AssignCommand(oNPC,ActionEquipItem(oNewobject,INVE NTORY_SLOT_RIGHTWEAPON,TRUE));

}

jrc24
06-30-2004, 08:06 PM
NOW IT S WORK VERY WELL !!!!!!!!!!!!!!

thank you tk102 and darth333

:D :D :D :D :D :D