Jump to content

Script works but can it be better?


Recommended Posts

What maxaturo said. I would advise though making two versions of your mod. An SKSE version and a None SKSE version. You can put them both up on your mod page under main files and direct users to use one or the other. That way you don't need to add checks in your scripts. Good luck with the mod though!

Link to comment
Share on other sites

You don't need to add them as "extra dependencies", you just include in your mod (in their corresponding folders) the "scripts - pex - psc" and the "po3_papyrusextender.dll" in the skse plugins folder.

That's all...

Oh, I read the page for the mod but didn't realise that the author allowed redistribution, I should get new glasses:)

Link to comment
Share on other sites

. An SKSE version and a None SKSE version. You can put them both up on your mod page under main files and direct users to use one or the other. That way you don't need to add checks in your scripts.

Well I already have an skse aware/non-skse version and an mcm aware version in the fomod, plus lots of patches. It will be easier to keep a version that covers both skse and non-skse but using the dll has potential, I shall rustle up a version for testing.

 

diziet

Link to comment
Share on other sites

 

You don't need to add them as "extra dependencies", you just include in your mod (in their corresponding folders) the "scripts - pex - psc" and the "po3_papyrusextender.dll" in the skse plugins folder.

That's all...

Oh, I read the page for the mod but didn't realise that the author allowed redistribution, I should get new glasses:)

 

 

Making an SKSE plugin extension with no permission to "distribute" would make no sense !, because no modder would be able to use it.
Have a nice weekend.
Link to comment
Share on other sites

 

 

Making an SKSE plugin extension with no permission to "distribute" would make no sense !, because no modder would be able to use it.

Indeed, but I thought the 'distribution' was to be by downloading the mod as-is. :)

Into work tomorrow, rather that than staying at home like so many these days. Anyone reading this stuck indoors, stay frosty!

 

diziet

Link to comment
Share on other sites

dizietemblesssma wrote: "Well I already have an skse aware/non-skse version and an mcm aware version in the fomod, plus lots of patches."

I had never seen a non skse script version from you. Are you sure with this?

My advice do not overwhelming you mod download page with too many patches. It is not very userfriendly.

 

In times of "Corona" I can go a bit deeper with your script and that is the result.

 

dz_mcm_ActivatorScript

 

Scriptname dz_mcm_ActivatorScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/8502938-script-works-but-can-it-be-better/

  dz_mcm_QuestScript PROPERTY mcm auto            ; the mcm quest script
  ; dz_mcm_ver2_undressing_script

  Spell PROPERTY dz_naked_spell_ver2  auto        ; the spell

  Form[] Armor_1
  Form[] Fight
      ; 0: spell Left hand
    ; 1: spell Right hand
    ; 2: spell other
    ;;; 3: spell instant
    ; [4] shout
    ; [5] Shield equipped, if any
    ; [6] Weapon Right hand equipped
    ; [7] Weapon Left hand equipped
    ; [8] Ammo equipped, if any
    ; [9] Torch, if any

  Actor player        ; [default=None]
  Bool  disrobed    ; [default=False] to track player naked
  Bool  bSkyUI        ; [default=False]    


; -- EVENTs -- 3

EVENT OnInit()
;===========
    Debug.Trace(self+" OnInit() - has been installed!")
ENDEVENT

EVENT OnCellAttach()
    player = Game.GetPlayer()
    bSkyUI = Game.GetFormFromFile(0x00000814, "SkyUI_SE.esp")
ENDEVENT

EVENT OnCellDetach()
    player = None
ENDEVENT


EVENT OnTriggerEnter(ObjectReference triggerRef)
;===================
IF (triggerRef as Actor == player)
    myF_ENTER()
    RETURN    ; - STOP -
ENDIF
;---------------------
    IF (triggerRef as Actor)
        myF_TrySpell(triggerRef, TRUE)
    ENDIF
ENDEVENT


EVENT OnTriggerLeave(ObjectReference triggerRef)
;===================
IF (triggerRef as Actor == player)
    myF_LEAVE()
    RETURN    ; - STOP -
ENDIF
;---------------------
    IF (triggerRef as Actor)
        myF_TrySpell(triggerRef, False)
    ENDIF
ENDEVENT


; -- FUNCTIONs -- 6

