Equip an Item if Another is Equipped

Post » Sun Sep 09, 2012 6:07 pm

--> Snapshot: I want to know how to make an item autoequip on a NPC if another base object is equpped on them, as well as how to use the GetEquippedItems OBSE funtion. <--

So I have this clothing mod that has an outfit that is broken into multiple parts. One part of it is assinged to the tailslot, and the thing you may all know about the tailslot is NPCs tend to ignore such items. I can get an NPC to wear the entire outfit, inlcuding the tailslot item, while I have them directly under my command (using another mod), but as soon as I release them to go about their business, they unequip the tailslot item.

I like to poke around and tweak my mods, and I'd noticed a bit of code in another mod that auto-equipped tailslot items, and at first I just copied and pasted that code directly to this mod. But then I decided that I wanted to improve it's fuctionality by having the code test to see if the NPC was wearing the rest of the outfit and then and only then forcing them to equip the tailslot item.

The problem is, while I can use GetEquippedObject to find out what the owner (the container of the object, which i've already tested and proven to be an NPC) of the tailslot is wearing, I don't know how to tell if this reference is a specific base ojbect. I need to be able to do the base object/Form ID rather than do a reference comparison because I need it to work with any copy of that outfit. I don't want to have it work with just one outfit, I want to be able to have an unknown number of copies of said outfit and have it work on all of them.

Here is the code I've come up with so far:
scn TailSlotSctref Ownerref Meref Pantsbegin GameMode	set Me to GetBaseObject	set Owner to GetContainer	if ( Me.IsEquipped ) ;if this item is already equipped, no need to do anything.		return	elseif ( Owner.IsActor != 1 ) ;if this item is not in an NPC's inventory, no need to do anything.		return	endif	set Pants to Owner.GetEquippedObject 3 ;get what pants the NPC is wearing, so we can test if they are the pants that go with this item.	if (  )		Owner.EquipItemSilent Me ;Silently equip the item, don't display a message or play the equip soundeffect.	endifend

Also, I want to know how to use the GetEquippedItems function from OBSE. The documentation says merely that it returns an array. It gives no information about said array, like the order of items in it, where what is stored, or basically anything that one would need to know to be able to actually use said fuction. I don't know if it will help me out here, but I want to know how to use it (and arrays in general) regardless.
User avatar
Leah
 
Posts: 3358
Joined: Wed Nov 01, 2006 3:11 pm

Post » Sun Sep 09, 2012 6:37 pm

You have your base/reference usage confused. Items in an inventory are always base objects (the OBSE inventory reference is a hack around that, but ignore it for now because it doesn't help you here). Also, for every function the syntax is reference.Function base. You can't use a base record in the reference spot like you did here
set Me to GetBaseObject...if ( Me.IsEquipped )
you need to use
if ( Owner.IsActor ) ;Have to test this first...	if ( Owner.GetEquipped Me)

As for GetEquippedItems, I assume the items aren't in any particular order. The array is the simple one - index 0-n with values of the base records (the documentation would read (items:Map) reference.GetEquippedItems or (items:StringMap) reference.GetEquippedItems if it was one of the others). You'd iterate through the array and use functions like http://cs.elderscrolls.com/index.php/GetEquipmentSlot and http://cs.elderscrolls.com/index.php/GetIsID to figure out what the item is, how you want to process it, etc. Arrays are described in the Array section of the OBSE documents, as well as Wikipedia for more examples. Iteration is described in the Flow Control section, particularly ForEach.
User avatar
Janine Rose
 
Posts: 3428
Joined: Wed Feb 14, 2007 6:59 pm


Return to IV - Oblivion