Jump to content

[LE] Please Help with a little Script


maxarturo

Recommended Posts

Hi everyone !.
I'm not an experienced scripter and although i've manage to make a few scripts to work correctly this one is giving me a hard time, because it's doing the exact opposite of what it's set to do.
What i'm trying to do :
When a gate-Portcullis is activated (in this case by a DweSteamTrigger) the Portcullis will Enable a Disable Xmarker (the Xmarker will enable other objects like lights, walls etc...). At this point everything is working correctly exept that the Portcullis in which the script is attached it's disabling the Link Ref instead of Enableing it.
This is my script:

Scriptname aXMD2StateActivatorEnableRef extends ObjectReference  
{This should enable Link Ref when gate is set to open}
 
import debug
import utility
 
bool property isOpen = false auto conditional
 
bool property doOnce = false auto
 
bool property isAnimating = false auto Hidden
 
string property openAnim = "open" auto
 
string property closeAnim = "close" auto
 
string property openEvent = "opening" auto
 
string property closeEvent = "closing" auto
 
string property startOpenAnim = "opened" auto
 
bool property bAllowInterrupt = FALSE auto
 
bool property zInvertCollision = FALSE auto
 
int property myState = 1 auto hidden
 
keyword property TwoStateCollisionKeyword auto
Keyword property LinkedRefKeyword Auto
 
; true when static or animating
; 0 == open or opening
; 1 == closed or closing
 
EVENT OnLoad()
SetDefaultState()
endEVENT
 
Event OnReset()
SetDefaultState()
EndEvent
 
Function SetDefaultState()
if (isOpen)
playAnimationandWait(startOpenAnim, openEvent)
 
if (zInvertCollision == FALSE)
trace(self + " Disabling Collision")
DisableLinkChain(TwoStateCollisionKeyword)
else
trace(self + " Enabling Collision")
EnableLinkChain(TwoStateCollisionKeyword)
endif
 
myState = 0
Else
playAnimationandWait(closeAnim, closeEvent)
 
if (zInvertCollision == FALSE)
trace(self + " Enabling Collision")
EnableLinkChain(TwoStateCollisionKeyword)
else
trace(self + " Disabling Collision")
DisableLinkChain(TwoStateCollisionKeyword)
endif
 
myState = 1
EndIf
EndFunction
 
auto STATE waiting ; waiting to be activated
EVENT onActivate (objectReference triggerRef)
 
SetOpen(!isOpen)
if (doOnce)
gotostate("done")
Self.GetLinkedRef(LinkedRefKeyword).Enable()
endif
endEVENT
endState
 
STATE busy
; This is the state when I'm busy animating
EVENT onActivate (objectReference triggerRef)
if bAllowInterrupt == TRUE
; send the activation\
SetOpen(!isOpen)
else
; block activation
trace (self + " Busy")
endif
endEVENT
endSTATE
 
STATE done
EVENT onActivate (objectReference triggerRef)
;Do nothing
endEVENT
endSTATE
 
function SetOpen(bool abOpen = true)
; if busy, wait to finish
while getState() == "busy"
wait(1)
endWhile
; open/close if necessary
isAnimating = true
if abOpen && !isOpen
gotoState ("busy")
trace(self + " Opening")
if bAllowInterrupt == TRUE || !Is3DLoaded()
playAnimation(openAnim) ; Animate Open
else
playAnimationandWait(openAnim, openEvent) ; Animate Open
endif
trace(self + " Opened")
 
if (zInvertCollision == FALSE)
trace(self + " Disabling Collision")
DisableLinkChain(TwoStateCollisionKeyword)
else
trace(self + " Enabling Collision")
EnableLinkChain(TwoStateCollisionKeyword)
endif
 
isOpen = true
gotoState("waiting")
elseif !abOpen && isOpen
gotoState ("busy")
trace(self + " Closing")
if bAllowInterrupt == TRUE || !Is3DLoaded()
playAnimation(closeAnim)
else
playAnimationandWait(closeAnim, closeEvent) ; Animate Closed
endif
trace(self + " Closed")
 
if (zInvertCollision == FALSE)
trace(self + " Enabling Collision")
EnableLinkChain(TwoStateCollisionKeyword)
else
trace(self + " Disabling Collision")
DisableLinkChain(TwoStateCollisionKeyword)
endif
 
isOpen = false
gotoState("waiting")
endif
isAnimating = false
endFunction

This is the line i'm having problem (i think?):