;----------------------------------------------------------
FUNCTION myF_TrySpell(ObjectReference triggerRef, Bool bOK)  ; NPCs only
;----------------------------------------------------------
IF ( !bOK )
    (triggerRef as Actor).DispelSpell(dz_naked_spell_ver2)        ; Dispel
    RETURN    ; - STOP -
ENDIF
;---------------------
    IF (!mcm.ignoreCombat) && (triggerRef as Actor).IsInCombat()
    ELSE
        ; actor "should ignore combat" or "is not in combat"
        dz_naked_spell_ver2.Cast(triggerRef, triggerRef)          ; SpellCasting
    ENDIF
ENDFUNCTION


;----------------------------
FUNCTION myF_Arrays(Bool bOK)
;----------------------------
    IF ( bOK )                      ; init arrays
        Armor_1 = new Form[10]
        Fight   = new Form[10]
    ELSE                            ; destroy arrays
        form[] b
        Armor_1 = b
        Fight   = b
    ENDIF
ENDFUNCTION


;-----------------------------------------------
FUNCTION myF_OtherItems(Actor aRef, Bool bTorch)
;-----------------------------------------------
;IF (SKSE.GetVersion() > 0)
;ELSE
;    RETURN None        ; SKSE not found!
;ENDIF
;---------
    int i                 ; i = Z
    int n                           ; [default=0], array counter armor

    IF ( aRef )                    ; actor is valid?
        i = aRef.GetNumItems()                                ; SKSE required!
    ENDIF

    bool bOK = TRUE

WHILE (i)                 ; (i > 0)
    i = i - 1
    form fm = aRef.GetNthForm(i)                              ; SKSE required!

    IF (fm as Armor)                            ; armor
        IF aRef.IsEquipped(fm) ;&& (n < 10)
            ; we assume more than 10 items cannot be equipped as armor
            Armor_1[n] = fm
            n = n + 1        
        ENDIF
    
    ELSEIF (fm as Ammo) && (bOK)                ; ammo
        IF aRef.IsEquipped(fm)
            bOK = False
            Fight[8] = fm
        ENDIF
    
    ELSEIF (fm as Light) && (bTorch)            ; torchLight
        IF aRef.IsEquipped(fm)
            bTorch = False
            Fight[9] = fm
        ENDIF    
    ENDIF
ENDWHILE
ENDFUNCTION


;------------------
FUNCTION myF_SAVE()
;------------------
; https://www.creationkit.com/index.php?title=GetEquippedItemType_-_Actor
; Gets the type of item the actor currently has equipped in the specified hand.
;    0: Nothing (Hand to hand)
;    1: One-handed sword
;    2: One-handed dagger
;    3: One-handed axe
;    4: One-handed mace
;    8: Staff

;    5: Two-handed sword
;    6: Two-handed axe or warhammer
;    7: Bow
;   12: Crossbow

;    9: Magic spell
;   10: Shield
;   11: Torch

    bool bTorch = False
    form fm

    Fight[6] = player.GetEquippedWeapon(False) as Form                              ; 6
    int i = player.GetEquippedItemType(1)                ; Right (weapon hand)

    IF (i == 12) || ((i >= 5) && (i <= 7))
        ; two-handed weapon
    ELSE
        IF (i == 9)            ; magic right hand
            Fight[1] = player.GetEquippedSpell(1) as Form                           ; 1,  Fight[6] = None
        ENDIF

        i = player.GetEquippedItemType(0)                ; Left (shield hand)

        IF     (i == 11)    ; torch in left hand only
            bTorch = TRUE                                                           ; 9,  Fight[7] = None

        ELSEIF (i == 10)
            Fight[5] = player.GetEquippedShield() as Form                           ; 5,  Fight[7] = None

        ELSEIF (i == 9)        ; magic left hand
            Fight[0] = player.GetEquippedSpell(0) as Form                           ; 0,  Fight[7] = None

        ELSEIF (i != 0)        ; one-handed weapon
            Fight[7] = player.GetEquippedWeapon(TRUE) as Form                       ; 7
        ENDIF
    ENDIF
; ------------------------------------------
    myF_OtherItems(player, bTorch)                        ; Armor, Ammo, Torch

    fm = player.GetEquippedShout()  as Form                                         ; 4
    IF ( fm )
        Fight[4] = fm
        player.UnEquipShout(fm as Shout)                ; shout
    ENDIF

