Making a custom light litunlit based on daytime

Post » Tue Jun 19, 2012 9:41 pm

Hello,
I'm a new player about CK, but I know what I want.

I've made a mod that add lanterns near bridges. These lanterns use a custom new light with ID: "lightLanternSkyrim"

Now I'm trying to make lit lanterns only from 6:00 to 18:00.
I don't know how to retrieve current clock time and I don't know how to modify light on/off.

There is my "ideal" script here

Function mainLanterns()					     RegisterForUpdateGameTime(1)endFunctionEvent OnUpdateGameTime()  if currentTime>=6 && currentTime<=18	TurnOFFLightByID  else	TurnONLightByID  endIfendEvent


Of course, currentTime, TurnOFFLightByID and TurnONLightByID are not the real script stuff.
What I've to do to get clock time and toggle lighting?

Thank you!
User avatar
Enny Labinjo
 
Posts: 3480
Joined: Tue Aug 01, 2006 3:04 pm

Post » Tue Jun 19, 2012 7:26 pm

Don't know off the top of my head but there are global variables in the Object window under Miscellaneous -> http://www.creationkit.com/Global. One of those is GameHour. Use the http://www.creationkit.com/GlobalVariable_Script script object to get the hour. Use http://www.creationkit.com/Enable_-_ObjectReference/disable to turn the light on and off.

I haven't done any scripting with Papyrus yet, but that should get you started. I'm sure someone else will come along with a complete script in an hour or two. :smile:
User avatar
Lucky Girl
 
Posts: 3486
Joined: Wed Jun 06, 2007 4:14 pm

Post » Tue Jun 19, 2012 4:52 pm

http://skyrim.nexusmods.com/downloads/file.php?id=10361

Might check this guy's work out. Will probably save you some time.
User avatar
Miragel Ginza
 
Posts: 3502
Joined: Thu Dec 21, 2006 6:19 am

Post » Tue Jun 19, 2012 4:36 pm

Just because I wrote this recently for a request and still have it, here's an example of a script that should work for what you want:
Spoiler
What you'd want to do for this is place a marker reference, and set it to be the http://www.creationkit.com/Reference#Enable_Parent of all of your lights. Then, on that marker, you'll want to attach a script that looks something like this:
ScriptName StreetLightTimer extends ObjectReference{Controls a set of lights with a master enable parent markerto turn on and off at the times of the day specified by theproperties LightsOffTime and LightsOnTime}ObjectReference EnableMarker auto{The marker set as the enable parent of all the lights}float Property LightsOffTime = 7.0 auto{The time at which lights should be turned off}float Property LightsOnTime = 18.0 auto{The time at which lights should be turned on}float Function GetCurrentHourOfDay() {Returns the current time of day in hours since midnight}	float Time = Utility.GetCurrentGameTime()	Time -= Math.Floor(Time) ; Remove "previous in-game days passed" bit	Time *= 24 ; Convert from fraction of a day to number of hours	Return TimeEndFunctionFunction RegisterForSingleUpdateGameTimeAt(float GameTime){Registers for a single UpdateGameTime event at the next occurrenceof the specified GameTime (in hours since midnight)}	float CurrentTime = GetCurrentHourOfDay()	If (GameTime < CurrentTime)		GameTime += 24	EndIf	RegisterForSingleUpdateGameTime(GameTime - CurrentTime)EndFunctionEvent OnInit()	If (GetCurrentHourOfDay() > LightsOffTime)		GoToState("LightsOff")	Else		GoToState("LightsOn")	EndIfEndEventState LightsOff	Event OnBeginState()		EnableMarker.Disable		RegisterForSingleUpdateGameTimeAt(LightsOnTime)	EndEvent	Event OnUpdateGameTime()		GoToState("LightsOn")	EndEventEndStateState LightsOn	Event OnBeginState()		EnableMarker.Enable()		RegisterForSingleUpdateGameTimeAt(LightsOffTime)	EndEvent	Event OnUpdateGameTime()		GoToState("LightsOff")	EndEventEndState

I hope that's useful.

Cipscis
User avatar
Rach B
 
Posts: 3419
Joined: Thu Mar 08, 2007 11:30 am

Post » Tue Jun 19, 2012 1:23 pm

Thanks, Cipscis.

Question: Can you not just call GetValue on the global GameHour instead of implementing the GetCurrentHourOfDay function? Or am I misunderstanding what the global represents (or making another noob error)? (I haven't really tried writing a script yet, that's just from perusing the wiki.)
User avatar
Jonathan Windmon
 
Posts: 3410
Joined: Wed Oct 10, 2007 12:23 pm

Post » Tue Jun 19, 2012 9:41 pm

Question: Can you not just call GetValue on the global GameHour