auto STATE waiting ; waiting to be activated
EVENT onActivate (objectReference triggerRef)
 
SetOpen(!isOpen)
if (doOnce)
gotostate("done")
Self.GetLinkedRef(LinkedRefKeyword).Enable()
endif
endEVENT
endState

 

 

In this script i get an option in the properties of the script to choose a Key word

 

 

 

This was my first attempt:

 

 

Scriptname aXMD2StateActivatorEnableRef extends ObjectReference  
{This should enable Link Ref when gate is set to open}
 
import game
import debug
import utility
 
bool property isOpen = false auto conditional
 
bool property doOnce = false auto
 
bool property isAnimating = false auto Hidden
 
string property openAnim = "open" auto
 
string property closeAnim = "close" auto
 
string property openEvent = "opening" auto
 
string property closeEvent = "closing" auto
 
string property startOpenAnim = "opened" auto
 
bool property bAllowInterrupt = FALSE auto
 
bool property zInvertCollision = FALSE auto
 
int property myState = 1 auto hidden
 
keyword property TwoStateCollisionKeyword auto
ObjectReference Property RefToBeEnabled auto
 
; true when static or animating
; 0 == open or opening
; 1 == closed or closing
 
EVENT OnLoad()
SetDefaultState()
endEVENT
 
Event OnReset()
SetDefaultState()
EndEvent
 
Function SetDefaultState()
if (isOpen)
playAnimationandWait(startOpenAnim, openEvent)
 
if (zInvertCollision == FALSE)
trace(self + " Disabling Collision")
DisableLinkChain(TwoStateCollisionKeyword)
else
trace(self + " Enabling Collision")
EnableLinkChain(TwoStateCollisionKeyword)
endif
 
myState = 0
Else
playAnimationandWait(closeAnim, closeEvent)
 
if (zInvertCollision == FALSE)
trace(self + " Enabling Collision")
EnableLinkChain(TwoStateCollisionKeyword)
else
trace(self + " Disabling Collision")
DisableLinkChain(TwoStateCollisionKeyword)
endif
 
myState = 1
EndIf
EndFunction
 
auto STATE waiting ; waiting to be activated
EVENT onActivate (objectReference triggerRef)
;  Debug.Trace("d2SA RESETS: " + Self + " " + isOpen)
; switch open state when activated
SetOpen(!isOpen)
if (doOnce)
gotostate("done")
             triggerRef == getPlayer() as actor
RefToBeEnabled.enable()
gotoState("Activated")
endif
endEVENT
endState
 
STATE busy
; This is the state when I'm busy animating
EVENT onActivate (objectReference triggerRef)
if bAllowInterrupt == TRUE
; send the activation\
SetOpen(!isOpen)
else
; block activation
trace (self + " Busy")
endif
endEVENT
endSTATE
 
STATE done
EVENT onActivate (objectReference triggerRef)
;Do nothing
endEVENT
endSTATE
 
function SetOpen(bool abOpen = true)
; if busy, wait to finish
while getState() == "busy"
wait(1)
endWhile
; open/close if necessary
isAnimating = true
if abOpen && !isOpen
gotoState ("busy")
trace(self + " Opening")
if bAllowInterrupt == TRUE || !Is3DLoaded()
playAnimation(openAnim) ; Animate Open
else
playAnimationandWait(openAnim, openEvent) ; Animate Open
endif
trace(self + " Opened")
 
if (zInvertCollision == FALSE)
trace(self + " Disabling Collision")
DisableLinkChain(TwoStateCollisionKeyword)
else
trace(self + " Enabling Collision")
EnableLinkChain(TwoStateCollisionKeyword)
endif
 
isOpen = true
gotoState("waiting")
elseif !abOpen && isOpen
gotoState ("busy")
trace(self + " Closing")
if bAllowInterrupt == TRUE || !Is3DLoaded()
playAnimation(closeAnim)
else
playAnimationandWait(closeAnim, closeEvent) ; Animate Closed
endif
trace(self + " Closed")
 
if (zInvertCollision == FALSE)
trace(self + " Enabling Collision")
EnableLinkChain(TwoStateCollisionKeyword)
else
trace(self + " Disabling Collision")
DisableLinkChain(TwoStateCollisionKeyword)
endif
 
isOpen = false
gotoState("waiting")
endif
isAnimating = false
endFunction

This is the line to enable a disabled Link Ref (but again i had the same resault):