; ---
;    Fight[3] = player.GetEquippedSpell(3) as Form                                  ; 3  instant
; ---
    Fight[2] = player.GetEquippedSpell(2) as Form                                   ; 2  other
    i = 3
    WHILE (i)
        i = i - 1
        fm = Fight[i]            ; [2] .. [0]
        IF ( fm )
            player.UnEquipSpell(Fight[i] as Spell, i)
        ENDIF
    ENDWHILE
ENDFUNCTION


;-------------------
FUNCTION myF_ENTER()
;-------------------
IF (SKSE.GetVersion() > 0)
ELSE
    RETURN    ; - STOP - SKSE not found!
ENDIF
;---------------------
; check for skyui
    IF ( !bSkyUI )
        debug.notification("You have installed the SkyUI version of this mod, but 'SkyUI_SE.esp' was not found!")

    ELSEIF Game.IsCamSwitchControlsEnabled()
    ; switch cam is possible for player

        if ( mcm.third_person )
        ; change to third person specified by mcm, if not already there
        
            IF (Game.GetCameraState() == 0)                   ; SKSE required!
                Game.ForceThirdPerson()            ; 3rd
            ENDIF
        else
        ; otherwise stay in first person, if not already there

            IF (Game.GetCameraState() == 0)                   ; SKSE required!
            ELSE
                Game.ForceFirstPerson()            ; 1th
            ENDIF
        endif
    ENDIF

IF ( mcm.disrobes )
    ; == TRUE
ELSE
    RETURN    ; - STOP -    do not make player naked
ENDIF
;---------------------
IF ( mcm.ignoreCombat )
    ; == TRUE
ELSE
    IF player.IsInCombat()
        RETURN    ; - STOP -    player is in combat, but combat should not be ignored
    ENDIF
;    ----------------------
ENDIF

IF ( disrobed )
    RETURN    ; - STOP -    threadLock active
ENDIF
;---------------------
    disrobed = TRUE            ; *T*

    myF_Arrays(TRUE)        ; init
    myF_SAVE()

; "Forces this actor to unequip all currently equipped items." (spells, shout excluded)
    player.UnEquipAll()        ; make player naked
ENDFUNCTION


;-------------------
FUNCTION myF_LEAVE()
;-------------------
IF (SKSE.GetVersion() > 0)
ELSE
    RETURN    ; - STOP - SKSE not found!
ENDIF
;---------------------
;return to first person if necessary

    IF Game.IsCamSwitchControlsEnabled()
    ; switch cam is possible for player

        if ( mcm.third_person )
        ; change to third person if not already if mcm specifies
        
            IF (Game.GetCameraState() == 0)                   ; SKSE required!
            ELSE
                Game.ForceFirstPerson()            ; 1th
            ENDIF
        endif
    ENDIF

IF ( disrobed )                ; ***
;;    debug.messagebox("Re-equipping armour")
ELSE
    RETURN    ; - STOP -    player is not naked
ENDIF
;---------------------
; https://www.creationkit.com/index.php?title=EquipItemEx_-_Actor
    form fm
    int i

;re-equip the armor array
    i = Armor_1.Length
    WHILE (i)
        i = i - 1
        fm = Armor_1[i]
        IF ( fm )            ; default slot
            player.EquipItemEx(fm, 0, False, False)           ; SKSE required!
        ENDIF
    ENDWHILE

;re-equip spells
    i = 4
    WHILE (i)
        i = i - 1
        fm = Fight[i]
        IF ( fm )    
            player.EquipSpell(fm as Spell, i)
        ENDIF
    ENDWHILE

;re-equip shout
    fm = Fight[4]
    IF ( fm )        ; player_shout
        player.EquipShout(fm as Shout)
      ENDIF

;re-equip shield
    fm = Fight[5]
    IF ( fm )        ; player_shield
        player.EquipItemEx(fm, 0, False, TRUE)                ; SKSE required!
    ENDIF

