Jump to content

Sit markers, end of animation question


Recommended Posts

Auto State WaitingPlayer
Event OnActivate(ObjectReference akActionRef)
     if akActionRef == Game.GetPlayer()
        GoToState("Busy")
        Utility.Wait(2.0)   ; 2 sec is required for the 'Sit' animation to play & finish
        Blessing.Cast(akActionRef, akActionRef)
        BlessingMessage.Show()
        GoToState("StandingUp")
  EndIf
EndEvent
EndState

Hi, in your code you out the GoToState("Busy") in the if statement before stuff happens. But when I do that 'stuff' doesn't happen:

Event OnActivate(ObjectReference akActionRef)

  If akActionRef == PlayerRef              ;checks to see if the trigger is the player

   GoToState("Busy")

   dz_undress_player_F()              ;if so call the function to undress the player

  ElseIf akActionRef as Actor              ;is the trigger an actor (NPC)?

   GoToState("Busy")

   dz_undress_NPC_F(akActionRef as Actor)          ;then call the function to undress the NPC

  EndIf
  ;debug.notification("state = sitting_mcm_installed")

  sitActor = akActionRef as Actor

  RegisterForSingleUpdateGameTime(0.0)

  GoToState("sitting_mcm_installed")

EndEvent

doesn't work. neither does:

Event OnActivate(ObjectReference akActionRef)

  GoToState("Busy")

  If akActionRef == PlayerRef              ;checks to see if the trigger is the player

   dz_undress_player_F()              ;if so call the function to undress the player

  ElseIf akActionRef as Actor              ;is the trigger an actor (NPC)?

   dz_undress_NPC_F(akActionRef as Actor)          ;then call the function to undress the NPC

  EndIf
  ;debug.notification("state = sitting_mcm_installed")

  sitActor = akActionRef as Actor

  RegisterForSingleUpdateGameTime(0.0)

  GoToState("sitting_mcm_installed")

EndEvent

but in:

Event OnActivate(ObjectReference akActionRef)

  If akActionRef == PlayerRef              ;checks to see if the trigger is the player

   dz_undress_player_F()              ;if so call the function to undress the player

  ElseIf akActionRef as Actor              ;is the trigger an actor (NPC)?

   dz_undress_NPC_F(akActionRef as Actor)          ;then call the function to undress the NPC

  EndIf
  ;debug.notification("state = sitting_mcm_installed")

  sitActor = akActionRef as Actor

  RegisterForSingleUpdateGameTime(0.0)

  GoToState("sitting_mcm_installed")

EndEvent

the functions dz_undress_player_F or dz_undress_NPC_F do fire

I do have the 'busy' state defined as you have.

What am I missing about why after 'going to another state' stuff in the previous one still happens?

 

diziet

Link to comment
Share on other sites

- Where is the script attached?

- What is handeling the script?

- Is this a part of the big script you posted?, i didn't read it (no much free time lately), but that script doesn't have 'States' defined so that you can actually use the "Change Of States" to your advantage.


Without 'States' defined in sequences, you will never be able to return or/and jump to the desirable for usage 'State'.

'States' is the fastest, most reliable and most powerful tool that this game engine and papyrus has, but in order to use them especially on big complex scripts requires a careful pre-design of how those 'States' will communicate with each other and what 'State' will handle what.


"Hi, in your code you out the GoToState("Busy") in the if statement before stuff happens. But when I do that 'stuff' doesn't happen:"

Once an 'Activation' event has been received by the script it will start to process from top to bottom, the 'Change of State' here is use as a "Fail Safe" to send any other possible activation that could be send to this object before the script has finish processing the functions from the first activation, to an "Empty State".

Once the functions from the first activation has finished the 'State' will be set to a valid for activation 'State'.


* The 'Change of State' inside an Event when its function are been processed can have multiple applications, except from the usual 'Fail Safe for Re-Activation'.


Have a happy modding.

Edited by maxarturo
Link to comment
Share on other sites

My point is that in your posted example:

 

 

Auto State WaitingPlayer

Event OnActivate(ObjectReference akActionRef)

     if akActionRef == Game.GetPlayer()

        GoToState("Busy")

        Utility.Wait(2.0)   ; 2 sec is required for the 'Sit' animation to play & finish

        Blessing.Cast(akActionRef, akActionRef)

        BlessingMessage.Show()

        GoToState("StandingUp")

  EndIf

EndEvent

EndState





State StandingUp

Event OnActivate(ObjectReference akActionRef)

       GoToState("Busy") ; We block any other activation event and we keep the 2 we're interested, the third activation event is send to an 'Empty State' / Busy State

    if akActionRef == Game.GetPlayer()

       Utility.Wait(1.5)   ; 1,5 sec is required for the 'Get Up' animation to play & finish
       ; Do here whatever you need to do
EndIf

       GoToState("WaitingPlayer")

EndEvent

EndState





State Busy

Event OnActivate(ObjectReference akActionRef)

;Do nothing.

EndEvent

EndState

 

 

 

The GoToState("Busy") statement is followed by 'stuff', within the same event. The code for doing things still gets executed even though the state has changed.

When I tried that my 'stuff' didn't happen. I had the busy state exactly as you have it.

 

