TimedLightSwitch script question

Post » Wed Jun 20, 2012 11:50 am

Hey, folks. Bumbling along like a tumbling tumbleweed through the CK, and I latched onto the http://www.creationkit.com/Light_Switch script to control a couple of lanterns outside a house I'm working on.

The instructions had me bewildered for a bit, as there is no "master" setting or enable/disable feature under the Enable Parent tab, but I eventually set up a generic X-marker, attached the script to that and was able to use the Select Reference in Render Window under the Enable Parent tab for the lanterns. :shrug:

There are a total of six items I'm trying to control, or rather, two groups of three items each:

CandleLanternwithCandle01 <- this is the base lantern
FXGlowFillRoundMid <- a glow suggesting atmosphere
SLightCandleStreet01 <- the actual illumination effect sphere

By jiminy, it worked! Well, sort of... I arrived at the house at 8:35am and both lanterns were gone. Oh, I see, by disabling the base lanterns with the script, they disappeared. :facepalm: Back to the drawing board, er, CK. I saw a checkbox on the lantern editor marked, "Turn Off Fire" so I checked that, saved, and tried again. Nope, that would be too easy. :( So next I simply deleted the reference to the controlling X-marker.

Well, alrighty then! The glow and illumination switch on and off right on schedule, and the lanterns are there... and the candles are lit at all times. :blink:

Now I'm thinking I'll have to add additional lanterns superimposing the existing ones, but with the fire-off box ticked. Then link both types to the X-marker again, but with the "fire-off" ones' Enable State set opposite the X-marker. So at dawn the lighted lanterns disappear as the dead ones appear. :ahhh:

Does that make sense? I've got the glow and illumination working as intended, but I just need to snuff the candles at daybreak, and relight them at dusk as well. Am I missing a simpler, more elegant solution? Let me know if there is! :whisper:
User avatar
FoReVeR_Me_N
 
Posts: 3556
Joined: Wed Sep 05, 2007 8:25 pm

Post » Wed Jun 20, 2012 4:28 pm

Update: I duplicated each lantern, checked the "turn off fire" box, and set them to activate opposite the master X-marker. Well, the candles are lit anyway, but the lanterns do "switch out" at the right time. :glare:

The trouble there is that one lantern fades out, then the next fades in, then the FX fade in. For clarity's sake, I also renamed the editor reference to something meaningful: LanternPatioOn, LanternPatioOff, LanternRoadOn, and LanternRoadOff.

Now I'm thinking I'll have to use the plain lantern for the "off" mode, but put some dead candles inside, as the base lantern has none. :unsure2:
User avatar
teeny
 
Posts: 3423
Joined: Sun Feb 25, 2007 1:51 am

Post » Wed Jun 20, 2012 11:33 pm

Wow. I wrote my own Light Timer for some campfires and the script is like 10 lines. That script just seems over complicated.
User avatar
WTW
 
Posts: 3313
Joined: Wed May 30, 2007 7:48 pm

Post » Wed Jun 20, 2012 12:16 pm

Wow. I wrote my own Light Timer for some campfires and the script is like 10 lines. That script just seems over complicated.

Haha, yes. I wrote one for interiors that also applies an imagespace modifier:
Spoiler

	scriptname DaylightMarker extends ObjectReference  		imagespacemodifier property InteriorDaylight auto		Float GameTime	Float CurrentTime	Bool Loop	Bool IsImodActive		Event OnCellAttach()			IsImodActive = false			Loop = true			while ( Loop == true )		  					;Current hour is Total hours passed - Full days passed * 24					GameTime = utility.GetCurrentGameTime()					CurrentTime = Math.Floor(GameTime*24) - Math.Floor(GameTime)*24				  					if ( CurrentTime >= 8 && CurrentTime < 20 )				  							;Daylight							;Disable the marker							disable()								;Apply daylight imod							if ( IsImodActive == false )									IsImodActive = true									InteriorDaylight.Apply()							endif						  					else				  							;Night							;Enable the marker							enable()							;Remove imod							InteriorDaylight.Remove()							IsImodActive = false						  					endif				  					;Wait to check again					utility.wait(3)				  			endwhile		  	endEvent			Event OnCellDetach()				;Stop the loop when we leave the cell			Loop = false			;Remove imod			InteriorDaylight.Remove()			IsImodActive = false		endevent

Anyway, just put "false" as an argument when calling disable or enable, it will disable the fadie in/fade out:
http://www.creationkit.com/Enable_-_ObjectReference
User avatar
Roddy
 
Posts: 3564
Joined: Fri Jun 15, 2007 11:50 pm

Post » Thu Jun 21, 2012 1:58 am

Haha, yes. I wrote one for interiors that also applies an imagespace modifier:

Anyway, just put "false" as an argument when calling disable or enable, it will disable the fadie in/fade out:
http://www.creationkit.com/Enable_-_ObjectReference

Hey, thanks for the code snippet. I'll add it to my big box of script pieces, lol. I saw that there's a checkbox marked "pop (something)" on the objects which might work, too.

So basically what I've outlined is correct, then? Heh, I sound like I'm from Minnesota. :lmao: That I have to add a second object (in this case a lantern, or in others, a candlehorn or what-have-you) that isn't lit and alternate the two objects in the same space? It's just that the lantern is dead, or inert, in the CK, but the flames appear in-game, so it's a bit confusing.

Edit: I'm new to Papyrus and game scripting, but have been dabbling in a few programming and scripting languages since the end of the 70s. But it looks like your code activates when the cell is entered, checks the time and then either enables or disables the marker. Is this a marker that controls the campfire, or the campfire itself that has this attached?

I'm here all weekend, don't tell your friends. :wave: And I have a fridge full of beer brain medication to help me parse these scripts, lol. :foodndrink:
User avatar
Josh Lozier
 
Posts: 3490
Joined: Tue Nov 27, 2007 5:20 pm

Post » Wed Jun 20, 2012 10:49 am

Well, you can attach it to the fire itself or the marker, but it's of course less processing time if you just attach it to the marker and make it the enable parent for the fires/other objects.

Also if you want it to replace them with something during the day, you don't need to make a separate marker; just check "initially disabled" on the replacement, and use the same marker.

And yes, my code also runs a loop every 3 seconds while you're in the cell to check if the time has changed. There are better ways to do this but it was the first script I wrote with Papyrus, so I didn't know about the OnUpdate event.
User avatar
Charlie Sarson
 
Posts: 3445
Joined: Thu May 17, 2007 12:38 pm

Post » Wed Jun 20, 2012 10:34 pm

Here's my little code for turning on lights at night and off in the morning (8PM, 6AM).

http://www.creationkit.com/Additional_Prefabs#Removable_Torches


Event OnInit()RegisterForUpdateGameTime(2)EndEventEvent OnUpdateGameTime()float GameTime = utility.GetCurrentGameTime()int GameTimeInt = (GameTime as int)float TOD = ((GameTime - GameTimeInt)*24)If(TOD < 6) || (TOD > 20)MyLight.Disable()EndIfEndEvent
User avatar
Connie Thomas
 
Posts: 3362
Joined: Sun Nov 19, 2006 9:58 am

Post » Wed Jun 20, 2012 9:47 pm

The sad thing is, the basic lantern does not have an upright bail, so if I switch it (and maybe a couple of unlit candles) with the regular lantern, it would be floating with no visible means of support. I even tried putting an occlusion box around the candles, but apparently "occlusion" does not apply to light animations. Maybe I'll have to break down and install Blender and make my own "off" lantern. :(
User avatar
Rude Gurl
 
Posts: 3425
Joined: Wed Aug 08, 2007 9:17 am


Return to V - Skyrim