Jump to content

Re-Equip worn armor script help


saintgrimm92

Recommended Posts

I'm tweaking my mod before it's final release and am looking for the transformations I've created to re-equip the items the player was wearing before they transformed... But I'm not good at scripting at all... Anyone wanna help me create the script?

 

This is what I have so far for the transformations (they're all pretty much the same, just a few diff properties)

Scriptname AAEmptyGodTransformScript extends activemagiceffect  


Armor Property boundArmor  Auto  
Idle Property IdleAnimation  Auto  
Explosion Property ExplosionEffect  Auto  
Idle Property IdleAnimationEnd  Auto 
WEAPON Property scythe  Auto  
armor property shield auto
spell property combat auto
spell property phantasm auto
spell property shieldspell auto
spell property stagger auto


EVENT OnEffectStart(Actor Target, Actor Caster)


Target.PlayIdle(IdleAnimation)
Utility.Wait(3)
Target.placeatme(ExplosionEffect)
Game.ShakeCamera(afDuration = 5)
caster.equipItem(boundArmor, TRUE, TRUE)
caster.equipItem(Scythe, TRUE, TRUE)
caster.equipItem(shield, TRUE, TRUE)
caster.addspell(combat)
caster.addspell(shieldspell)
caster.equipspell(phantasm, 2)
Utility.Wait(4)
Target.PlayIdle(IdleAnimationEnd)


endevent


EVENT OnEffectFinish(Actor Target, Actor Caster)


Target.placeatme(ExplosionEffect)
caster.removeitem(boundArmor,caster.getItemCount(boundArmor),TRUE)
caster.removeitem(scythe,caster.getItemCount(scythe),TRUE)
caster.removeitem(shield,caster.getItemCount(shield),TRUE)
caster.removespell(combat)
caster.removespell(shieldspell)
caster.removespell(phantasm)
stagger.cast(caster)


endEVENT
Link to comment
Share on other sites

I have no idea what you mean by store them in a variable...

 

Also, taking the example.... would I put this in the effect start,

 

Game.GetPlayer().GetWornForm(0x00000004) as Armor

Game.GetPlayer().GetWornForm(0x00000005) as Boots (or maybe as feet? lol no clue)

 

Then in the effect end

 

Game.GetPlayer().additem(0x00000004, true, true)

Game.GetPlayer().additem(0x00000005, true, true)

 

 

 

EDIT: And hello again! :P

Edited by saintgrimm92
Link to comment
Share on other sites

It's not foolproof and can probably be done more efficiently, but should do the armor they were wearing.

Scriptname AAEmptyGodTransformScript extends activemagiceffect

Armor Property boundArmor  Auto
Idle Property IdleAnimation  Auto
Explosion Property ExplosionEffect  Auto
Idle Property IdleAnimationEnd  Auto
WEAPON Property scythe  Auto
armor property shield auto
spell property combat auto
spell property phantasm auto
spell property shieldspell auto
spell property stagger auto

Form[] StoredForms

Event OnEffectStart(Actor Target, Actor Caster)
    Target.PlayIdle(IdleAnimation)
    Utility.Wait(3)
    Target.placeatme(ExplosionEffect)
    Game.ShakeCamera(afDuration = 5)
    
    StoredForms = StoreWornForms(Caster)
    
    caster.equipItem(boundArmor, TRUE, TRUE)
    caster.equipItem(Scythe, TRUE, TRUE)
    caster.equipItem(shield, TRUE, TRUE)
    caster.addspell(combat)
    caster.addspell(shieldspell)
    caster.equipspell(phantasm, 2)
    Utility.Wait(4)
    Target.PlayIdle(IdleAnimationEnd)
EndEvent

Event OnEffectFinish(Actor Target, Actor Caster)
    Target.placeatme(ExplosionEffect)
    caster.removeitem(boundArmor,caster.getItemCount(boundArmor),TRUE)
    caster.removeitem(scythe,caster.getItemCount(scythe),TRUE)
    caster.removeitem(shield,caster.getItemCount(shield),TRUE)
    caster.removespell(combat)
    caster.removespell(shieldspell)
    caster.removespell(phantasm)
    stagger.cast(caster)
    
    EquipStoredForms(caster)
EndEvent

Form[] Function StoreWornForms(Actor akActor)
    Form[] WornForms
    Int i
    Int SlotsChecked = (0x00100000 + 0x00200000 + 0x80000000)
    Int ThisSlot = 1
    while (ThisSlot < 0x80000000)
        If (Math.LogicalAnd(SlotsChecked, ThisSlot) != ThisSlot)
            Form ThisForm = akActor.GetWornForm(ThisSlot)
            If (ThisForm As Armor)
                i += 1
                WornForms = Utility.ResizeFormArray(WornForms, i, ThisForm)
                SlotsChecked += (ThisForm As Armor).GetSlotMask()
            Else ;no armor was found on this slot
                SlotsChecked += ThisSlot
            EndIf
        EndIf
        ThisSlot *= 2
    EndWhile
    Return WornForms
EndFunction

Function EquipStoredForms(Actor akActor)
    Int i = StoredForms.Length
    While i > 0
        i -= 1
        If !akActor.IsEquipped(StoredForms[i])
            akActor.EquipItem(StoredForms[i], False, True)
        EndIf
    EndWhile
EndFunction

Edit: Requires SKSE 1.7.3 or greater (due to using resize array)

Edited by sLoPpYdOtBiGhOlE
Link to comment
Share on other sites

In response to your pm...

This covers restoring weapon in left and right hand.

Also adds a check on equip that the actor still has the item before equipping.

(Just in case the actor drops the item from their inventory while transformed, this way they won't receive another item when they no longer have the item)

Scriptname AAEmptyGodTransformScript extends activemagiceffect

Armor Property boundArmor  Auto
Idle Property IdleAnimation  Auto
Explosion Property ExplosionEffect  Auto
Idle Property IdleAnimationEnd  Auto
WEAPON Property scythe  Auto
armor property shield auto
spell property combat auto
spell property phantasm auto
spell property shieldspell auto
spell property stagger auto

Form[] StoredForms
Form[] HandsRL

Event OnEffectStart(Actor Target, Actor Caster)
    Target.PlayIdle(IdleAnimation)
    Utility.Wait(3)
    Target.placeatme(ExplosionEffect)
    Game.ShakeCamera(afDuration = 5)

    StoredForms = StoreWornForms(Caster)

    caster.equipItem(boundArmor, TRUE, TRUE)
    caster.equipItem(Scythe, TRUE, TRUE)
    caster.equipItem(shield, TRUE, TRUE)
    caster.addspell(combat)
    caster.addspell(shieldspell)
    caster.equipspell(phantasm, 2)
    Utility.Wait(4)
    Target.PlayIdle(IdleAnimationEnd)
EndEvent

Event OnEffectFinish(Actor Target, Actor Caster)
    Target.placeatme(ExplosionEffect)
    caster.removeitem(boundArmor,caster.getItemCount(boundArmor),TRUE)
    caster.removeitem(scythe,caster.getItemCount(scythe),TRUE)
    caster.removeitem(shield,caster.getItemCount(shield),TRUE)
    caster.removespell(combat)
    caster.removespell(shieldspell)
    caster.removespell(phantasm)
    stagger.cast(caster)

    EquipStoredForms(caster)
EndEvent

Form[] Function StoreWornForms(Actor akActor)
    Form[] WornForms
    HandsRL = New Form[2]
    Form ThisForm
    Int i
    Int SlotsChecked = (0x00100000 + 0x00200000 + 0x80000000)
    Int ThisSlot = 1
    while (ThisSlot < 0x80000000)
        If (Math.LogicalAnd(SlotsChecked, ThisSlot) != ThisSlot)
            ThisForm = akActor.GetWornForm(ThisSlot)
            If (ThisForm As Armor)
                i += 1
                WornForms = Utility.ResizeFormArray(WornForms, i, ThisForm)
                SlotsChecked += (ThisForm As Armor).GetSlotMask()
            Else ;no armor was found on this slot
                SlotsChecked += ThisSlot
            EndIf
        EndIf
        ThisSlot *= 2
    EndWhile
    i = akActor.GetEquippedItemType(1)
    If i > 0 && i != 10
        HandsRL[0] = akActor.GetEquippedObject(1)
    EndIf
    i = akActor.GetEquippedItemType(0)
    If i > 0 && i != 10
        HandsRL[1] = akActor.GetEquippedObject(0)
    EndIf
    Return WornForms
EndFunction

Function EquipStoredForms(Actor akActor)
    Int i = StoredForms.Length
    While i > 0
        i -= 1
        If ((akActor.GetItemCount(StoredForms[i]) > 0) && (!akActor.IsEquipped(StoredForms[i])))
            akActor.EquipItem(StoredForms[i], False, True)
        EndIf
    EndWhile
    If (HandsRL[0] && (!akActor.IsEquipped(HandsRL[0])))
        If (HandsRL[0] As Spell)
            akActor.EquipSpell(HandsRL[0] As Spell, 1)
        Else
            If akActor.GetItemCount(HandsRL[0]) > 0
                akActor.EquipItemEx(HandsRL[0], 1)
            EndIf
        EndIf
    EndIf
    If (HandsRL[1] && (!akActor.IsEquipped(HandsRL[1])))
        If (HandsRL[1] As Spell)
            akActor.EquipSpell(HandsRL[1] As Spell, 0)
        Else
            If akActor.GetItemCount(HandsRL[1]) > 0
                akActor.EquipItemEx(HandsRL[1], 2)
            EndIf
        EndIf
    EndIf
EndFunction

Edit: Had to change things with equipping equipped weapons, spells, torches etc..

I overlooked the hand the weapon, spell or torch was in and equipped prior.

 

Now it restores any spell, weapon, torch to the correct hand providing the actor still has them in inventory before transforming back.

Excludes checking if they still have a prior equipped spell, due to spell natively can't be dropped from inventory like other items. :smile:

 

Since i don't have your spells and whatnot I tested the added functions by putting them in a script attached to a trigger volume.

OnTriggerEnter() event I store my stuff and unequip all.

OnTriggerLeave() event I re-equip my sttored stuff.

 

Tried different equipment before entering the trigger.

Each time when i left the trigger I was re-equipped with what I had prior.

 

Note: I wouldn't use this method for a stripping trigger volume, eg: spa or sauna..

Since their are a lot shorter and more efficient methods for strip and re-equip.

 

But for the instance your using where your only replacing certain weapons and armor, then those strip methods wouldn't work for your needs.

Edited by sLoPpYdOtBiGhOlE
Link to comment
Share on other sites

  • 6 months later...

I can't get this to work with if conditionals

 

if (akCaster.GetItemCount(SomeItem) == 0)
StoredForms = StoreWornForms(akCaster)
else
EquipStoredForms(akCaster)

 


The idea is the script fires off and checks if something is equipped, and if it is, stuff happens. if it isn't, other stuff happens.

I was hoping to add this functionality to the script. I can get it working when the if's are skipped like in the context of the response (OnEffectStart/OnEffectFinish)

The script in question is a transformation script itself, but runs like a toggle reliant on that conditional item present or not. So hitting it once would ideally store the forms, hitting it again would call them.


Sorry to barge into this thread and ask, this is literally the only good source of information I can find anywhere on it.

Edited by LoonyDoll
Link to comment
Share on other sites

  • Recently Browsing   0 members

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