My whole script:

 

 

ScriptName dz_undress_sitting_script Extends ObjectReference
 
dz_undress_MCM_menu_script Property mcm  Auto         ;the quest script that holds the MCM menu
Actor  Property PlayerRef    Auto         ;this allows us to use the fast PlayerRef reference

Spell  Property dz_undress_spell  Auto            ;this is the spell that will undress NPCs

MagicEffect Property dz_undress_magic_effect  Auto        ;this is the magic effect from the spell
Form[]  Items                   ;this will store all equipped items except spells

Spell[] Spell_1                   ;to store equipped spells

Armor[] Slots
Weapon Lefthand                   ;we need to store the weapons in each hand separately

Weapon Righthand
Bool disrobed                            ;to track player undressed status
Actor sitActor

;;;define variable for camera state;;;

int iCameraState
Event OnLoad()

;debug.messagebox("loading script")

If !(SKSE.GetVersion() > 0)

  debug.notification("SKSE64 was not found, please install SKSE64 for Diziet's Undressing mod")

  Return

EndIf

If !(Game.GetFormFromFile(0x00000814, "SkyUI_SE.esp"))        ;check if SkyUI is installed

  GoToState("no_mcm")                ;if not use the no-mcm state

Else

  GoToState("mcm_installed")              ;otherwise use the mcm installed state

EndIf

EndEvent
 
State no_mcm

Event OnActivate(ObjectReference akActionRef)

  GoToState("sitting_no_mcm")

  If akActionRef == PlayerRef && !PlayerRef.isincombat()       ;checks to see if the trigger is the player and also not in combat

   dz_undress_player_F()              ;if so call the function to undress the player

  ElseIf (!(akActionRef as Actor).isincombat())         ;is the trigger an actor (NPC)?

   dz_undress_NPC_F(akActionRef as Actor)          ;then undress the NPC

  EndIf
  sitActor = akActionRef as Actor

  RegisterForSingleUpdateGameTime(0.0)

 

EndEvent
Function dz_undress_player_F()              ;define the function to undress the player

If ( disrobed )

  Return                      ;if the player is already undressed exit the function

EndIf

disrobed = True                           ;set the player is undressed variable
  iCameraState = Game.GetCameraState()           ;skse function

  If ( iCameraState == 0)

  ; change to third person

    Game.ForceThirdPerson()                      ;3rd Person

  Else

  EndIf
Lefthand = PlayerRef.GetEquippedWeapon(True)          ;store the left hand weapon - if any

Righthand = PlayerRef.GetEquippedWeapon(False)          ;store the righthand weapon - if any

Items = PO3_SKSEFunctions.AddAllEquippedItemsToArray(PlayerRef)      ;store all equipped items in an array using https://www.nexusmods.com/skyrimspecialedition/mods/22854
int i                    ;define this variable for use in arrays

Spell_1 = New Spell[4]                ;create the spells array

i = spell_1.Length                 ;size of spells array (should be 4)

While (i)

  i = i - 1

  spell_1[i] = PlayerRef.GetEquippedSpell(i)          ;fill the spells array

EndWhile
PlayerRef.UnEquipAll()                ;all stored, strip the player

EndFunction
Function dz_undress_NPC_F(Actor NPCRef)

  If (NPCRef as Actor).HasMagicEffect(dz_undress_magic_effect)

   Return                  ;then we are done, exit the function

  EndIf

  dz_undress_spell.Cast(NPCRef, NPCRef)              ;cast the undress spell on the NPC

EndFunction
EndState
State sitting_no_mcm

Event OnActivate(ObjectReference akActionRef)

EndEvent
Event OnUpdateGameTime()

  Utility.Wait(0.25)                               ;adjust the wait time, if required

  While (True)

   Utility.Wait(0.1)

   Int i = sitActor.GetSitState()                  ;https://www.creationkit.com/index.php?title=GetSitState_-_Actor

   If (i == 4)
    If sitActor == PlayerRef            ;checks to see if the actor is the player

     dz_redress_player_F()            ;if so call the function to re-dress the player

    ElseIf sitActor as Actor            ;is the actor an NPC?

     dz_redress_NPC_F(sitActor as Actor)         ;then re-dress the NPC

    EndIf

    sitActor = None

    GoToState("no_mcm")

    ;debug.messagebox("it has finished")

    Return                    ; - STOP -    is still sitting, wants to stand up

   EndIf

  EndWhile

EndEvent
Function dz_redress_player_F()              ;define the function to re-dress the player

If ( disrobed == True )                ;is the player undressed

Else

  Return                      ;the player is not undressed, exit the function

EndIf
;;return to first person if necessary

  If ( iCameraState == 0 )              ; skse function

   ; change to first person as player was initially

   Game.ForceFirstPerson()                       ; 1st Person

  EndIf
;;https://www.creationkit.com/index.php?title=EquipItemEx_-_Actor

int i                    ;define this variable for use in arrays

i = 0

While i < items.Length                ;loop through the stored items

  If Items[i] As Armor || Items[i] As Ammo ||  Items[i] As Light     ;if stored items are armour or ammo or torch

   PlayerRef.EquipItemEx(Items[i],0,False,True)        ;re-equip them

  EndIf

  i = i +1

