Jump to content

[LE] Script - Spell Effect, Storing equipped armor, removing, and then replacing at end of effect


Recommended Posts

Good morning (or afternoon/evening depending on where you're located),

 

I'm working on a script for an effect that essentially summons and equips a target (the player in my current case) with a unique set of armor. I've managed to get that part working great, however at the end of the effect it leaves the target with no armor/clothing on. Ideally I'm trying to figure out the best way to essentially record or store the target's original armor, so at the effect's finish, I can equip the target back in their original armor/clothing.

 

I haven't really spent a lot of time thinking this through just yet as I wrote what I have so far and created a retexture of an armor to use for the appearance of the spell's armor this morning, but alas I'm headed to work. Off the top of my head, I'm guessing I could try and look at how Dawnguard does it with the VampireLord transformation, but otherwise does anyone know any quick script functions off the top of their heads to essentially store what the target is wearing?

 

Either SKSE or not, just if it is an SKSE solution let me know when you type it.

 

Thanks so much and have a good day.

 

For reference here's the script as is atm:

;-- Properties --------------------------------------
armor property Cuirass auto
armor property Gloves auto
armor property Boots auto
armor property Helm auto

;-- Variables ---------------------------------------
Actor TargetActor

;-- Functions ---------------------------------------

function OnEffectStart(Actor Target, Actor Caster)
	TargetActor = Target
	Target.EquipItem(Cuirass as Form, true, true)
	Target.EquipItem(Gloves as Form, true, true)
	Target.EquipItem(Boots as Form, true, true)
	Target.EquipItem(Helm as Form, true, true)
endFunction

function OnEffectFinish(Actor Target, Actor akCaster)
	Target.UnequipItem(Cuirass as Form, true, true)
	Target.UnequipItem(Gloves as Form, true, true)
	Target.UnequipItem(Boots as Form, true, true)
	Target.UnequipItem(Helm as Form, true, true)
	Target.RemoveItem(Cuirass as Form, Target.GetItemCount(Cuirass as Form), true, none)
	Target.RemoveItem(Gloves as Form, Target.GetItemCount(Gloves as Form), true, none)
	Target.RemoveItem(Boots as Form, Target.GetItemCount(Boots as Form), true, none)
	Target.RemoveItem(Helm as Form, Target.GetItemCount(Helm as Form), true, none)
endFunction
Link to comment
Share on other sites

There isn't a quick function for it, as far as I know, but you will need SKSE. You'll need to use GetWornForm from SKSE to determine what item is equipped - the default functions only let you equip/unequip items based on slot numbers, they have no way to determine what items are currently equipped.

Link to comment
Share on other sites

Thanks for the reply. I'm still at work but I was pondering it a bit and was thinking it was going to require something along those lines lines.

 

Otherwise I was thinking about trying to have the script store the original armor/clothes as a global at the beginning of the script and then at the end try and have it equip them based on the data I stored before. I just wasn't sure if it was going to work and if it did reequip everything that it took it from the target's inventory as opposed to duplicating a 2nd set, so I could preserve any player added enchantments or such that might be on the item.

Link to comment
Share on other sites

You might want to look at some mods that unequip items temporarily and later reequip them. Bathing in Skyrim, for example, does something similar to your thoughts: store the original armor/clothes as a global, then remove and reequip based on that list. Mind you it does more than just the four basic armor slots, so it is a little more complex (I think it supports around 30 slots). Though the method it uses also seems to have a bug that doesn't reapply player added enchantments when the items are equipped again.

Link to comment
Share on other sites

If you can put the target actor into a quest alias you can use OnObjectUnequipped to grab the items being removed when you equip your own items and store them in a formlist or within properties for later re-equipping. However, there will be an issue with re-equipping items via script. DarkRudra mentioned it in passing. The issue is that items enchanted by the player only have an internal object reference ID within the save file. They do not have their own base ID. As a result, since player enchanted gear is not always persistent the returned ObjectReference value in the OnObjectUnequipped event will return none and you'll be left having to use the Form value instead. This ends up equipping the base item that the enchanted gear is derived from. Thankfully, the game also recognizes that the enchanted gear is derived from that base item and will equip it. It just cannot equip the enchanted portion properly. Thus the player is encouraged to re-equip the gear themselves or not use player created enchantments when using the mod in question.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...