auto STATE waiting ; waiting to be activated
EVENT onActivate (objectReference triggerRef)
;  Debug.Trace("d2SA RESETS: " + Self + " " + isOpen)
; switch open state when activated
SetOpen(!isOpen)
if (doOnce)
gotostate("done")
             triggerRef == getPlayer() as actor
RefToBeEnabled.enable()
gotoState("Activated")
endif
endEVENT
endState

In this script i get an option in the properties of the script to select a Link Ref to be enable
Many Thanks in Advance!!.
Edited by maxarturo
Link to comment
Share on other sites

I'm guessing the XMarker you are using starts disabled ... so it's just staying disabled, not that it's being switched to that.

The line Self.GetLinkedRef(LinkedRefKeyword).Enable() will never be read by its location in the if statement.

I take it you want it to be done once as in the variable name doOnce ... so this may/should work.

 

 

auto STATE waiting ; waiting to be activated
EVENT onActivate (objectReference triggerRef)
SetOpen(!isOpen)
if (doOnce)
gotostate("done")
endif
doOnce = true
Self.GetLinkedRef(LinkedRefKeyword).Enable()
endEVENT
endState
Edited by NexusComa
Link to comment
Share on other sites

 

I'm guessing the XMarker you are using starts disabled ... so it's just staying disabled, not that it's being switched to that.

The line Self.GetLinkedRef(LinkedRefKeyword).Enable() will never be read by its location in the if statement.

I take it you want it to be done once as in the variable name doOnce ... so this may/should work.

 

 

auto STATE waiting ; waiting to be activated
EVENT onActivate (objectReference triggerRef)
SetOpen(!isOpen)
if (doOnce)
gotostate("done")
endif
doOnce = true
Self.GetLinkedRef(LinkedRefKeyword).Enable()
endEVENT
endState

 