EndWhile
PlayerRef.EquipItemEx(Righthand,1,False,True)          ;re-equip the righthand

PlayerRef.EquipItemEx(Lefthand,2,False,True)          ;re-equip the lefthand
i = spell_1.Length

While (i)                   ;loop through the stored spells

  i = i - 1

  spell sp = spell_1[i]               ;if that spell position exists

  If ( sp )

   PlayerRef.EquipSpell(sp,i)             ;fill it

  EndIf

EndWhile
Disrobed = False                 ;store the dressed state of the player

EndFunction
Function dz_redress_NPC_F(Actor NPCRef)

  If (NPCRef as Actor).HasMagicEffect(dz_undress_magic_effect)

   NPCRef.DispelSpell(dz_undress_spell)          ;dispell the undress spell on the NPC

  EndIf

  Utility.Wait(0.5)

  If (!Game.GetFormFromFile(0x00000804, "dz_auto_outfits.esp"))     ;is diziet's auto outfits installed?

   Return

  Else

   (Game.GetFormFromFile(0x00000804, "dz_auto_outfits.esp") As Spell).Cast(NPCRef,NPCRef)

  EndIf

EndFunction
EndState
State Busy

Event OnActivate(ObjectReference akActionRef)

;Do nothing.

EndEvent

EndState
State mcm_installed

;/ Event OnBeginState()

  debug.notification("mcm_installed state!")

EndEvent /;
Event OnActivate(ObjectReference akActionRef)

  If akActionRef == PlayerRef              ;checks to see if the trigger is the player

   dz_undress_player_F()              ;if so call the function to undress the player

  ElseIf akActionRef as Actor              ;is the trigger an actor (NPC)?

   dz_undress_NPC_F(akActionRef as Actor)          ;then call the function to undress the NPC

  EndIf
  ;debug.notification("state = sitting_mcm_installed")

  sitActor = akActionRef as Actor

  RegisterForSingleUpdateGameTime(0.0)

  GoToState("sitting_mcm_installed")

EndEvent
Function dz_undress_player_F()              ;define the function to undress the player

  iCameraState = Game.GetCameraState()           ;store whether first/third person

  If iCameraState == 0 && mcm.third_person == True

   Game.ForceThirdPerson()

  EndIf
  If mcm.disrobes == false || Disrobed == True         ;if the MCM menu has player undressing toggled off, or the player is already undressed

   Return                  ;then exit the function

  EndIf
  If mcm.ignoreCombat == True || !PlayerRef.IsInCombat()       ;MCM menu 'Ignore Combat is toggled on or the player is not in combat

  Else                   ;otherwise

   Return                  ;then exit the function

  EndIf
  Lefthand = PlayerRef.GetEquippedWeapon(True)         ;store the left hand weapon - if any

  Righthand = PlayerRef.GetEquippedWeapon(False)         ;store the righthand weapon - if any

  Items = PO3_SKSEFunctions.AddAllEquippedItemsToArray(PlayerRef)     ;store all equipped items in an array using https://www.nexusmods.com/skyrimspecialedition/mods/22854
  int i                   ;define this variable for use in arrays

  Spell_1 = new Spell[4]               ;create the spells array

  i = spell_1.Length                ;size of spells array (should be 4)

  While (i)

   i = i - 1

   spell_1[i] = PlayerRef.GetEquippedSpell(i)         ;fill the spells array

  EndWhile
  Slots = New Armor[32]

  If mcm.player_hair_slots == True || mcm.npc_hair_slots == True || mcm.all_slots == True

   Slots = dz_get_all_player_slots()

  EndIf
  If mcm.slow_unequip == True

   ;debug.messagebox("slower unequipping")

   dz_slow_unequip(PlayerRef)

   Else

   PlayerRef.UnEquipAll()              ;all stored, strip the player

  EndIf
  If mcm.player_hair_slots == True

   If mcm.ignorehair == True             ;re-equip problematic slots if enabled

   PlayerRef.equipitemex(slots[1],0,False,True)

   EndIf

   If mcm.ignorelonghair == True

   PlayerRef.equipitemex(slots[11],0,False,True)

   EndIf

   If mcm.ignorecirclet == True

   PlayerRef.equipitemex(slots[12],0,False,True)

   EndIf

  ElseIf mcm.all_slots == True

   dz_fill_player_slots()

  EndIf
  Disrobed = True                 ;store the undressed state of the player

EndFunction
Function dz_undress_NPC_F(Actor NPCRef)

  If (mcm.ignorenpcCombat) || !(NPCRef as Actor).IsInCombat()      ;actor "should ignore combat" or "is not in combat"

   dz_undress_spell.Cast(NPCRef, NPCRef)             ;cast the undress spell on the NPC

  EndIf

EndFunction
Function dz_slow_unequip(Actor aRef)

  Form[] check_items = PO3_SKSEFunctions.AddAllEquippedItemsToArray(aRef)      ;store all equipped items in an array

  Int arr_length = check_items.Length

  Int i = 0

  String[] kwords = mcm.keywords_list

  Bool keep

  While i < arr_length

   Int j = 0

   keep = False

   While j < kwords.Length

   Keyword testKW = Keyword.GetKeyword(kwords[j])

    ;debug.messagebox("testKW is "+testKW)

    If check_items[i].HasKeyword(testKW) == True

    keep = True

    EndIf

   j += 1

   EndWhile

   If keep == False

   aRef.UnEquipitemEx(check_items[i])

   EndIf

  i += 1

  EndWhile

