Equipping items

Moderator: Event DM

Post Reply
User avatar
Jeffi0
Apprentice Scholar
Posts: 567
Joined: Fri Apr 04, 2003 12:57 am

Equipping items

Post by Jeffi0 » Mon Jul 28, 2003 2:38 am

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...
User avatar
maxinion
Team Member; Retired with Honors
Posts: 2778
Joined: Mon Mar 17, 2003 7:44 pm
DM Avatar: Andrinor
Location: Bay Area, CA
Contact:

Post by maxinion » Mon Jul 28, 2003 3:09 pm

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.

:P
User avatar
Jeffi0
Apprentice Scholar
Posts: 567
Joined: Fri Apr 04, 2003 12:57 am

Post by Jeffi0 » Mon Jul 28, 2003 3:24 pm

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. :D
User avatar
Jeffi0
Apprentice Scholar
Posts: 567
Joined: Fri Apr 04, 2003 12:57 am

Post by Jeffi0 » Mon Jul 28, 2003 4:41 pm

Still doesn't work. :(
User avatar
Jordicus
Team Member; Retired with Honors
Posts: 8042
Joined: Tue Jan 21, 2003 3:46 pm
Location: Whitehall, PA (GMT -4)
Contact:

Post by Jordicus » Mon Jul 28, 2003 5:04 pm

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
User avatar
Aloro
Team Member; Retired with Honors
Posts: 12805
Joined: Sat Dec 28, 2002 5:11 am
Location: Rainbow's End
Contact:

Post by Aloro » Mon Jul 28, 2003 5:27 pm

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
User avatar
Jeffi0
Apprentice Scholar
Posts: 567
Joined: Fri Apr 04, 2003 12:57 am

Post by Jeffi0 » Mon Jul 28, 2003 9:30 pm

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. :(
User avatar
Aloro
Team Member; Retired with Honors
Posts: 12805
Joined: Sat Dec 28, 2002 5:11 am
Location: Rainbow's End
Contact:

Post by Aloro » Mon Jul 28, 2003 9:41 pm

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
User avatar
Jeffi0
Apprentice Scholar
Posts: 567
Joined: Fri Apr 04, 2003 12:57 am

Post by Jeffi0 » Mon Jul 28, 2003 10:14 pm

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. :)
User avatar
Aloro
Team Member; Retired with Honors
Posts: 12805
Joined: Sat Dec 28, 2002 5:11 am
Location: Rainbow's End
Contact:

Post by Aloro » Mon Jul 28, 2003 10:22 pm

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
User avatar
Jeffi0
Apprentice Scholar
Posts: 567
Joined: Fri Apr 04, 2003 12:57 am

Post by Jeffi0 » Mon Jul 28, 2003 11:31 pm

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.
pitched_black
Prince of Bloated Discourse
Posts: 186
Joined: Thu Feb 06, 2003 8:49 pm
Location: Nova Scotia (GMT - 4)

Post by pitched_black » Mon Jul 28, 2003 11:41 pm

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
User avatar
Jeffi0
Apprentice Scholar
Posts: 567
Joined: Fri Apr 04, 2003 12:57 am

Post by Jeffi0 » Tue Jul 29, 2003 12:03 am

Yeah, that was a typo. Can you see anything else wrong with it?
User avatar
Aloro
Team Member; Retired with Honors
Posts: 12805
Joined: Sat Dec 28, 2002 5:11 am
Location: Rainbow's End
Contact:

Post by Aloro » Tue Jul 29, 2003 12:04 am

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
User avatar
Jeffi0
Apprentice Scholar
Posts: 567
Joined: Fri Apr 04, 2003 12:57 am

Post by Jeffi0 » Tue Jul 29, 2003 1:48 am

Thanks Aloro, I'll use that. :)
Myk D'vor
Lord of Blithering Idiots
Posts: 111
Joined: Mon Feb 24, 2003 9:05 am

Post by Myk D'vor » Tue Jul 29, 2003 2:42 am

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
Falkin
Scholar of Fools
Posts: 311
Joined: Thu Apr 03, 2003 1:16 pm
Location: Currently, NAS Whidbey Island, Washington State
Contact:

Post by Falkin » Tue Jul 29, 2003 2:47 am

Ummm.... I think they already said that...
"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
User avatar
Aloro
Team Member; Retired with Honors
Posts: 12805
Joined: Sat Dec 28, 2002 5:11 am
Location: Rainbow's End
Contact:

Post by Aloro » Tue Jul 29, 2003 4:00 am

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
Falkin
Scholar of Fools
Posts: 311
Joined: Thu Apr 03, 2003 1:16 pm
Location: Currently, NAS Whidbey Island, Washington State
Contact:

Post by Falkin » Tue Jul 29, 2003 4:02 am

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
Post Reply