It should work fine (Gamehour is a 24 hour clock). If you want minutes as well you will need to convert the decimal component (ie ... 0.5 = 30 minutes).
User avatar
Mr. Ray
 
Posts: 3459
Joined: Sun Jul 29, 2007 8:08 am

Post » Tue Jun 19, 2012 9:15 pm

Just because I wrote this recently for a request and still have it, here's an example of a script that should work for what you want

I just c/p this into the CK and compiled it and got the following error:
Starting 1 compile threads for 1 files...Compiling "StreetLightTimer"...c:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\StreetLightTimer.psc(6,29): required (...)+ loop did not match anything at input 'auto'c:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\StreetLightTimer.psc(6,33): mismatched input '\\r\\n' expecting STATENo output generated for StreetLightTimer, compilation failed.Batch compile of 1 files finished. 0 succeeded, 1 failed.Failed on StreetLightTimer
So, um...since I'm a huge noob at Papyrus...what did I do wrong. :biggrin:
User avatar
CArla HOlbert
 
Posts: 3342
Joined: Wed Feb 21, 2007 11:35 pm

Post » Tue Jun 19, 2012 6:50 pm

Sounds like I've got a syntax error in there somewhere. I didn't try to compile it when I wrote it, as I didn't have access to the compiler at the time.

Ah, I found it. A simple error, of course - I missed out the "Property" keyword in a property declaration:
ObjectReference Property EnableMarker auto
Hopefully that's the only syntax error in there.

Cipscis
User avatar
Amy Cooper
 
Posts: 3400
Joined: Thu Feb 01, 2007 2:38 am

Post » Tue Jun 19, 2012 3:18 pm

And it's
EnableMarker.Disable()

you forget something :P
User avatar
Heather Kush
 
Posts: 3456
Joined: Tue Jun 05, 2007 10:05 pm

Post » Tue Jun 19, 2012 6:50 pm

Yeah, just got both of those. For some reason I didn't think of checking the wiki for a list of common errors. Sheesh.
User avatar
Shannon Marie Jones
 
Posts: 3391
Joined: Sun Nov 12, 2006 3:19 pm

Post » Tue Jun 19, 2012 2:28 pm

And it's
EnableMarker.Disable()
you forget something :P
There we go :)
Thanks Planteur.

Cipscis
User avatar
Juliet
 
Posts: 3440
Joined: Fri Jun 23, 2006 12:49 pm

Post » Tue Jun 19, 2012 2:26 pm

Just hooked it up and tested it in-game. Works like a charm. :)

Thanks, Cipscis. I think this deserves a spot on the wiki under solutions.

Now, to figure out how to get an NPC to light it instead of it just popping on. I think there's an idle in there somewhere...
User avatar
Nikki Hype
 
Posts: 3429
Joined: Mon Jan 01, 2007 12:38 pm

Post » Tue Jun 19, 2012 9:16 pm

Just hooked it up and tested it in-game. Works like a charm. :)
Awesome!

Thanks, Cipscis. I think this deserves a spot on the wiki under solutions.
You're right, that would be a great place for it. When I have a bit of time tonight I'll put it there on the wiki with instructions, and then go through it line by line as an example script for people to learn from.

Cipscis
User avatar
Killer McCracken
 
Posts: 3456
Joined: Wed Feb 14, 2007 9:57 pm

Post » Tue Jun 19, 2012 1:26 pm

Is there any reason why, when setting the properties, the CK wouldn't let me select the xmarker in the reference window by double-clicking it? I had to manually set it from the drop down box. Just curious if there was a reason for this.
User avatar
Yonah
 
Posts: 3462
Joined: Thu Aug 02, 2007 4:42 am

Post » Tue Jun 19, 2012 11:14 am

Is there any reason why, when setting the properties, the CK wouldn't let me select the xmarker in the reference window by double-clicking it? I had to manually set it from the drop down box. Just curious if there was a reason for this.

Because you try to select the marker with the script attached, you have to create another marker as the enable parent, because you can't make cycling reference in papyrus. By the way, the script can't work if the enable parent of the lights is itself, once disabled it can't do anything.
User avatar
Gill Mackin
 
Posts: 3384
Joined: Sat Dec 16, 2006 9:58 pm

Post » Wed Jun 20, 2012 12:02 am

Just put a page up on the Creation Kit Wiki, if anyone's interested. I also included a variation that I expect should work as a manual light switch.

http://www.creationkit.com/Light_Switch

Cipscis
User avatar
Robert Jr
 
Posts: 3447
Joined: Fri Nov 23, 2007 7:49 pm

Post » Tue Jun 19, 2012 3:51 pm

Hello,
my apologies for not responding! I've forgotten this thread because I've created the same at the nexus forum.

Regards
User avatar
Chase McAbee
 
Posts: 3315
Joined: Sat Sep 08, 2007 5:59 am


Return to V - Skyrim