EndFunction
Armor[] Function dz_get_all_player_slots()

  Armor[] temp

  temp = New Armor[32]

  Int i

  i = 0

  While i < temp.Length

   temp[i] = PlayerRef.GetEquippedArmorInSlot(i + 30)

   i = i + 1

  EndWhile

  Return temp

EndFunction
Function dz_fill_player_slots()

  Int i

  i = 0

  While i < mcm.ignoremoreslots.Length

   If mcm.ignoremoreslots[i] == True

   PlayerRef.equipitemex(slots[i],0,False,True)

   EndIf

   i = i + 1

  EndWhile

EndFunction
EndState
State sitting_mcm_installed

Event OnBeginState()

  ;debug.messagebox("sitting state!")

EndEvent
Event OnActivate(ObjectReference akActionRef)

EndEvent
Event OnUpdateGameTime()

  Utility.Wait(0.25)                              ;adjust the wait time, if required

  ;debug.messagebox("OnUpdateGameTime fired")

  While (True)

   Utility.Wait(0.1)

   Int i = sitActor.GetSitState()                  ;https://www.creationkit.com/index.php?title=GetSitState_-_Actor

   If (i == 4)

    If sitActor == PlayerRef            ;checks to see if the actor is the player

     dz_redress_player_F()            ;if so call the function to re-dress the player
    ElseIf sitActor as Actor            ;is the trigger an NPC?

     dz_redress_NPC_F(sitActor as Actor)         ;then re-dress the NPC

    EndIf

    sitActor = None

    GoToState("mcm_installed")

    ;debug.notification("state = mcm_installed")

    ;debug.messagebox("it has finished")

    Return                    ; - STOP -    is still sitting, wants to stand up

   EndIf

  EndWhile

EndEvent
Function dz_redress_player_F()              ;define the function to re-dress the player

  If mcm.third_person == true && iCameraState == 0        ;if the MCM menu to force third person on entry is toggled on and the player was originally in first person

   Game.ForceFirstPerson()              ;then force back to first person

  EndIf
  If Disrobed == False               ;the player is not undressed

   Return                  ;exit the function as re-dressing not needed

  EndIf
  PlayerRef.EquipItemEx(Righthand,1,False,True)         ;re-equip the righthand

  PlayerRef.EquipItemEx(Lefthand,2,False,True)         ;re-equip the lefthand
  int i                   ;define this variable for use in arrays
  i = 0

  While i < items.length               ;loop through the stored items

   If Items[i] As Armor || Items[i] As Ammo ||  Items[i] As Light    ;if stored items are armour or ammo or torch

    PlayerRef.EquipItemEx(Items[i],0,False,True)       ;re-equip them

   EndIf

   i = i +1

  EndWhile
  i = spell_1.Length

  While (i)                  ;loop through the stored spells

   i = i - 1

   spell sp = spell_1[i]              ;if that spell position exists

   If ( sp )

    PlayerRef.EquipSpell(sp,i)            ;fill it

   EndIf

  EndWhile
  Disrobed = False                ;store the dressed state of the player

EndFunction
Function dz_redress_NPC_F(Actor NPCRef)

  If (NPCRef as Actor).HasMagicEffect(dz_undress_magic_effect)     ;does the NPC have the spell on them?

   NPCRef.DispelSpell(dz_undress_spell)          ;dispell the undress spell on the NPC

  EndIf

  Utility.Wait(0.5)

  If (!Game.GetFormFromFile(0x00000804, "dz_auto_outfits.esp"))     ;is diziet's auto outfits installed?

   Return

  Else

   (Game.GetFormFromFile(0x00000804, "dz_auto_outfits.esp") As Spell).Cast(NPCRef,NPCRef)

  EndIf

EndFunction
EndState
;;;dummy functions to keep the compiler happy;;;

Function dz_undress_player_F()

EndFunction
Function dz_redress_player_F()

EndFunction
Function dz_undress_NPC_F(Actor NPCRef)

EndFunction
Function dz_redress_NPC_F(Actor NPCRef)

EndFunction
Armor[] Function dz_get_all_player_slots()

EndFunction
Function dz_fill_player_slots()

EndFunction
Function dz_slow_unequip(Actor aRef)

EndFunction

 

 

 

I wanted to use your example to avoid extraneous activations from sitting down and getting up.

 

 

diziet

Link to comment
Share on other sites

"I had the busy state exactly as you have it"

First of all, you haven't! you are missing the most important part of the script's logic, the declaration of 'states' in all the 'events'.


AUTO STATE MyFirstState

Event SomeEvent.... "Or groups of Events"

GoToState("Busy")


; Do Something


GoToState("MySecondState")

EndEvent

ENDSTATE


STATE MySecondState

Event SomeEvent.... "Or groups of Events"

GoToState("Busy")


; Do Something


GoToState("MyFirstState")

EndEvent

ENDSTATE


State Busy