;re-equip weapons
    fm = Fight[6]
    IF ( fm )                ; equippedRight
        player.EquipItemEx(fm, 1, False, TRUE)                ; SKSE required!
    ENDIF

    fm = Fight[7]
    IF ( fm )                ; equippedLeft
        player.EquipItemEx(fm,  2, False, TRUE)               ; SKSE required!
    ENDIF

;re-equip ammo
    fm = Fight[8]
    IF ( fm )        ; player_ammo
        player.EquipItemEx(fm, 0, False, False)               ; SKSE required!
      ENDIF

;re-equip torch
    fm = Fight[9]
    IF ( fm )        ; player_torch
        player.EquipItem(fm, False, TRUE)
      ENDIF

    myF_Arrays(False)        ; destroy
    disrobed = False        ; ***
ENDFUNCTION

 

 

 

dz_mcm_QuestScript

 

Scriptname dz_mcm_QuestScript extends SKI_ConfigBase
; https://forums.nexusmods.com/index.php?/topic/8244443-access-variable-from-other-script/
 
 ;Bool[] PROPERTY o auto Hidden
  Bool PROPERTY disrobes     auto Hidden    ; _toggle_State1, [default=False]
  Bool PROPERTY third_person auto Hidden    ; _toggle_State2
  Bool PROPERTY ignoreCombat auto Hidden    ; _toggle_State3

  Int[] a
      ; 0 allowPlayerSetting
      ; 1 thirdPersonSetting
      ; 2 ignoreCombatSetting


; -- EVENTs -- 4

EVENT OnConfigInit()
;=================
    Pages = new String[1]
    Pages[0] = "Options menu"

    a = new Int[3]
;;;    o = new Bool[3]
ENDEVENT


EVENT OnPageReset(String a_page)
;===============================
{Called when a new page is selected, including the initial empty page}
;IF (page == "")
;    LoadCustomContent("SkyBuild.dds", 0, 50)
;    RETURN    ; - STOP -
;ENDIF
;;---------------------
;    UnloadCustomContent()

    SetCursorFillMode(TOP_TO_BOTTOM)
    AddHeaderOption("Player Disrobing Options")

    AddEmptyOption()
    a[0] = AddToggleOption("Player Undresses",   disrobes)

    AddEmptyOption()
    a[1] = AddToggleOption("Force Third Person", third_person)

    AddEmptyOption()
    a[2] = AddToggleOption("Ignore Combat any",  ignoreCombat)
ENDEVENT


EVENT OnOptionHighlight(Int a_option)
;======================
    IF     (a_option == a[0])
        SetInfoText("option 1")

    ELSEIF (a_option == a[1])
        SetInfoText("option 2")

    ELSEIF (a_option == a[2])
        SetInfoText("option 3")
    ENDIF
ENDEVENT


EVENT OnOptionSelect(Int a_option)
;===================
IF (a_option == a[0])
    disrobes = !disrobes
    SetToggleOptionValue(a_option, disrobes)
    RETURN    ; - STOP -
ENDIF
;---------------------
IF (a_option == a[1])
    third_person = !third_person
    SetToggleOptionValue(a_option, third_person)
    RETURN    ; - STOP -
ENDIF
;---------------------
IF (a_option == a[2])
    ignoreCombat = !ignoreCombat
    SetToggleOptionValue(a_option, ignoreCombat)
ENDIF
ENDEVENT


EVENT OnOptionDefault(Int a_option)
;====================
IF (a_option == a[0])
    disrobes = TRUE
    SetToggleOptionValue(a_option, disrobes)
     RETURN    ; - STOP -
 ENDIF
;---------------------
IF (a_option == a[1])
    third_person = TRUE
    SetToggleOptionValue(a_option, third_person)
    RETURN    ; - STOP -
ENDIF
;---------------------
IF (a_option == a[2])
    ignoreCombat = False
    SetToggleOptionValue(a_option, ignoreCombat)
ENDIF
ENDEVENT

 

 

Link to comment
Share on other sites

The first script I posted checked for skse and if not found used equipitem instead of equipitemex, the player lost both hands weapon equipping but everything I've read says that skse is needed to do that. Just recently I've had great help using skse to add ammo functionality.

 

All my patches are in one FOMOD, the FOMOD selects the mcm versus non-mcm version based on the presence of SkyUi.esp, the user still has the option to choose the non-mcm version if they want. The non-mcm version is the one that checks for skse and uses equipitem if necessary,

