Time based enable/disable script

Post » Tue Aug 25, 2009 10:52 pm

I'm working on a house-mod, and it's almost finished.
I have placed a light to simulate daylight coming in through a door, and it looks really nice.

The problem is that the "daylight" will come in at all hours, even at midnight,
so I want to script it to enable/disable depending on time of day.
(Perhaps also with the previous cell's weather, like "Kirel's Interior Weather" does with sound.)
I'd like it to show up between sunrise and sunset, naturally.

I once experimented with something like this before, but I couldn't get it to work then...
I figured I should ask for help this time, heh heh...

Can someone here help me with this? I need a working script that can do this.
If someone can make a good script for me, I'll credit them in the readme.

Edit: I mentioned the "previous cell" because this house-mod is portable.
User avatar
Antony Holdsworth
 
Posts: 3387
Joined: Tue May 29, 2007 4:50 am

Post » Wed Aug 26, 2009 12:55 am

I made a similar script for scheduling NPCs in cases where I wanted to switch between one instance and another rather than moving them from cell to cell for various reasons. The scripting is really quite simple, and it's been working perfectly for me. I use a cell change because I don't want the npcs to vanish in front of the player if the script happens to hit the right hour, but if you're replacing a day window with a night window, a cell change is not really necessary. The change would be very sudden though if witnessed by the player. It would have to be tweaked to simulate a gradual change, and would get quite a bit more complicated, but this is the basic idea:

If ( GameHour < 6 )	EnableElseif ( GameHour < 20 )	DisableElse	EnableEndif


Then do the exact opposite for the other window.
User avatar
NeverStopThe
 
Posts: 3405
Joined: Tue Mar 27, 2007 11:25 pm

Post » Wed Aug 26, 2009 9:19 am

Ah... I see. Thank you! :celebration:

The last time I tried something like this, I was trying to make a "Daedric Shrine Offering" mod.
It would have made the daedric quest shrines require an offering like in oblivion.

I couldn't get the "gamehour" effects to work properly for Azura's statue.
I was going to make it give the quest only between dusk and dawn, but I couldn't make it work.
I was able to make the "offering" requirement itself work, but then the statue would automatically be set off,
whenever the player enters the cell containing the statue.

I couldn't fix it, so I had to scrap the project...

Anyway, thanks for the script. I'll use it in my mod. ^_^
User avatar
Brittany Abner
 
Posts: 3401
Joined: Wed Oct 24, 2007 10:48 pm

Post » Wed Aug 26, 2009 12:38 am

You can't use enable/disable on lights and have it work properly (or so I've heard). The usual way is to move them down a lot, below the cell.
Now, you can combine that with gamehour as a multiplier to have them fade quite nicely with no work on your part.

float tempPosSet tempPos To ( -500 + ( GameHour * ( 500 / 12 ) ) )"dayLight"->SetPos Z tempPos


It's rough and you'll probably want to play with the math, but the concept is at 0000 hours, the light will be 500 units below it's original position. At 1200 hours it will be level with the door, and at 2359 hours it will be above the door. Depending on the radius, you might want to use quadratics to get a better curve, but it should look better than the sharp on-off and runs just as well.
User avatar
Siobhan Thompson
 
Posts: 3443
Joined: Sun Nov 12, 2006 10:40 am

Post » Wed Aug 26, 2009 9:46 am

You can't use enable/disable on lights and have it work properly (or so I've heard).


My enable/disable script is working quite nicely, I've had no problems with it.
It does appear/disappear suddenly though...
I've been thinking of adding a second light that enables/disables slightly before/after it, to mask the effect.
User avatar
Monique Cameron
 
Posts: 3430
Joined: Fri Jun 23, 2006 6:30 am

Post » Tue Aug 25, 2009 8:35 pm

I've never had the problem with enabling/disabling lights myself. I have a few lights disabled in a tower construction script, and there's no residual glow while they're disabled. I don't know...maybe this is something that the code patch or MGE fixes? Because I've heard of that problem, but never actually encountered it.
User avatar
Shannon Lockwood
 
Posts: 3373
Joined: Wed Aug 08, 2007 12:38 pm

Post » Wed Aug 26, 2009 12:40 pm

I've never seen that happen either...
Anyway, the scripts are working perfectly. :D

A dimmer light enables at 6am, and disables at 8pm.
A brighter light enables at 9am, and disables at 6pm.

It looks really nice ingame, too. ;)
User avatar
Farrah Barry
 
Posts: 3523
Joined: Mon Dec 04, 2006 4:00 pm


Return to III - Morrowind