Event SomeEvent.... "Or groups of Events"

; Do nothing.

EndEvent

ENDSTATE


* The script i posted is to be attached to the furniture.



It's pretty clear that you don't understand how "States" work.


Unfortunately lately i haven't had too much free time, plus the last couple o weeks have been very hard on me and i'm not on the mood to get involved with anything except from my couch, pillow and girlfriend.

My apologies my friend !!.


I think it's better for you to change direction and use dylbill suggestions and work with:

Event OnSit(ObjectReference akFurniture)

Event OnGetUp(ObjectReference akFurniture)

bool Function IsFurnitureInUse(bool abIgnoreReserved = false) native


* Except of course if someone gets into the trouble to explain you how 'States' should work on your script.


I once again apologize for my lack of cooperation.

Edited by maxarturo
Link to comment
Share on other sites

@maxarturo It's absolutely fine how you choose to reply or not of course:) I hope I haven't given any impression of entitlement and I don't wish to hereafter.

But your comment "you are missing the most important part of the script's logic, the declaration of 'states' in all the 'events'." leaves me confused, maybe someone else can help.

 

I though that:

 

 

State no_mcm

Event OnActivate(ObjectReference akActionRef)

  GoToState("sitting_no_mcm")

  If akActionRef == PlayerRef && !PlayerRef.isincombat()       ;checks to see if the trigger is the player and also not in combat

   dz_undress_player_F()              ;if so call the function to undress the player

  ElseIf (!(akActionRef as Actor).isincombat())         ;is the trigger an actor (NPC)?

   dz_undress_NPC_F(akActionRef as Actor)          ;then undress the NPC

  EndIf
  sitActor = akActionRef as Actor

  RegisterForSingleUpdateGameTime(0.0)

 

EndEvent
Function dz_undress_player_F()              ;define the function to undress the player

If ( disrobed )

  Return                      ;if the player is already undressed exit the function

EndIf

disrobed = True                           ;set the player is undressed variable
  iCameraState = Game.GetCameraState()           ;skse function

  If ( iCameraState == 0)

  ; change to third person

    Game.ForceThirdPerson()                      ;3rd Person

  Else

  EndIf
Lefthand = PlayerRef.GetEquippedWeapon(True)          ;store the left hand weapon - if any

Righthand = PlayerRef.GetEquippedWeapon(False)          ;store the righthand weapon - if any

Items = PO3_SKSEFunctions.AddAllEquippedItemsToArray(PlayerRef)      ;store all equipped items in an array using https://www.nexusmods.com/skyrimspecialedition/mods/22854
int i                    ;define this variable for use in arrays

Spell_1 = New Spell[4]                ;create the spells array

i = spell_1.Length                 ;size of spells array (should be 4)

While (i)

  i = i - 1

  spell_1[i] = PlayerRef.GetEquippedSpell(i)          ;fill the spells array

EndWhile
PlayerRef.UnEquipAll()                ;all stored, strip the player

EndFunction
Function dz_undress_NPC_F(Actor NPCRef)

  If (NPCRef as Actor).HasMagicEffect(dz_undress_magic_effect)

   Return                  ;then we are done, exit the function

  EndIf

  dz_undress_spell.Cast(NPCRef, NPCRef)              ;cast the undress spell on the NPC

EndFunction
EndState

 

 

and

 

 

State sitting_no_mcm
Event OnActivate(ObjectReference akActionRef)
EndEventEvent OnUpdateGameTime()
  Utility.Wait(0.25)                               ;adjust the wait time, if required
  While (True)
   Utility.Wait(0.1)
   Int i = sitActor.GetSitState()                  ;https://www.creationkit.com/index.php?title=GetSitState_-_Actor
   If (i == 4)    If sitActor == PlayerRef            ;checks to see if the actor is the player
     dz_redress_player_F()            ;if so call the function to re-dress the player
    ElseIf sitActor as Actor            ;is the actor an NPC?
     dz_redress_NPC_F(sitActor as Actor)         ;then re-dress the NPC
    EndIf
    sitActor = None
    GoToState("no_mcm")
    ;debug.messagebox("it has finished")
    Return                    ; - STOP -    is still sitting, wants to stand up
   EndIf
  EndWhile
EndEventFunction dz_redress_player_F()              ;define the function to re-dress the player
If ( disrobed == True )                ;is the player undressed
Else
  Return                      ;the player is not undressed, exit the function
EndIf;;return to first person if necessary
  If ( iCameraState == 0 )              ; skse function
   ; change to first person as player was initially
   Game.ForceFirstPerson()                       ; 1st Person
  EndIf;;https://www.creationkit.com/index.php?title=EquipItemEx_-_Actor
int i                    ;define this variable for use in arrays
i = 0
While i < items.Length                ;loop through the stored items
  If Items[i] As Armor || Items[i] As Ammo ||  Items[i] As Light     ;if stored items are armour or ammo or torch
   PlayerRef.EquipItemEx(Items[i],0,False,True)        ;re-equip them
  EndIf
  i = i +1