The limit on mcm menus, though large (well for me it would be) means I don't want to force a user to have one, its only real utility is the ignore combat check, some player homes are in wilderness areas with wild animals such that even after entering a home the player is still deemed in combat and won't undress even if alone! And turning off player undressing seems to defeat the point of the patch.:)

 

Some player homes already have NPC undressing so I have versions of those two scripts that just add player undressing, a total of 4 scripts. The FOMOD keeps track of player homes detected and selects the appropriate scrips and esps for install.

 

I notice tnat you added torch to the activator script, is a torch not something that my existing script would pick up? I had thought it to be treated as a weapon. If not then I can see it's utility for completeness, though I image few players wanting to enter a pool or bath holding a torch; not if they were expecting to 'unequipall' once in. :)

 

diziet

Link to comment
Share on other sites

dz_mcm_ActivatorScript

 


EVENT OnCellAttach()
    player = Game.GetPlayer()
    bSkyUI = Game.GetFormFromFile(0x00000814, "SkyUI_SE.esp")
ENDEVENT

EVENT OnCellDetach()
    player = None
ENDEVENT


 

 

I'm not sure what these lines are for. I looked up OnCellAttach https://www.creationkit.com/index.php?title=OnCellAttach_-_ObjectReference and the talk page but I'm still a bit confused as to why you feel they are needed.

 

I'm getting lots of interesting and useful info from this and other threads, I feel the need to read and understand before moving on to what will probably be ver3 of my mod patches!

Although with all those already existing patches with triggerboxes and attached scripts I guess I'll be keeping the filenames. :smile:

Link to comment
Share on other sites

event OnCellAttach() will be fired here, if player and activator (which has this script attached) share the same parent cell, the detach event is fired as opposite

 

It is always a good idea to shrink the memory usage of actor and objectreference as much as possible, because of persistence.

To check Skyui mod loaded we can use the attach event too.

 

I came across with another idea (for naked player), because you are using a spell for npcs, but not for the player.

Scripts could be as follow:

 

dz_mcm_ActivatorScript

 

Scriptname dz_mcm_ActivatorScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/8502938-script-works-but-can-it-be-better/

  dz_mcm_QuestScript PROPERTY mcm auto          ; the mcm quest script
  ; dz_mcm_ver2_undressing_script

  Spell PROPERTY dz_naked_spell_ver2   auto     ; for NPCs like follower
  Spell PROPERTY dz_naked_spell_player auto     ; for player exclusive

  Actor player      ; [default=None]
  Bool  disrobed    ; [default=False] to track player naked
  Bool  bSkyUI      ; [default=False]    


; -- EVENTs -- 3

EVENT OnInit()
;===========
    Debug.Trace(self+" OnInit() - has been installed!")
ENDEVENT

EVENT OnCellAttach()
    player = Game.GetPlayer()
    bSkyUI = Game.GetFormFromFile(0x00000814, "SkyUI_SE.esp")
ENDEVENT

EVENT OnCellDetach()
    player = None
ENDEVENT


EVENT OnTriggerEnter(ObjectReference triggerRef)
;===================
IF (triggerRef as Actor == player)
    myF_ENTER()
    RETURN    ; - STOP -
ENDIF
;---------------------
    IF (triggerRef as Actor)
        myF_TrySpell(triggerRef, TRUE)
    ENDIF
ENDEVENT


EVENT OnTriggerLeave(ObjectReference triggerRef)
;===================
IF (triggerRef as Actor == player)
    myF_LEAVE()
    RETURN    ; - STOP -
ENDIF
;---------------------
    IF (triggerRef as Actor)
        myF_TrySpell(triggerRef, False)
    ENDIF
ENDEVENT


; -- FUNCTIONs -- 3

;----------------------------------------------------------
FUNCTION myF_TrySpell(ObjectReference triggerRef, Bool bOK)  ; NPCs only
;----------------------------------------------------------
IF ( !bOK )
    (triggerRef as Actor).DispelSpell(dz_naked_spell_ver2)        ; Dispel
    RETURN    ; - STOP -
ENDIF
;---------------------
    IF (!mcm.ignoreCombat) && (triggerRef as Actor).IsInCombat()
    ELSE
        ; actor "should ignore combat" or "is not in combat"
        dz_naked_spell_ver2.Cast(triggerRef, triggerRef)          ; SpellCasting
    ENDIF
