Equipping items
Moderator: Event DM
Equipping items
Should be simple. ActionEquipItem(oItem, INVENTORY_SLOT_CHEST);. But it doesn't work for me, for clothes, helmets, anything. I must be missing something really simple here, but I can't figure it out- I have the object, why won't it equip? I'll go try using AssignCommand(OBJECT_SELF, ActionEquipItem), I havent tried that yet, not that I have much hope...
- maxinion
- Team Member; Retired with Honors
- Posts: 2778
- Joined: Mon Mar 17, 2003 7:44 pm
- DM Avatar: Andrinor
- Location: Bay Area, CA
- Contact:
Poor Jeff...
Think, man. ActionEquipItem(object oItem, int iSlot); Where does it refer to the creature there? Nowhere. You're just telling air to equip oItem into iSlot. There's no default creature to assign it to, even if you're running it off of some handle attached to the creature. You have to assign this command to the creature, then you might get something. So yeah, go do what you were doing.

Think, man. ActionEquipItem(object oItem, int iSlot); Where does it refer to the creature there? Nowhere. You're just telling air to equip oItem into iSlot. There's no default creature to assign it to, even if you're running it off of some handle attached to the creature. You have to assign this command to the creature, then you might get something. So yeah, go do what you were doing.

It's in the OnSpawn of an NPC. It is supposed to equip a random commoner's tunic so that the commoners spawn with different tunics. Getting the tag of the random tunic is simple and works, but it doesn't get equipped. The exact line is EquipItem(oTunic, INVENTORY_SLOT_CHEST);. Chest is the inventory slot right? I think so. Besides, I tried it with head and a helmet and that didnt work either. 

- Aloro
- Team Member; Retired with Honors
- Posts: 12805
- Joined: Sat Dec 28, 2002 5:11 am
- Location: Rainbow's End
- Contact:
Something like this should work:
Check to make sure that oTunic isn't OBJECT_INVALID (Tag error). Depending on what else you have going on in the OnSpawn, you might also need to send a ClearAllActions() call to the NPC with AssignCommand.
- Aloro
Code: Select all
AssignCommand(oNPC, ActionEquipItem(oTunic, INVENTORY_SLOT_CHEST));
- Aloro
Still doesn't work. I'll post my exact code here. At least I think it's the exact code, as NWN is tempermental and sometimes doesnt work, such as right now.
int iNum=Random(4)+1;
string sNum=IntToString(iNum);
string sTag="CommonersTunic"+sNum;
object oTunic=GetObjectByTag(sTag);
ClearAllActions();
object oNPC=OBJECT_SELF;
AssignCommand(oNPC, ActionEquipItem(oTunic, INVENTORY_SLOT_CHEST);
I'm fairly sure thats the exact code. Originally, I didnt have the ClearAllActions or AssignCommand, not that it really matters. Can you please tell me whats wrong with it? The only other option is to have blueprints for about twenty commoners of each race, but I'd like to avoid that if possible, especially since I'll probably add in more clothes later on.
int iNum=Random(4)+1;
string sNum=IntToString(iNum);
string sTag="CommonersTunic"+sNum;
object oTunic=GetObjectByTag(sTag);
ClearAllActions();
object oNPC=OBJECT_SELF;
AssignCommand(oNPC, ActionEquipItem(oTunic, INVENTORY_SLOT_CHEST);
I'm fairly sure thats the exact code. Originally, I didnt have the ClearAllActions or AssignCommand, not that it really matters. Can you please tell me whats wrong with it? The only other option is to have blueprints for about twenty commoners of each race, but I'd like to avoid that if possible, especially since I'll probably add in more clothes later on.
-
- Prince of Bloated Discourse
- Posts: 186
- Joined: Thu Feb 06, 2003 8:49 pm
- Location: Nova Scotia (GMT - 4)
You missed a round thing ')' on the end of CHEST. It might of just been a typo in the post because I don't think it would let you compile without that.
The Island(s) of Hala
http://www.hala-world.org
http://www.hala-world.org
- Aloro
- Team Member; Retired with Honors
- Posts: 12805
- Joined: Sat Dec 28, 2002 5:11 am
- Location: Rainbow's End
- Contact:
OK, I see a few things here I'd suggest changing...
1) You should just use a CreateObject instead of GetObjectByTag. If there exist more than one such tunic in the world, you're most likely telling the commoner to put on a tunic that he doesn't even have in his possession.
2) You need to use the resrefs to create objects. Make SURE you have entered the right ones, because a typo will cause everything to fail - and can crash your computer (ActionEquipItem gets screwy sometimes).
3) Instead of int iNum=Random(4)+1;, why not use d4(1)? Same result.
So I'd suggest something like this:
Replace "nw_cloth024" with the resref of your tunics. This script works fine - I just tested it, and it successfully creates the clothing and makes the commoner equip it.
- Aloro
1) You should just use a CreateObject instead of GetObjectByTag. If there exist more than one such tunic in the world, you're most likely telling the commoner to put on a tunic that he doesn't even have in his possession.
2) You need to use the resrefs to create objects. Make SURE you have entered the right ones, because a typo will cause everything to fail - and can crash your computer (ActionEquipItem gets screwy sometimes).
3) Instead of int iNum=Random(4)+1;, why not use d4(1)? Same result.
So I'd suggest something like this:
Code: Select all
void main()
{
int iNum=d4(1);
string sNum=IntToString(iNum);
string sTunicRR="nw_cloth024"; //"commonerstunic"+sNum;
object oTunic=CreateItemOnObject(sTunicRR, OBJECT_SELF, 1);
AssignCommand(OBJECT_SELF, ActionEquipItem(oTunic, INVENTORY_SLOT_CHEST));
}
- Aloro
- Aloro
- Team Member; Retired with Honors
- Posts: 12805
- Joined: Sat Dec 28, 2002 5:11 am
- Location: Rainbow's End
- Contact:
Errr... I suggested he replace Random(4)+1 with d4(1), as they are identical in output.Myk D'vor wrote:Little quibble... Random(4)+1 is not the same as d4()+1. Random(4) generates a number between 0 and 3, then add 1 and it becomes the same as d4(), which generates a number from 1 to 4.
Myk D'Vor

- Aloro
-
- Scholar of Fools
- Posts: 311
- Joined: Thu Apr 03, 2003 1:16 pm
- Location: Currently, NAS Whidbey Island, Washington State
- Contact:
Yes, those of us with the ability to do simple math without a calculator can see that... as can those of us who also grew up playing PnP, and learning how to use a calculator's random function when dice were in short supply...
"Don't worry, I'll have it all figured out by the time we reach the Frontier..."
"So what's that over there?"
"The Frontier..."
modified from The Last Starfighter
"So what's that over there?"
"The Frontier..."
modified from The Last Starfighter