EndWhilePlayerRef.EquipItemEx(Righthand,1,False,True)          ;re-equip the righthand
PlayerRef.EquipItemEx(Lefthand,2,False,True)          ;re-equip the lefthandi = spell_1.Length
While (i)                   ;loop through the stored spells
  i = i - 1
  spell sp = spell_1[i]               ;if that spell position exists
  If ( sp )
   PlayerRef.EquipSpell(sp,i)             ;fill it
  EndIf
EndWhileDisrobed = False                 ;store the dressed state of the player
EndFunctionFunction dz_redress_NPC_F(Actor NPCRef)
  If (NPCRef as Actor).HasMagicEffect(dz_undress_magic_effect)
   NPCRef.DispelSpell(dz_undress_spell)          ;dispell the undress spell on the NPC
  EndIf
  Utility.Wait(0.5)
  If (!Game.GetFormFromFile(0x00000804, "dz_auto_outfits.esp"))     ;is diziet's auto outfits installed?
   Return
  Else
   (Game.GetFormFromFile(0x00000804, "dz_auto_outfits.esp") As Spell).Cast(NPCRef,NPCRef)
  EndIf
EndFunctionEndState

 

 

 

and

 

 

State Busy
Event OnActivate(ObjectReference akActionRef)
;Do nothing.
EndEvent
EndStateState mcm_installed
;/ Event OnBeginState()
  debug.notification("mcm_installed state!")
EndEvent /;Event OnActivate(ObjectReference akActionRef)
  If akActionRef == PlayerRef              ;checks to see if the trigger is the player
   dz_undress_player_F()              ;if so call the function to undress the player
  ElseIf akActionRef as Actor              ;is the trigger an actor (NPC)?
   dz_undress_NPC_F(akActionRef as Actor)          ;then call the function to undress the NPC
  EndIf  ;debug.notification("state = sitting_mcm_installed")
  sitActor = akActionRef as Actor
  RegisterForSingleUpdateGameTime(0.0)
  GoToState("sitting_mcm_installed")
EndEventFunction dz_undress_player_F()              ;define the function to undress the player
  iCameraState = Game.GetCameraState()           ;store whether first/third person
  If iCameraState == 0 && mcm.third_person == True
   Game.ForceThirdPerson()
  EndIf  If mcm.disrobes == false || Disrobed == True         ;if the MCM menu has player undressing toggled off, or the player is already undressed
   Return                  ;then exit the function
  EndIf  If mcm.ignoreCombat == True || !PlayerRef.IsInCombat()       ;MCM menu 'Ignore Combat is toggled on or the player is not in combat
  Else                   ;otherwise
   Return                  ;then exit the function
  EndIf  Lefthand = PlayerRef.GetEquippedWeapon(True)         ;store the left hand weapon - if any
  Righthand = PlayerRef.GetEquippedWeapon(False)         ;store the righthand weapon - if any
  Items = PO3_SKSEFunctions.AddAllEquippedItemsToArray(PlayerRef)     ;store all equipped items in an array using https://www.nexusmods.com/skyrimspecialedition/mods/22854  int i                   ;define this variable for use in arrays
  Spell_1 = new Spell[4]               ;create the spells array
  i = spell_1.Length                ;size of spells array (should be 4)
  While (i)
   i = i - 1
   spell_1[i] = PlayerRef.GetEquippedSpell(i)         ;fill the spells array
  EndWhile  Slots = New Armor[32]
  If mcm.player_hair_slots == True || mcm.npc_hair_slots == True || mcm.all_slots == True
   Slots = dz_get_all_player_slots()
  EndIf  If mcm.slow_unequip == True
   ;debug.messagebox("slower unequipping")
   dz_slow_unequip(PlayerRef)
   Else
   PlayerRef.UnEquipAll()              ;all stored, strip the player
  EndIf  If mcm.player_hair_slots == True
   If mcm.ignorehair == True             ;re-equip problematic slots if enabled
   PlayerRef.equipitemex(slots[1],0,False,True)
   EndIf
   If mcm.ignorelonghair == True
   PlayerRef.equipitemex(slots[11],0,False,True)
   EndIf
   If mcm.ignorecirclet == True
   PlayerRef.equipitemex(slots[12],0,False,True)
   EndIf
  ElseIf mcm.all_slots == True
   dz_fill_player_slots()
  EndIf  Disrobed = True                 ;store the undressed state of the player
EndFunctionFunction dz_undress_NPC_F(Actor NPCRef)
  If (mcm.ignorenpcCombat) || !(NPCRef as Actor).IsInCombat()      ;actor "should ignore combat" or "is not in combat"
   dz_undress_spell.Cast(NPCRef, NPCRef)             ;cast the undress spell on the NPC
  EndIf
EndFunctionFunction dz_slow_unequip(Actor aRef)
  Form[] check_items = PO3_SKSEFunctions.AddAllEquippedItemsToArray(aRef)      ;store all equipped items in an array
  Int arr_length = check_items.Length
  Int i = 0
  String[] kwords = mcm.keywords_list
  Bool keep
  While i < arr_length
   Int j = 0
   keep = False
   While j < kwords.Length
   Keyword testKW = Keyword.GetKeyword(kwords[j])
    ;debug.messagebox("testKW is "+testKW)
    If check_items[i].HasKeyword(testKW) == True
    keep = True
    EndIf
   j += 1
   EndWhile
   If keep == False
   aRef.UnEquipitemEx(check_items[i])
   EndIf
  i += 1
  EndWhile
