Page 1 of 1
Equipping items
Posted: Mon Jul 28, 2003 2:38 am
by Jeffi0
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...
Posted: Mon Jul 28, 2003 3:09 pm
by maxinion
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.

Posted: Mon Jul 28, 2003 3:24 pm
by Jeffi0
I figured it'd automatically be the object that called it- that's what most are. Like ActionAttack, ActionMoveToObject, etc. I thought ActionEquipItem wouldn't be any different. Oh well, thanks.

Posted: Mon Jul 28, 2003 4:41 pm
by Jeffi0
Still doesn't work.

Posted: Mon Jul 28, 2003 5:04 pm
by Jordicus
you sure it should be OBJECT_SELF that is referred to? if an item is firing the script, the OBJECT_SELF refers to the item, not the holder
Posted: Mon Jul 28, 2003 5:27 pm
by Aloro
OK, let's back up a step here... we don't have enough information to answer your questions.
First, when and where is this script fired? Is it e.g. off a trigger, off a conversation, off the OnEnter of an area, or what?
Second, what are you trying to equip, and on whom? Is it a PC or NPC?
- Aloro
Posted: Mon Jul 28, 2003 9:30 pm
by Jeffi0
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.

Posted: Mon Jul 28, 2003 9:41 pm
by Aloro
Something like this should work:
Code: Select all
AssignCommand(oNPC, ActionEquipItem(oTunic, INVENTORY_SLOT_CHEST));
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
Posted: Mon Jul 28, 2003 10:14 pm
by Jeffi0
Thanks! I'll try that. I dont get why it should need an AssignCommand though, cause its for the NPC thats calling it anyway. Does this happen with other commands? I havent seen this happen befor, but there are a LOT of commands I havent used yet.

Posted: Mon Jul 28, 2003 10:22 pm
by Aloro
I always manually insert the subject of any script. Sometimes OBJECT_SELF is implicit, and sometimes it isn't. I just make a habit of always specifying, so I'm never susprised by it not working.
- Aloro
Posted: Mon Jul 28, 2003 11:31 pm
by Jeffi0
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.
Posted: Mon Jul 28, 2003 11:41 pm
by pitched_black
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.
Posted: Tue Jul 29, 2003 12:03 am
by Jeffi0
Yeah, that was a typo. Can you see anything else wrong with it?
Posted: Tue Jul 29, 2003 12:04 am
by Aloro
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:
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));
}
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
Posted: Tue Jul 29, 2003 1:48 am
by Jeffi0
Thanks Aloro, I'll use that.

Posted: Tue Jul 29, 2003 2:42 am
by Myk D'vor
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
Posted: Tue Jul 29, 2003 2:47 am
by Falkin
Ummm.... I think they already said that...
Posted: Tue Jul 29, 2003 4:00 am
by Aloro
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
Errr... I suggested he replace Random(4)+1 with d4(1), as they are identical in output.
- Aloro
Posted: Tue Jul 29, 2003 4:02 am
by Falkin
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...