ENDFUNCTION


;-------------------
FUNCTION myF_ENTER()
;-------------------
IF (SKSE.GetVersion() > 0)
ELSE
    RETURN    ; - STOP - SKSE not found!
ENDIF
;---------------------
; check for skyui
    IF ( !bSkyUI )
        debug.notification("You have installed the SkyUI version of this mod, but 'SkyUI_SE.esp' was not found!")

    ELSEIF Game.IsCamSwitchControlsEnabled()
    ; switch cam is possible for player

        if ( mcm.third_person )
        ; change to third person specified by mcm, if not already there
        
            IF (Game.GetCameraState() == 0)                   ; SKSE required!
                Game.ForceThirdPerson()            ; 3rd
            ENDIF
        else
        ; otherwise stay in first person, if not already there

            IF (Game.GetCameraState() == 0)                   ; SKSE required!
            ELSE
                Game.ForceFirstPerson()            ; 1th
            ENDIF
        endif
    ENDIF

IF ( mcm.disrobes )
    ; == TRUE
ELSE
    RETURN    ; - STOP -    do not make player naked
ENDIF
;---------------------
IF ( mcm.ignoreCombat )
    ; == TRUE
ELSE
    IF player.IsInCombat()
        RETURN    ; - STOP -    player is in combat, but combat should not be ignored
    ENDIF
;    ----------------------
ENDIF

    IF ( disrobed )
    ELSE
        disrobed = TRUE            ; *T*
        dz_naked_spell_player.Cast(player, player)        ; cast spell on player
    ENDIF
ENDFUNCTION


;-------------------
FUNCTION myF_LEAVE()
;-------------------
IF (SKSE.GetVersion() > 0)
ELSE
    RETURN    ; - STOP - SKSE not found!
ENDIF
;---------------------
;return to first person if necessary

    IF Game.IsCamSwitchControlsEnabled()
    ; switch cam is possible for player

        if ( mcm.third_person )
        ; change to third person if not already if mcm specifies
        
            IF (Game.GetCameraState() == 0)                   ; SKSE required!
            ELSE
                Game.ForceFirstPerson()            ; 1th
            ENDIF
        endif
    ENDIF

    IF ( disrobed )
;;        debug.messagebox("Re-equipping armour")
        player.DispelSpell(dz_naked_spell_player)        ; Dispel player spell
        Utility.Wait(0.1)
        disrobed = False        ; ***
    ENDIF
ENDFUNCTION

 

 

 

dz_mcm_PlayerNakedEffectScript

 

Scriptname dz_mcm_PlayerNakedEffectScript extends ActiveMagicEffect
; we assume player is Target of the spell (which has this scripted effect)

  Form[] myItems    ; will be filled with unequipped items and weapons
  Form[] myMagic    ; will be filled with spells and shout
  Int    n            ; [default=0], array counter

  Bool bSKSE        ; [default=False]
  Weapon weapL
  Weapon weapR


; -- EVENTs -- 3

; Event received when this effect is first started (OnInit may not have been run yet!)
Event OnEffectStart(Actor akTarget, Actor akCaster)
    Debug.Trace(" OnEffectStart() - target = " +akTarget+ "  " +self)    ; for debugging

    IF (akTarget == Game.GetPlayer())
        myF_Init(akTarget)
        myF_GetMagic(akTarget)
        akTarget.UnEquipAllItems()
    ENDIF
EndEvent


; Event received when this effect is finished (effect may already be deleted, calling functions on this effect will fail)
Event OnEffectFinish(Actor akTarget, Actor akCaster)
    Debug.Trace(" OnEffectFinish() - has been reached..  " +self)        ; for debugging
    myF_ReEquip()                    ; use dispelspell within activator script
EndEvent


; Event received when this actor unequips something - akReference may be None if object is not persistent
Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)
    myItems[n] = akBaseObject        ; save item
    n = n + 1                        ; increase counter
EndEvent


;; Event received when this actor equips something - akReference may be None if object is not persistent
;Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
;EndEvent


; -- FUNCTIONs -- 4