EndFunctionArmor[] Function dz_get_all_player_slots()
  Armor[] temp
  temp = New Armor[32]
  Int i
  i = 0
  While i < temp.Length
   temp[i] = PlayerRef.GetEquippedArmorInSlot(i + 30)
   i = i + 1
  EndWhile
  Return temp
EndFunctionFunction dz_fill_player_slots()
  Int i
  i = 0
  While i < mcm.ignoremoreslots.Length
   If mcm.ignoremoreslots[i] == True
   PlayerRef.equipitemex(slots[i],0,False,True)
   EndIf
   i = i + 1
  EndWhile
EndFunctionEndState

 

 

 

and

 

 

State sitting_mcm_installed
Event OnBeginState()
  ;debug.messagebox("sitting state!")
EndEventEvent OnActivate(ObjectReference akActionRef)
EndEventEvent OnUpdateGameTime()
  Utility.Wait(0.25)                              ;adjust the wait time, if required
  ;debug.messagebox("OnUpdateGameTime fired")
  While (True)
   Utility.Wait(0.1)
   Int i = sitActor.GetSitState()                  ;https://www.creationkit.com/index.php?title=GetSitState_-_Actor
   If (i == 4)
    If sitActor == PlayerRef            ;checks to see if the actor is the player
     dz_redress_player_F()            ;if so call the function to re-dress the player    ElseIf sitActor as Actor            ;is the trigger an NPC?
     dz_redress_NPC_F(sitActor as Actor)         ;then re-dress the NPC
    EndIf
    sitActor = None
    GoToState("mcm_installed")
    ;debug.notification("state = mcm_installed")
    ;debug.messagebox("it has finished")
    Return                    ; - STOP -    is still sitting, wants to stand up
   EndIf
  EndWhile
EndEventFunction dz_redress_player_F()              ;define the function to re-dress the player
  If mcm.third_person == true && iCameraState == 0        ;if the MCM menu to force third person on entry is toggled on and the player was originally in first person
   Game.ForceFirstPerson()              ;then force back to first person
  EndIf  If Disrobed == False               ;the player is not undressed
   Return                  ;exit the function as re-dressing not needed
  EndIf  PlayerRef.EquipItemEx(Righthand,1,False,True)         ;re-equip the righthand
  PlayerRef.EquipItemEx(Lefthand,2,False,True)         ;re-equip the lefthand  int i                   ;define this variable for use in arrays  i = 0
  While i < items.length               ;loop through the stored items
   If Items[i] As Armor || Items[i] As Ammo ||  Items[i] As Light    ;if stored items are armour or ammo or torch
    PlayerRef.EquipItemEx(Items[i],0,False,True)       ;re-equip them
   EndIf
   i = i +1
  EndWhile  i = spell_1.Length
  While (i)                  ;loop through the stored spells
   i = i - 1
   spell sp = spell_1[i]              ;if that spell position exists
   If ( sp )
    PlayerRef.EquipSpell(sp,i)            ;fill it
   EndIf
  EndWhile  Disrobed = False                ;store the dressed state of the player
EndFunctionFunction dz_redress_NPC_F(Actor NPCRef)
  If (NPCRef as Actor).HasMagicEffect(dz_undress_magic_effect)     ;does the NPC have the spell on them?
   NPCRef.DispelSpell(dz_undress_spell)          ;dispell the undress spell on the NPC
  EndIf
  Utility.Wait(0.5)
  If (!Game.GetFormFromFile(0x00000804, "dz_auto_outfits.esp"))     ;is diziet's auto outfits installed?
   Return
  Else
   (Game.GetFormFromFile(0x00000804, "dz_auto_outfits.esp") As Spell).Cast(NPCRef,NPCRef)
  EndIf
EndFunctionEndState

 

 

had all the events in states?

Now the full posted script is the one that works which is kind of why I though that:)

The problem is that putting GoToState("Busy") such as:

 

 

State Busy
Event OnActivate(ObjectReference akActionRef)
;Do nothing.
EndEvent
EndState State mcm_installedEvent OnActivate(ObjectReference akActionRef)GoToState("Busy")
  If akActionRef == PlayerRef              ;checks to see if the trigger is the player
   dz_undress_player_F()              ;if so call the function to undress the player
  ElseIf akActionRef as Actor              ;is the trigger an actor (NPC)?
   dz_undress_NPC_F(akActionRef as Actor)          ;then call the function to undress the NPC
  EndIf 
  sitActor = akActionRef as Actor
  RegisterForSingleUpdateGameTime(0.0)
  GoToState("sitting_mcm_installed")
EndEventFunction dz_undress_player_F().....rest of function stuff........EndState

 

 

 

does not fire the functions dz_undress_player_F or dz_undress_NPC_F,

neither does:

 

 

