Objects in container loose their keywords?

Post » Tue Jun 19, 2012 11:10 pm

Hello, i've a script attached on a weapon like this

Script This extends ObjectreferenceKeyword Property iron autoEvent OnEquipped(actor akactor)if (akactor == game.getplayer())  if (getbaseobject().haskeyword(iron))	  do this and that  endifendifendevent

When i test it on a weapon placed on the ground in the editor, it works perfectly. It does "this and that" and store correctly every variable.
If i place (in the editor) the same weapon in a container (or an actor or a merchant), when i equip it the "if keyword" part is jumped, like the objects has no keywords, but the rest of the script works perfectly.

It's a really strange behavior, because if the weapon is spawns on the ground, when i drop and get it in a container, it works perfectly :(
User avatar
Nitol Ahmed
 
Posts: 3321
Joined: Thu May 03, 2007 7:35 am

Post » Wed Jun 20, 2012 4:12 am

GetBaseObject() is a native function, so you can't call it on inventory items (or equipped items).

So it's probably that part that is failing, due to the ref's going AWOL when you put them into a container.
If you could store the baseform elsewhere when it's accessible, then the keyword will probably show up.

Yes it is strange. It was like this in FNV too. A script could be running on one object but act on another of the same kind.
User avatar
Jesus Lopez
 
Posts: 3508
Joined: Thu Aug 16, 2007 10:16 pm

Post » Tue Jun 19, 2012 8:54 pm

GetBaseObject() is a native function, so you can't call it on inventory items (or equipped items).

So it's probably that part that is failing, due to the ref's going AWOL when you put them into a container.
If you could store the baseform elsewhere when it's accessible, then the keyword will probably show up.

Yes it is strange. It was like this in FNV too. A script could be running on one object but act on another of the same kind.

But in the working case i call it on an inventory item, and it works.

I did 2 tests.
First test:
I tried anyway to eliminate GetBaseObject() and kept HasKeyword(iron) alone. It acts exaclty in the same way, working on ground items (so GetBaseObject() was uncessary in my script), and not on inventory spawned items. Maybe the problem is still present on hasKeyword()

Second test:
I added "weapon property WEAP auto" and called "WEAP.haskeyword(iron)" in the IF. It works.

So? I cannot call native functions on objects spawned inside a container?
User avatar
Elea Rossi
 
Posts: 3554
Joined: Tue Mar 27, 2007 1:39 am

Post » Wed Jun 20, 2012 10:54 am

I think the rule is that you can't rely on native functions working on 'self'. (like your first test.)

Weapon is a baseform.
So your second test used the result that self.gbo() would give you outside of an inventory?
I'm assuming WEAP was the same type of weapon that the objectRef is.

You could have passed in any baseform property and run HasKeyword on it, and it'll work.
User avatar
Teghan Harris
 
Posts: 3370
Joined: Mon Mar 05, 2007 1:31 pm

Post » Wed Jun 20, 2012 12:08 am

Items spawned inside a container are not valid object references until they've been taken out of the container and dropped into the gameworld. Once that's happened, an object reference has been created, and if its picked up it retains its object reference properties (though I'm not sure for how long, I've only tested it in the short term.) So its likely that any Object Reference functions you try to call on one of these container spawned items will fail until they've been dropped and picked back up.

If you only care about having this function execute when its the player that's equipping the weapon, you could create a quest alias for the player and attach a script to that with an http://www.creationkit.com/OnObjectEquipped_-_Actor block. Then run your code if that equipped item has the appropriate keyword.
User avatar
CORY
 
Posts: 3335
Joined: Sat Oct 13, 2007 9:54 pm

Post » Wed Jun 20, 2012 5:35 am

Thank you for your help tunaisafish and Imp of the Perverse! :)
I think i'll solve the problem with your advices ;)
User avatar
Nitol Ahmed
 
Posts: 3321
Joined: Thu May 03, 2007 7:35 am


Return to V - Skyrim