;------------------------------
FUNCTION myF_Init(Actor player)
;------------------------------
    myMagic = new Form[4]
    myItems = new Form[128]        ; take papyrus maximum, should be more than enough

    bSKSE = (SKSE.GetVersion() > 0)

    weapR = player.GetEquippedWeapon(False) as Form   ; right
    weapL = player.GetEquippedWeapon(TRUE)  as Form   ; left
ENDFUNCTION


;---------------------------------
FUCTION myF_GetMagic(Actor player)
;---------------------------------
;    [0] = player.GetEquippedSpell(0) as Form    ; 0 left hand
;    [1] = player.GetEquippedSpell(1) as Form    ; 1 right hand
;    [2] = player.GetEquippedSpell(2) as Form    ; 2 other
;;;    [3] = player.GetEquippedSpell(3) as Form  ; 3 instant
;    [4] = player.GetEquippedShout()  as Form    ; 4

    form fm

int i = 3            ; "instant" cannot be re-equipped
    WHILE (i)
        i = i - 1
        fm = player.GetEquippedSpell(i) as Form        ; [2] .. [0]
        IF ( fm )
            player.UnEquipSpell(fm as Spell, i)
            myMagic[i] = fm
        ENDIF
    ENDWHILE

    fm = player.GetEquippedShout() as Form
    IF ( fm )
        player.UnEquipShout(fm as Shout)
        myMagic[4] = fm
    ENDIF
ENDFUNCTION


;--------------------
FUCTION myF_ReEquip()
;--------------------
; https://www.creationkit.com/index.php?title=EquipItemEx_-_Actor
    actor player = Game.GetPlayer()

    form fm
    int i

;re-equip items from array
    i = n
    WHILE (i > 1)
        i = i - 1
        fm = myItems[i]            ; last unequipped item
        IF ( fm )
;            ------------
            IF ( bSKSE )
                IF (fm as Weapon)
                    IF     (fm == weapL as Form)
                        player.EquipItemEx(fm, 2, False, TRUE)       ; SKSE required!

                    ELSEIF (fm == weapR as Form)
                        player.EquipItemEx(fm, 1, False, TRUE)       ; SKSE required!
                    ENDIF
                ELSE                ; default slot for armor, torch, ammo
                        player.EquipItemEx(fm, 0, False, False)      ; SKSE required!
                ENDIF
            ELSE
                        player.EquipItem(fm)
            ENDIF
;            ------------
        ENDIF
    ENDWHILE

;re-equip spells, if any
    i = 4
    WHILE (i)
        i = i - 1
        fm = myMagic[i]
        IF ( fm )            ; player_spells
            player.EquipSpell(fm as Spell, i)
        ENDIF
    ENDWHILE

;re-equip shout
    fm = myMagic[4]
    IF ( fm )               ; player_shout
        player.EquipShout(fm as Shout)
    ENDIF
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

 

event OnCellAttach() will be fired here, if player and activator (which has this script attached) share the same parent cell, the detach event is fired as opposite

It is always a good idea to shrink the memory usage of actor and objectreference as much as possible, because of persistence.

 

 

Could you expand on how that shrinks memory? Since the activator does of course not move, it seems trivial that the player and the trigger are in the same cell?

 

 

 

To check Skyui mod loaded we can use the attach event too.

 

 

 

Again I probably come across as being obtuse. :smile: But I'd like to understand the whys as well as the whats.

 

 

 

I came across with another idea (for naked player), because you are using a spell for npcs, but not for the player.

 

 

 

When I first looked at doing these patches it was because I wondered why so many player home mods only had NPC undressing in, when the obvious thing would be to include the player. My reading lead me to numerous references to the game engine having a problem with using a spell on the player but not NPCs. My own testing showed the magic effect of 'unequipall' used by all NPC undressing mods, would undress the player, but whereas dispelling the spell would 'redress' an NPC the player stayed undressed.

 

Hence my doing things the 'long way around'. :smile:

I don't know if placing the functions of filling arrays with the players equipment in a spell would meet the same problem.

If not then perhaps the end result of all this discussion about my patches over a few threads here could result in a very small modders resource on the Nexus? A few generic scripts that others can take and use in their player home mods - or any mod that wants to undress people. :smile:

Link to comment
Share on other sites

  • Recently Browsing   0 members

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