State Busy
Event OnActivate(ObjectReference akActionRef)
;Do nothing.
EndEvent
EndState State mcm_installedEvent OnActivate(ObjectReference akActionRef)
  If akActionRef == PlayerRef              ;checks to see if the trigger is the playerGoToState("Busy")
   dz_undress_player_F()              ;if so call the function to undress the player
  ElseIf akActionRef as Actor              ;is the trigger an actor (NPC)?GoToState("Busy")
   dz_undress_NPC_F(akActionRef as Actor)          ;then call the function to undress the NPC
  EndIf 
  sitActor = akActionRef as Actor
  RegisterForSingleUpdateGameTime(0.0)
  GoToState("sitting_mcm_installed")
EndEventFunction dz_undress_player_F()

 

 

 

 

whereas in your example, the GoToState("Busy") line occurs immediately after the first if statement "if akActionRef == Game.GetPlayer()"

and is followed by 'stuff' which presumably is still expected to happen, even though the state has now been 'GoneTo' :smile:

 

My script without the "Busy" State works fine using states, I just wanted to add the GoToBusy("State") stuff to ward off the extra activations that were mentioned. They don't seem to be a problem in my working script, but I wanted to be be sure:)

 

diziet

 

edit: the copy paste seems to mangle some lines, concatenating them together, the last lines in each snippet for example.

Link to comment
Share on other sites

Not a problem my friend, i'm just too tired lately...

 

I did not read carefully all your scripts, i just modify the first script to show you how 'States' should work for using them on a "Chair" furniture, i also added some descriptions so you can see what does what.


AUTO STATE no_mcm       ; We are waiting for an actor to SIT/Activate this furniture
Event OnActivate(ObjectReference akActionRef)
        GoToState("sitting_no_mcm")      ; We go to a STATE that activating does nothing
 
       If ( akActionRef == PlayerRef ) && ( PlayerRef.isincombat() == False )      ; FASTER FUNCTION
            Utility.Wait(2.0)                ; We wait for the SITING Animation to finish before calling FUNCTION
            dz_undress_player_F()
  ElseIf ((akActionRef as Actor).isincombat() == Flase )     ; FASTER FUNCTION
            Utility.Wait(2.0)                ; We wait for the SITING Animation to finish before calling FUNCTION
            dz_undress_NPC_F(akActionRef as Actor)
   EndIf
              ; sitActor = akActionRef as Actor        ; I don't why this is here ???
              ; RegisterForSingleUpdateGameTime(0.0)   ; You Don't have an UPDATE EVENT
 
        GoToState("no_mcm_StandingUp")     : After finishing the FUNCTIONS we go to a STATE for standing up and prevanting the 3 activation that the furniture will send
EndEvent
ENDSTATE
 
 
STATE sitting_no_mcm   ; FAIL SAFE STATE to prevent further activation
Event OnActivate(ObjectReference akActionRef)
     ; DO NOTHING - We have Just activated the chair/throne/sitting down furniture and NO FURTHER ACTIVATIONS ARE POSSIBLE
EndEvent
ENDSTATE
 
 
STATE no_mcm_StandingUp    ; The actor is already sitting on this furniture and this activation will play the STANDING UP Animation
Event OnActivate(ObjectReference akActionRef)
      GoToState("sitting_no_mcm") ; We go to a STATE that activating does nothing - We block the THIRD ACTIVATION
      Utility.Wait(1.5)           : We wait for the STANDING UP Animation to finish
      GoToState("no_mcm")         ; Now we go to a STATE that activation is possible for SITTING DOWN
EndEvent
ENDSTATE
 
 
    ;;;;;;; FUNCTIONS don't need to be inside an EVENT or STATE - They are "GO-SUB" that are process by the initial Executed Event - Which called it
Function dz_undress_player_F()              ;define the function to undress the player
 
If ( disrobed )
 
  Return                      ;if the player is already undressed exit the function
 
EndIf
 
disrobed = True                           ;set the player is undressed variable
  iCameraState = Game.GetCameraState()           ;skse function
 
  If ( iCameraState == 0)
 
  ; change to third person
 
    Game.ForceThirdPerson()                      ;3rd Person
 
  Else
 
  EndIf
Lefthand = PlayerRef.GetEquippedWeapon(True)          ;store the left hand weapon - if any
 
Righthand = PlayerRef.GetEquippedWeapon(False)          ;store the righthand weapon - if any
 
Items = PO3_SKSEFunctions.AddAllEquippedItemsToArray(PlayerRef)      ;store all equipped items in an array using https://www.nexusmods.com/skyrimspecialedition/mods/22854
int i                    ;define this variable for use in arrays
 
Spell_1 = New Spell[4]                ;create the spells array
 
i = spell_1.Length                 ;size of spells array (should be 4)
 
While (i)
 
  i = i - 1
 
  spell_1[i] = PlayerRef.GetEquippedSpell(i)          ;fill the spells array
 
EndWhile
PlayerRef.UnEquipAll()                ;all stored, strip the player
 
EndFunction
 
 
Function dz_undress_NPC_F(Actor NPCRef)
 
  If (NPCRef as Actor).HasMagicEffect(dz_undress_magic_effect)
 
   Return                  ;then we are done, exit the function
 
  EndIf
 
  dz_undress_spell.Cast(NPCRef, NPCRef)              ;cast the undress spell on the NPC
 
EndFunction

* I hope it helps.
Have a nice week.
Edited by maxarturo
Link to comment
Share on other sites

  • Recently Browsing   0 members

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