Getting the Form of an ObjectReference in a container

Post » Thu Jun 21, 2012 9:24 am

So I have a script attached to a form (an armor, to be specific). There are 2 events: OnEquip and OnUnequip. However, to do what I want to do for these events, I need to check if the reference has a keyword. Of course, references don't carry the keywords of their forms, so I have to get the form for the armor.

I first tried to cast the reference as a form. That returns none. I then tried to use GetBaseObject (though I have a feeling that's not what it's for). That also returned none. I then tried to do the following...

Game.GetForm(GetFormID())

That returned none as well. So I did a little debugging, and found that "Self as String" gives "[ScriptName ]" or something like that, where # is some number depending on the item. I knew the FormID was that of the container because it was the FormID of the player.

So how the heck am I supposed to get the form of the armor the script is running on? The only way I've found to do it is the SKSE command "GetWornForm" which works fine for the "OnEquip" event, but the only way to get it to work for the "OnUnequip" event is to do this....

Event OnUnequipped(Actor akActor)Armor ArmorBak = (akActor.GetWornForm(0x00000004) as Armor)akActor.EquipItem(Self)Armor TheArmor = (akActor.GetWornForm(0x00000004) as Armor)akActor.UnEquipItem(Self)akActor.EquipItem(ArmorBak)

Needless to say, all the equipping and unequipping here wreaks havoc on my script, which I might be able to deal with, but I'd rather avoid it if possible.

It occurs to me that there's an SKSE function that gets the form of the nth object in a container. It also occurs to me that the script somehow knows what n is, because it told it to me in a string. Is there any way to get that number other than casting the object reference as a string?
User avatar
Kevin S
 
Posts: 3457
Joined: Sat Aug 11, 2007 12:50 pm

Post » Thu Jun 21, 2012 7:09 pm

There are 2 events: OnEquip and OnUnequip.

It's EquipPED.

An ObjectReference is a form. This works, if it's on an object in the world:

Scriptname TESTclothesScript extends ObjectReferenceKeyword Property AKeyword autoEvent OnEquipped(Actor akActor)     if HasKeyword(AKeyword)          Debug.MessageBox("I have the keyword")     endifendEvent

But there are problems with OnEquipped and scripts on items in containers (like the player's inventory), so you might think about using OnObjectEquipped on the player, instead.
User avatar
james reed
 
Posts: 3371
Joined: Tue Sep 18, 2007 12:18 am

Post » Thu Jun 21, 2012 11:27 am

Scriptname TESTclothesScript extends ObjectReferenceKeyword Property AKeyword autoEvent OnEquipped(Actor akActor)	 if HasKeyword(AKeyword)		  Debug.MessageBox("I have the keyword")	 endifendEvent

That's what I tried very first... It didn't work for me though.

I found a different way to do what I was trying to do, but it's not working quite right for reasons I don't understand (script is working on some objects it's attached to but not others) so I guess it's just buggy like you said. I might end up attaching it to the player, but I'd rather it work on all actors. How do I use a script on the player?

EDIT: Just fixed my problems, I had a backup version of my mod active by accident from before I'd attached the keywords! It's pretty possible all my problems today stemmed from that, including my initial problem of the ObjectReference not having the keywords *facepalm* oh well, at least I learned a lesson not to keep my backups in my data folder!
User avatar
Shelby Huffman
 
Posts: 3454
Joined: Wed Aug 08, 2007 11:06 am


Return to V - Skyrim