Jump to content

[LE] [Papyrus] Script range


Daimonicon

Recommended Posts

Hello,


I'm not quite sure if you're talking about range in this context, so I'll describe in detail.


I would like to activate and deactivate the flares on several objects that are spread over different cells. I already have the script my question would be - Should I assign a separate script to each object, or can one script control the torches in whitewalk the same as the ones in solitude ? So the script would activate an object reference e.g. an XMarker and another XMarker behaves then exactly opposite. So the torches would turn on at time X and turn off again.


If it depends on the code I put it here somehow the forum codeblock doesn't work.



Link to comment
Share on other sites

There are many ways to do things. The preferred way you're describing is to Enable Parent for all the references you want to enable / disable, to link them to one object reference, such as an xMarker. Then, to disable or enable them all, you just disable or enable the xMarker reference. Since they are vanilla objects though, that would require editing their forms in the CK which can be bad for compatibility. So, in that case I would put them all in a formlist or array and use a while loop in a single script to enable or disable them.

 

Formlist Property TorchRefs Auto 

Function EnableRefs()
    Int I = TorchRefs.GetSize()
    While I > 0 
        I -= 1 
        (TorchRefs.GetAt(I) as ObjectReference).Enable()
    EndWhile 
EndFunction

Function DisableRefs()
    Int I = TorchRefs.GetSize()
    While I > 0 
        I -= 1 
        (TorchRefs.GetAt(I) as ObjectReference).Disable()
    EndWhile 
EndFunction
Link to comment
Share on other sites

Refering to the provided papyrus source code on "codesharing.io", there is a lot of extra logging code inside. No matter it should be used or not.

 

daimLightSwitchScript

 

Scriptname daimLightSwitchScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/10524988-papyrus-script-range/

; Controls a set of lights linked to a xMarker (this script attached) to turn it on/off depends on daytime

  GlobalVariable  PROPERTY GameHour    auto        ; use auto-fill
  ObjectReference PROPERTY LightMarker auto        ; control marker to switch on/off all the lights

  Float PROPERTY timeOFF =  6.0 auto    ; at this hour lights should be turned OFF
  Float PROPERTY timeON  = 20.0 auto    ; at this hour lights should be turned ON


; -- EVENTs -- 3 + "Waiting"

EVENT OnInit()
    Debug.Trace(" OnInit() - has been reached for " +self)
ENDEVENT

EVENT OnCellAttach()
;EVENT OnCellLoad()
    myF_Action()
    gotoState("Waiting")            ; ### STATE ###    use OnUpdateGameTime() to check periodically
ENDEVENT

EVENT OnCellDetach()
;EVENT OnUnLoad()
    UnRegisterForUpdateGameTime()
    gotoState("")                   ; ### STATE ### do not check again with update

IF ( LightMarker )
    IF LightMarker.IsDisabled()
    ELSE
        LightMarker.DisableNoWait()            ; disable regardeless of time, maybe player goes into a house or is doing fast travel
    ENDIF
ENDIF
ENDEVENT


;============================
state Waiting
;============
    EVENT OnUpdateGameTime()
        Utility.Wait(0.1)
        myF_Action()
    ENDEVENT
;=======
endState


; -- FUNCTIONs -- 2

;--------------------
FUNCTION myF_Action()
;--------------------
    float f = GameHour.GetValue()
    float w

    IF (f >= timeOFF) && (f < timeON)       ; OFF ( 6.00 .. 19.59 )     6am >= f < 8pm        
        IF LightMarker.IsDisabled()
        ELSE
            LightMarker.DisableNoWait()
        ENDIF
        w = myF_WaitTime(f, timeON)
    ELSE                                    ; ON  ( 20.00 .. 5.59 )     8pm > f <= 12pm, 0am <= f < 6am
        IF LightMarker.IsDisabled()
            LightMarker.EnableNoWait(()
        ENDIF
        w = myF_WaitTime(f, timeOFF)
    ENDIF

    RegisterForSingleUpdateGameTime(w)      ; check lights again after ingame time waiting
ENDFUNCTION


;------------------------------------------------
Float FUNCTION myF_WaitTime(Float f, Float fTime)
;------------------------------------------------
    float w = 0.75

IF (fTime == OFF) && (f >= fTime)
    RETURN w                                ; 8pm > f <= 12pm
ENDIF
;---------
    WHILE ((f+w) > fTime)
        w = w - 0.1
    ENDWHILE

    RETURN w
ENDFUNCTION

 

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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