Thank you for replying.
I try your suggestion but didn't work, the only thing that is happening is that:
- Once i Link Ref the gate to an Enable object it disables the object. (and not the other way around)
- If i Link Ref the gate to a Desable object it does nothing.
This is my chain of events if this assist anyone in help me resolve this:
DweSteamTrigger(activates) > Portcullis-Gate(enables) > Xmarker or object (it's in desable state)
I'm useing a lot the enable-disable function in the mod i'm working on, in differents combination-Link Ref an chain of events with different kind of triggers and objects and they all work just fine, only this... is driving me nuts !!!.
Link to comment
Share on other sites

Is doOnce set to false ?

 

Anyways I'm kind of lost here what you are trying to do exactly. (by that script.)

Are you trying to turn a valve that opens a gate and have a 1 time enabled on a XMarker also.

and if so does the gate need to be blocked from the player opening it directly ...

 

It looks to me like you're over coding this to death ...

Explain what you're doing in detail ... What things look like before, what things should do during and what everything should be after.

What you're going for sounds easy to do so I just need the details and I'll get you rolling. I need to know all about what you want out of the gate

especially ... the before, during and after. As in is the gate useable and will it end up useable after you leave this area.

Edited by NexusComa
Link to comment
Share on other sites

maxarturo was looking for help. At first you can spare a lot of time by using Skyrim default scripts. And second use a function to test your own code.

 

default2StateActivator

 

Scriptname default2StateActivator extends ObjectReference Conditional
{v1.4 ReDragon 2014}    ; for any activator with standard open/close states
; see also "DLC2ApoExtendingHallScript" which extends default2stateActivator

;; What is the different between Skyrim and Dragonborn version?
;; ------------------------------------------------------------
;; bool property isAnimating = false auto Hidden Conditional    ; *** Dragonborn.esm ***
;; bool property isAnimating = false auto Hidden                ; *** Skyrim.esm ***
;; ============================================================

  Keyword PROPERTY TwoStateCollisionKeyword auto

  Bool PROPERTY isOpen = False auto Conditional        ; set TRUE, to start open
  Bool PROPERTY doOnce = False auto                    ; set TRUE, to open/close on first activation only

  Bool PROPERTY isAnimating = False auto Hidden Conditional        ; *** Dragonborn ***
; Is the activator currently animating from one state to another?

  Bool PROPERTY bAllowInterrupt  = False auto        ; Allow interrupts while animation? [Default=False]
  Bool PROPERTY zInvertCollision = False auto        ; [Default=False], If you want that functionality inverted set this to TRUE
; The Refs LinkRef Chained with the TwoStateCollisionKeyword will typically be Enabled onOpen, and Disabled on Close.

  String PROPERTY openAnim      = "open"    auto    ; animation to play when opening
  String PROPERTY closeAnim     = "close"   auto    ; animation to play when closing
  String PROPERTY openEvent     = "opening" auto    ; waits for this event before considering itself "open"
  String PROPERTY closeEvent    = "closing" auto    ; waits for this event before considering itself "closed"
  String PROPERTY startOpenAnim = "opened"  auto    ; OnLoad calls this if the object starts in the open state

  Int    PROPERTY myState       = 1 auto Hidden        ; 0 == open or opening, 1 == closed or closing


; -- EVENTs -- 2 + "waiting" + "busy" + "done"

EVENT OnReset()
    SetDefaultState()
ENDEVENT

EVENT OnLoad()
    SetDefaultState()
ENDEVENT


;============================================
auto STATE waiting
;=================
EVENT OnActivate(ObjectReference actionRef)
    gotoState("done")                ; ### STATE ###    switch immediately to this state

    SetOpen(!isOpen)                                    ; switch open state when activated
    IF ( doOnce )
        gotoState("done")            ; ### STATE ###
    ELSE
        gotoState("waiting")        ; ### STATE ###    go back to auto state, not really needed
    ENDIF
ENDEVENT
;=======
endState


;============================================
STATE busy
;=========
EVENT OnActivate(ObjectReference actionRef)
IF ( bAllowInterrupt )
    SetOpen(!isOpen)
;ELSE
ENDIF
ENDEVENT
;=======
endState


;============================================
STATE done        ; do nothing
;=========
endState


; -- FUNCTIONs -- 4

;-------------------------
FUNCTION SetDefaultState()    ; internal only
;-------------------------
; since OnLoad() and OnReset() can fire in either order,
; and we cannot handle competing animation calls.
; So we have to handle this with a function. (Bethesda)
;
; http://afkmods.iguanadons.net/index.php?/topic/4129-skyrim-interpreting-papyrus-log-errors/
; "OnReset now has to wait for 3D, so it will call the SetDefaultState() function almost
; at the same time as OnLoad, most likely within the same frame." (Sclerocephalus)

; see also these scripts:
; "DLC2ApoExtendingHallScript" extends default2stateActivator
; "dunCGdefault2StateActivator.psc"
; "NorLever01SCRIPT.psc", "NorPortcullisSCRIPT.psc", "TG08LeverPuzzle.psc"

IF (myState < 0)
    RETURN    ; - STOP -    OnReset() or OnLoad() is already running, do not animate twice at the same time
ENDIF
;---------------------
    myState = -1

IF ( isOpen )        ; - OPEN -
    self.PlayAnimationandWait(startOpenAnim, openEvent)
    myF_Open()
    myState = 0
ELSE                ; - CLOSE -
    self.PlayAnimationandWait(closeAnim, closeEvent)
    myF_Close()
    myState = 1
ENDIF
ENDFUNCTION


;------------------
FUNCTION myF_Open()
;------------------
    IF ( zInvertCollision )
        EnableLinkChain(TwoStateCollisionKeyword)
    ELSE
        DisableLinkChain(TwoStateCollisionKeyword)
    ENDIF
ENDFUNCTION

;-------------------
FUNCTION myF_Close()
;-------------------
    IF ( zInvertCollision )
        DisableLinkChain(TwoStateCollisionKeyword)
    ELSE
        EnableLinkChain(TwoStateCollisionKeyword)
    ENDIF
ENDFUNCTION


;-----------------------------------
FUNCTION SetOpen(Bool abOpen = true)
;-----------------------------------
WHILE (self.GetState() == "busy")
    Utility.Wait(1.0)                                ; if busy, wait to finish
ENDWHILE
    isAnimating = TRUE

; +++++++++++++++++++++++++++++++++++
IF (abOpen) && (!isOpen)
    gotoState ("busy")                ; ### STATE ###

    IF (bAllowInterrupt) || !self.Is3DLoaded()
        self.PlayAnimation(openAnim)
    ELSE
        self.PlayAnimationandWait(openAnim, openEvent)
    ENDIF
;;                                                    Debug.Trace(self+" Opened")
    myF_Open()
    isOpen = TRUE
    gotoState("waiting")            ; ### STATE ### go back to auto state

; +++++++++++++++++++++++++++++++++++
ELSEIF (!abOpen) && (isOpen)
    gotoState ("busy")                ; ### STATE ###

    IF (bAllowInterrupt) || !self.Is3DLoaded()
        self.PlayAnimation(closeAnim)
    ELSE
        self.PlayAnimationandWait(closeAnim, closeEvent)
    ENDIF
;;                                                    Debug.Trace(self+" Closed")
    myF_Close()
    isOpen = False
    gotoState("waiting")            ; ### STATE ### go back to auto state
ENDIF

    isAnimating = False
ENDFUNCTION

 

 

 

aXMD2StateActivatorEnableRef

 

Scriptname aXMD2StateActivatorEnableRef extends default2StateActivator
; https://forums.nexusmods.com/index.php?/topic/7160186-please-help-with-a-little-script/

  Keyword PROPERTY LinkedRefKeyword auto        ; What did you filled here?

; -- EVENTs --

;============================================
auto STATE waiting
;=================
EVENT OnActivate(ObjectReference actionRef)
    gotoState("done")                ; ### STATE ###    switch immediately to this state
    SetOpen(!isOpen)

    IF ( doOnce )
        gotoState("done")            ; ### STATE ###
        myF_EnableLink(actionRef)
;;;        self.GetLinkedRef(LinkedRefKeyword).Enable()
    ELSE
        gotoState("waiting")        ; ### STATE ###    go back to auto state, not really needed
    ENDIF
ENDEVENT
;=======
endState


; -- FUNCTION --

;-------------------------------------------------
FUNCTION myF_EnableLink(ObjectReference actionRef)
;-------------------------------------------------
    objectReference oRef = self.GetLinkedRef(LinkedRefKeyword)
    Debug.Trace(self+" OnActivate() - by " +actionRef+ ", linkedRef is " +oRef+ " with " +LinkedRefKeyword)        ; info only

; in case "LinkedRefKeyword" is None, next will be the same
; self.GetLinkedRef() == self.GetLinkedRef(None) == self.GetLinkedRef(LinkedRefKeyword)

    IF ( oRef )
        oRef.Enable()
    ELSE
        Debug.Trace(self+" OnActivate() - linkedRef by Keyword does not exists!")
    ENDIF
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

hold on firing up the kit for a few tests ... sorry had a few others things going on.

 

ok ...

 

Drop a XMarker down for use and disabled it. Take all the items in the room you are using for this and set them to the XMarker via the

[ Enable Parent ] tab and check [ pop in ] ... unless you want them to fade in ...

From the [ Script ] tab on the Portcullis Gate click the CWFortGateScript and press [ Remove ].

It should show a red - in front of the script name now (Perfect. Do not [ Edit Base ] at all).

Drop that defaultBlockFollowerActivation script on the valve.

Drop the lower script on the value and fill in the property's from the Creation Kit.
( you may want to change the name of the script )
------------------------------------
Scriptname MyValveScriptName extends ObjectReference
ObjectReference Property XMarker Auto
ObjectReference Property Gate Auto
Bool cf = true ; overclick flag
Bool gf = true ; gate info flag
Bool Property DisableFlag Auto
;
Event OnInit()
GoToState("GateControl")
EndEvent
Event OnLoad()
Gate.BlockActivation(true)
EndEvent
;-----------------------
State GateControl
Event OnActivate(ObjectReference akActionRef)
If(cf)
cf = false
Gate.BlockActivation(false)
If(gf)
gf = false
XMarker.Enable()
Gate.playAnimationandWait("open","opening")
Else
gf = true
If(DisableFlag)
XMarker.Disable()
Endif
Gate.playAnimationandWait("close","closing")
Endif
Gate.BlockActivation(true)
Utility.Wait(2.0)
cf = true
Endif
EndEvent
EndState
;
There is also a way to get rid of the "Open Gate" and "Close Gate " words that show on the screen when you point at the gate too.
If you want to know how just say so ... little complicated but it's not that bad and would be easy to add to this without changing anything done.
Ran into a little trouble here with a few things. That gate there is always a pain and so is that valve ...
And what if they just walk up and click the gate. Also I didn't know if once you enabled the room objects
you wished to disable them when you close the gate. So I put in an option to do it both ways ...
You could trim the wait time down to something like 1.1 ... I used 2.0 for a tiny totally sure buffer but the gate animation time is 1.
I added in a counter spamming the switch flag because they always do that. :smile: Set that true of false from the Creation Kit.
Fully tested, runs like a champ have fun!
Edited by NexusComa
Link to comment
Share on other sites

maxarturo was looking for help. At first you can spare a lot of time by using Skyrim default scripts. And second use a function to test your own code.

 

default2StateActivator

 

Scriptname default2StateActivator extends ObjectReference Conditional
{v1.4 ReDragon 2014}    ; for any activator with standard open/close states
; see also "DLC2ApoExtendingHallScript" which extends default2stateActivator

;; What is the different between Skyrim and Dragonborn version?
;; ------------------------------------------------------------
;; bool property isAnimating = false auto Hidden Conditional    ; *** Dragonborn.esm ***
;; bool property isAnimating = false auto Hidden                ; *** Skyrim.esm ***
;; ============================================================

  Keyword PROPERTY TwoStateCollisionKeyword auto

  Bool PROPERTY isOpen = False auto Conditional        ; set TRUE, to start open
  Bool PROPERTY doOnce = False auto                    ; set TRUE, to open/close on first activation only

  Bool PROPERTY isAnimating = False auto Hidden Conditional        ; *** Dragonborn ***
; Is the activator currently animating from one state to another?

  Bool PROPERTY bAllowInterrupt  = False auto        ; Allow interrupts while animation? [Default=False]
  Bool PROPERTY zInvertCollision = False auto        ; [Default=False], If you want that functionality inverted set this to TRUE
; The Refs LinkRef Chained with the TwoStateCollisionKeyword will typically be Enabled onOpen, and Disabled on Close.

  String PROPERTY openAnim      = "open"    auto    ; animation to play when opening
  String PROPERTY closeAnim     = "close"   auto    ; animation to play when closing
  String PROPERTY openEvent     = "opening" auto    ; waits for this event before considering itself "open"
  String PROPERTY closeEvent    = "closing" auto    ; waits for this event before considering itself "closed"
  String PROPERTY startOpenAnim = "opened"  auto    ; OnLoad calls this if the object starts in the open state

  Int    PROPERTY myState       = 1 auto Hidden        ; 0 == open or opening, 1 == closed or closing


; -- EVENTs -- 2 + "waiting" + "busy" + "done"

EVENT OnReset()
    SetDefaultState()
ENDEVENT

EVENT OnLoad()
    SetDefaultState()
ENDEVENT


;============================================
auto STATE waiting
;=================
EVENT OnActivate(ObjectReference actionRef)
    gotoState("done")                ; ### STATE ###    switch immediately to this state

    SetOpen(!isOpen)                                    ; switch open state when activated
    IF ( doOnce )
        gotoState("done")            ; ### STATE ###
    ELSE
        gotoState("waiting")        ; ### STATE ###    go back to auto state, not really needed
    ENDIF
ENDEVENT
;=======
endState


;============================================
STATE busy
;=========
EVENT OnActivate(ObjectReference actionRef)
IF ( bAllowInterrupt )
    SetOpen(!isOpen)
;ELSE
ENDIF
ENDEVENT
;=======
endState


;============================================
STATE done        ; do nothing
;=========
endState


; -- FUNCTIONs -- 4

;-------------------------
FUNCTION SetDefaultState()    ; internal only
;-------------------------
; since OnLoad() and OnReset() can fire in either order,
; and we cannot handle competing animation calls.
; So we have to handle this with a function. (Bethesda)
;
; http://afkmods.iguanadons.net/index.php?/topic/4129-skyrim-interpreting-papyrus-log-errors/
; "OnReset now has to wait for 3D, so it will call the SetDefaultState() function almost
; at the same time as OnLoad, most likely within the same frame." (Sclerocephalus)

; see also these scripts:
; "DLC2ApoExtendingHallScript" extends default2stateActivator
; "dunCGdefault2StateActivator.psc"
; "NorLever01SCRIPT.psc", "NorPortcullisSCRIPT.psc", "TG08LeverPuzzle.psc"

IF (myState < 0)
    RETURN    ; - STOP -    OnReset() or OnLoad() is already running, do not animate twice at the same time
ENDIF
;---------------------
    myState = -1

IF ( isOpen )        ; - OPEN -
    self.PlayAnimationandWait(startOpenAnim, openEvent)
    myF_Open()
    myState = 0
ELSE                ; - CLOSE -
    self.PlayAnimationandWait(closeAnim, closeEvent)
    myF_Close()
    myState = 1
ENDIF
ENDFUNCTION


;------------------
FUNCTION myF_Open()
;------------------
    IF ( zInvertCollision )
        EnableLinkChain(TwoStateCollisionKeyword)
    ELSE
        DisableLinkChain(TwoStateCollisionKeyword)
    ENDIF
ENDFUNCTION

;-------------------
FUNCTION myF_Close()
;-------------------
    IF ( zInvertCollision )
        DisableLinkChain(TwoStateCollisionKeyword)
    ELSE
        EnableLinkChain(TwoStateCollisionKeyword)
    ENDIF
ENDFUNCTION


;-----------------------------------
FUNCTION SetOpen(Bool abOpen = true)
;-----------------------------------
WHILE (self.GetState() == "busy")
    Utility.Wait(1.0)                                ; if busy, wait to finish
ENDWHILE
    isAnimating = TRUE

; +++++++++++++++++++++++++++++++++++
IF (abOpen) && (!isOpen)
    gotoState ("busy")                ; ### STATE ###

    IF (bAllowInterrupt) || !self.Is3DLoaded()
        self.PlayAnimation(openAnim)
    ELSE
        self.PlayAnimationandWait(openAnim, openEvent)
    ENDIF
;;                                                    Debug.Trace(self+" Opened")
    myF_Open()
    isOpen = TRUE
    gotoState("waiting")            ; ### STATE ### go back to auto state

; +++++++++++++++++++++++++++++++++++
ELSEIF (!abOpen) && (isOpen)
    gotoState ("busy")                ; ### STATE ###

    IF (bAllowInterrupt) || !self.Is3DLoaded()
        self.PlayAnimation(closeAnim)
    ELSE
        self.PlayAnimationandWait(closeAnim, closeEvent)
    ENDIF
;;                                                    Debug.Trace(self+" Closed")
    myF_Close()
    isOpen = False
    gotoState("waiting")            ; ### STATE ### go back to auto state
ENDIF

    isAnimating = False
ENDFUNCTION

 

 

 

aXMD2StateActivatorEnableRef

 

Scriptname aXMD2StateActivatorEnableRef extends default2StateActivator
; https://forums.nexusmods.com/index.php?/topic/7160186-please-help-with-a-little-script/

  Keyword PROPERTY LinkedRefKeyword auto        ; What did you filled here?

; -- EVENTs --

;============================================
auto STATE waiting
;=================
EVENT OnActivate(ObjectReference actionRef)
    gotoState("done")                ; ### STATE ###    switch immediately to this state
    SetOpen(!isOpen)

    IF ( doOnce )
        gotoState("done")            ; ### STATE ###
        myF_EnableLink(actionRef)
;;;        self.GetLinkedRef(LinkedRefKeyword).Enable()
    ELSE
        gotoState("waiting")        ; ### STATE ###    go back to auto state, not really needed
    ENDIF
ENDEVENT
;=======
endState


; -- FUNCTION --

;-------------------------------------------------
FUNCTION myF_EnableLink(ObjectReference actionRef)
;-------------------------------------------------
    objectReference oRef = self.GetLinkedRef(LinkedRefKeyword)
    Debug.Trace(self+" OnActivate() - by " +actionRef+ ", linkedRef is " +oRef+ " with " +LinkedRefKeyword)        ; info only

; in case "LinkedRefKeyword" is None, next will be the same
; self.GetLinkedRef() == self.GetLinkedRef(None) == self.GetLinkedRef(LinkedRefKeyword)

    IF ( oRef )
        oRef.Enable()
    ELSE
        Debug.Trace(self+" OnActivate() - linkedRef by Keyword does not exists!")
    ENDIF
ENDFUNCTION

 

 

Thanks for replying.
That's how i started by using Skyrim default scripts and learned by comparing and modifying those scripts, as i mention i'm not an experienced scripter and since there aren't any tutorials out there to teach you (none that i could find), this was the only approach i could take.
I did learn something... then everything got messed up trying to make this script work.
Link to comment
Share on other sites

 

hold on firing up the kit for a few tests ... sorry had a few others things going on.

 

ok ...

 

Drop a XMarker down for use and disabled it. Take all the items in the room you are using for this and set them to the XMarker via the

[ Enable Parent ] tab and check [ pop in ] ... unless you want them to fade in ...

From the [ Script ] tab on the Portcullis Gate click the CWFortGateScript and press [ Remove ].

It should show a red - in front of the script name now (Perfect. Do not [ Edit Base ] at all).

Drop that defaultBlockFollowerActivation script on the valve.

Drop the lower script on the value and fill in the property's from the Creation Kit.
( you may want to change the name of the script )
------------------------------------
Scriptname MyValveScriptName extends ObjectReference
ObjectReference Property XMarker Auto
ObjectReference Property Gate Auto
Bool cf = true ; overclick flag
Bool gf = true ; gate info flag
Bool Property DisableFlag Auto
;
Event OnInit()
GoToState("GateControl")
EndEvent
Event OnLoad()
Gate.BlockActivation(true)
EndEvent
;-----------------------
State GateControl
Event OnActivate(ObjectReference akActionRef)
If(cf)
cf = false
Gate.BlockActivation(false)
If(gf)
gf = false
XMarker.Enable()
Gate.playAnimationandWait("open","opening")
Else
gf = true
If(DisableFlag)
XMarker.Disable()
Endif
Gate.playAnimationandWait("close","closing")
Endif
Gate.BlockActivation(true)
Utility.Wait(2.0)
cf = true
Endif
EndEvent
EndState
;
There is also a way to get rid of the "Open Gate" and "Close Gate " words that show on the screen when you point at the gate too.
If you want to know how just say so ... little complicated but it's not that bad and would be easy to add to this without changing anything done.
Ran into a little trouble here with a few things. That gate there is always a pain and so is that valve ...
And what if they just walk up and click the gate. Also I didn't know if once you enabled the room objects
you wished to disable them when you close the gate. So I put in an option to do it both ways ...
You could trim the wait time down to something like 1.1 ... I used 2.0 for a tiny totally sure buffer but the gate animation time is 1.
I added in a counter spamming the switch flag because they always do that. :smile: Set that true of false from the Creation Kit.
Fully tested, runs like a champ have fun!

 

Again thanks for taking the time to reply and search for a solution !!!..
But i got so frustrated trying to make this work + i lost almost 10 days trying to set up and make it work correctly, that i completely change the puzzle that this was intended to, it was so complicated to build that i had to draw schematics in order to make it work correctly, 54 different objects interacting with each other.
I had to change direction and remove from the equation the gate enableing the XMarker that it was used to activate lights & steam fx so that the player could keep truck of the Steam Triggers that had been activated. Now i've cut the puzzle by half and the player can see all Steam triggers and activators by just standing in the middle of the room, and is much more elegance and easy to built.
Althought the sequence Trigger > Portcullis > Xmarker i will need it for my last cell but in this case not for a puzzle, until that time i'm taking a break from this because as i mention i'm not an expirienced scripter and everything i've manage to learn it's completely messed up in my head right now by trying to make this work !!.
Many... Many thanks for taking the time to help me !!!.
* I might need to bother you again if i don't manage to make it work when i build my last cell.
Edited by maxarturo
Link to comment
Share on other sites

I will use default build in scripts the way they are intended ... generically. If I'm doing a custom anything the main script is usually made from scratch.

I need to totally understand what is going on to feel I'm not pushing out mods with errors. Also been programming for 40 years professionally so ...

That code I gave you is rock solid, eliminates possible player error and takes care of the player just clicking on the gate bypassing the valve.

 

When I do things like you are doing I like you use XMarkers and link my room objects to it. It helps when you really start getting complicated.

 

I have a script you may like it is very generic and I use it to death for this type of stuff. It is placed on switches and has the huge advantage in that

it can be used by multiple switches to change the same XMarker no matter the state. Opens up a few options for use in that respect.

It is simplistic, easy to use and has never failed me ... it is a double logic script. XMarker state is read on the fly and the script adjusts.

 

Scriptname _MarkerEnable extends ObjectReference
;* Marker Enable/Disable * By: NexusComa * nexusmods.com
ObjectReference Property Marker Auto
;
Event OnInit()
If(Marker.IsDisabled())
GoToState("Disable")
Else
GoToState("Enable")
EndIf
EndEvent
;-----------------------
State Disable
Event OnBeginState()
Marker.Disable()
EndEvent
Event OnActivate(ObjectReference akActionRef)
If(Marker.IsDisabled())
GoToState("Enable")
Else
GoToState("Disable")
EndIf
EndEvent
EndState
;-----------------------
State Enable
Event OnBeginState()
Marker.Enable()
EndEvent
Event OnActivate(ObjectReference akActionRef)
If(Marker.IsDisabled())
GoToState("Enable")
Else
GoToState("Disable")
EndIf
EndEvent
EndState

;

Link to comment
Share on other sites

  • Recently Browsing   0 members

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