Chthonian Posted May 1, 2016 Share Posted May 1, 2016 I am making all the lights in my mod turn off and on with switches via script, but I've got an issue. As many of you know there are not many tutorials floating around for Fallout 4's CK, therefore I have been trying to make my light switches work using scripts from Skyrim. I found this on the Creation Kits website: ScriptName ManualLightSwitch extends ObjectReference{Controls a set of lights with a master enable parentmarker (EnableMarker) and a switch with this scriptattached to turn on and off when the switch is activated}ObjectReference Property EnableMarker auto{The marker set as the enable parent of all the lights}Event OnInit() If (EnableMarker.IsDisabled()) GoToState("LightsOff") Else GoToState("LightsOn") EndIfEndEventState LightsOff Event OnBeginState() EnableMarker.Disable() EndEvent Event OnActivate(ObjectReference akActionRef) GoToState("LightsOn") EndEventEndStateState LightsOn Event OnBeginState() EnableMarker.Enable() EndEvent Event OnActivate(ObjectReference akActionRef) GoToState("LightsOff") EndEventEndState Only thing I changed was the name at the start of the script to match the name I gave mine for my mod, but my problem is I go to save the script but it won't because it fails to compile. I have tried different names for the script thinking maybe something in the name is causing it to fail, but everyone of them fails. If someone can help shed some light on why its not compiling I'd be much obliged. Also just for reference these are what I have changed the name to: ChtTubManualLightSwitch ChtMOTlightswitchscript ChtMOTlightswitch00 chttublight Link to comment Share on other sites More sharing options...
rdunlap Posted May 1, 2016 Share Posted May 1, 2016 onbeginstate() needs a parameter of string Event OnBeginState(string asOldState) EnableMarker.Disable() EndEvent in GoToState you pass it a string so compiler expects you to handle a string Robert Your complete script would change thus. ScriptName ManualLightSwitch extends ObjectReference{Controls a set of lights with a master enable parentmarker (EnableMarker) and a switch with this scriptattached to turn on and off when the switch is activated} ObjectReference Property EnableMarker auto{The marker set as the enable parent of all the lights} Event OnInit() If (EnableMarker.IsDisabled()) GoToState("LightsOff") Else GoToState("LightsOn") EndIf EndEvent State LightsOff Event OnBeginState(string asOldState) EnableMarker.Disable() EndEvent Event OnActivate(ObjectReference akActionRef) GoToState("LightsOn") EndEvent EndState State LightsOn Event OnBeginState(string asOldState) EnableMarker.Enable() EndEvent Event OnActivate(ObjectReference akActionRef) GoToState("LightsOff") EndEvent EndState and compiles well Link to comment Share on other sites More sharing options...
Chthonian Posted May 1, 2016 Author Share Posted May 1, 2016 omg thank you so much, worked like a charm!!! I can finally finish my mod and get it released! Link to comment Share on other sites More sharing options...
rdunlap Posted May 1, 2016 Share Posted May 1, 2016 :) your welcome. Link to comment Share on other sites More sharing options...
daisy8 Posted March 29, 2017 Share Posted March 29, 2017 Hi everyone I have been trying to replicate the light switch script here using a 'toggle button'. The script that comes with the button works fine, but I would like to modify it to enable lights. If I copy the whole default script and use the copy instead of the default, the switch does not do anything on activate. Any reason why ? It is the same script after all ?? I have a copy of the switch with a different name (created by changing the name in the edit base dialog). My intention was to create a light switch that activates, lights up when the lights are on and then when activated again turns the lights off and dims itself too. Below is the script I have. It is a straight copy of the default one on the switch (I have not modified it), but it still wont work. When the player approaches it the activate dialog shows up but there is no interaction with the switch. If I could get a renamed version of the default script to work on a copy of the switch I could then modify the renamed script to turn on lights and play the right animations, but have not been able to. Any help would be awesome ! Thanks ! Scriptname ADZLightSwitch2State extends ObjectReference {Script for a button with active and inactive states.} Group Required_Properties Message property ToggleButtonInactiveMessage auto {Failure message to display if the player presses the button while it's in its inactive state. Can be changed via script if desired.} String property animationName = "Press" auto const {Animation to play when the button is activated.} EndGroup Group Optional_Properties bool property startsActive = False auto const {Should the button start in the Active state? Default: False} bool property playerActivationOnly = False auto const {Should we block follower activation of this button? Default: False} bool property shouldAutoReset = False auto const {Should the button automatically return to the Inactive state after being pressed while in the active state? Assuming no other scripting, this effectively makes the button single-use. Default: False} Keyword property LinkedRefToActivate auto const {Keyword of a linked ref to activate when the button is successfully pressed. If None, don't activate anything.} String property inactiveStateAnimation = "TurnOff01" auto const {Name for the animation event called when the button enters the Inactive state. Default="Red"} String property activeStateAnimation = "TurnOn01" auto const {Name for the animation event called when the button enters the Active state. Default="Green"} EndGroup bool animationStateInactive = True ;Is the button currently in the 'Inactive' animation state? Used to minimize warning spam. bool shouldBeActiveNext = False ;Used for SetActiveNoWait, the whether the button should be active once the timer returns. Event OnLoad() ;Block follower activation if desired. Self.SetNoFavorAllowed(playerActivationOnly) ;Set initial state. SetActive(startsActive) EndEvent Function SetActive(bool shouldBeActive) Self.WaitFor3DLoad() if (shouldBeActive) if (GetState() != "Active") if (animationStateInactive) Self.PlayAnimationAndWait(ActiveStateAnimation, "End") animationStateInactive = False EndIf Self.BlockActivation(False) GoToState("Active") EndIf Else if (GetState() != "Inactive") if (!animationStateInactive) Self.PlayAnimationAndWait(InactiveStateAnimation, "End") animationStateInactive = True EndIf Self.BlockActivation(True) GoToState("Inactive") EndIf EndIf EndFunction Function SetActiveNoWait(bool shouldBeActive) shouldBeActiveNext = shouldBeActive StartTimer(0) EndFunction Event OnTimer(int timerID) SetActive(shouldBeActiveNext) EndEvent Function SetBusy(bool shouldBeBusy, bool returnToActive = True) Self.WaitFor3DLoad() if (shouldBeBusy) if (GetState() != "Busy") Self.BlockActivation(True) GoToState("Busy") EndIf Else SetActive(returnToActive) EndIf EndFunction State Inactive Event OnActivate(ObjectReference akActionRef) SetBusy(True) PlayAnimationAndWait(animationName, "End") ToggleButtonInactiveMessage.Show() SetBusy(False, False) EndEvent EndState State Active Event OnActivate(ObjectReference akActionRef) SetBusy(True) PlayAnimationAndWait(animationName, "End") if ((LinkedRefToActivate != None) && (Self.GetLinkedRef(LinkedRefToActivate) != None)) Self.GetLinkedRef(LinkedRefToActivate).Activate(akActionRef) EndIf if (shouldAutoReset) SetBusy(False, False) Else SetBusy(False, True) EndIf EndEvent EndState State Busy Event OnActivate(ObjectReference akActionRef) ;Do nothing. EndEvent EndState Link to comment Share on other sites More sharing options...
MissingMeshTV Posted March 29, 2017 Share Posted March 29, 2017 Unless I'm missing a specific reason or function you want to use, these scripts seem far more complex than they need to be for just turning lights on and off. This is what I use for all my light switches, and it works on the vanilla toggle and button switches as well: Scriptname LightToggle extends ObjectReference ObjectReference Property LightMarker Auto Event OnActivate(ObjectReference akActionRef) If (LightMarker.IsEnabled()) LightMarker.disable() Else LightMarker.enable() EndIf EndEvent The lights are parented to an EnableMarker or XMarker set to be initially disabled. I have a video tutorial on using the script and getting light switches to work. Link to comment Share on other sites More sharing options...
daisy8 Posted March 29, 2017 Share Posted March 29, 2017 Hi Rocket, thanks for the reply ! I have used a very similar script for switches too in past creation kits, but for some reason they aren't working for me now in Fallout4. Fantastic tutorial ! However, I have followed the steps but cannot get the lights on. Will try a few more things tomorrow. Does the above work for everyone else ? Thanks againdaisy Link to comment Share on other sites More sharing options...
MissingMeshTV Posted March 29, 2017 Share Posted March 29, 2017 I'm probably stating the obvious, but make sure you define the properties for your own markers, and don't just copy/paste my example. Link to comment Share on other sites More sharing options...
daisy8 Posted March 29, 2017 Share Posted March 29, 2017 Hey. Yep, I tried your tutorial example exactly. I will put together a little collage of my dialog boxes and put it on here so you can see what I have done. A couple of other things in my creation kit aren't working either so I will try a re install too.Cheers! Link to comment Share on other sites More sharing options...
caleb68 Posted March 31, 2017 Share Posted March 31, 2017 I recently had problems with things not functioning properly in ck and getting wierd errors when loading mods to work on them, I found that the problem was inside the creationkitPrefs.ini. I deleted that and started up ck, setup my layout again, and loaded the mod, everything started working again. Started going funky on me after updating to the latest. Far as RedRocketTV script, I have one thats pretty much exactly like his (different objectreference name), I also have one that toggles a power switch off / on as well thats just as simple, both work fine for me. Link to comment Share on other sites More sharing options...
Recommended Posts