Jump to content

Need help with a light script.


Deleted31005User

Recommended Posts

This is regarding my mod Tel Nalta II.

 

I'm trying to add a light script that would make light sources disable at day and enable at night, an example of that can be found here:

http://www.creationkit.com/Light_Switch

 

Now my issue is that this kind of script can not work for my mod because literally everything already has en "enable parent", the player needs to build the entire town from nothing and attaching the script from the link above will simply not work and throw error floodings in the script log files:

"error: cannot disable an object with an enable state parent."

 

So, can someone please assist me with a script that could work with a light source that already has en "enable parent" on it, I have very little experience with scripting myself but could it be possible to set the light radius or the light intensity to 0 during the day instead of trying to disable the light source itself?

 

Please help, I'd really appreciate it.

Thanks.

Link to comment
Share on other sites

I can probably come up with something, but can't look at it for the next few of days though as I've already got someone else project I'm trying to get done.

 

I'd imagine you'll need to change some things.

Instead of the original lights enabling by parent.

Disconnect the lights from the parent and have the lights initially disabled.

 

 

Then all your lights get handled by the light script event of of day and night.

The light script would have a property for the disconnected parent.

The light script checks the now disconnected parent and if enabled then fire the light state for day or night.

If the disconnected parent is disabled then lights stay disabled and the day night event never fires.

 

Other option would be use linked ref chain and disable by the ref as required.

 

There is no way of disabling or enabling a child of a parent, so basically there aren't that many options.

Link to comment
Share on other sites

The first option you mention makes sense, I can definitely wait for you.

 

And if this works for the lights then maybe I can also use the script for other things, I always wanted to have some clutter (like food) appear at certain hours of the day or have my apiaries respawn in a certain time, but I never got to do any of those things because they are all parent enabled, so scripts never worked on them.

 

If I don't hear from you within a week I'll probably start buggering you though a PM :yes:

Edited by Guest
Link to comment
Share on other sites

That parent that currently enables your lights when built, does it have a parent that enables it?

 

EG: You build whatever at the bench, does the parent of the lights get enabled by another parent?

 

Or are there other item apart from lights attached to the parent.

Edited by sLoPpYdOtBiGhOlE
Link to comment
Share on other sites

A bit tricky.

The light sources themselves are attached to a parent, and that parent has no other parent.

But most other objects are attached to a parent that does have another parent.

And yes, sometimes the parent that enables the light source also enables other items, or other parents.

 

Its quite a big system with the core parents enabling light sources/items/other parents, but all exterior light sources are attached to those core parents and I only want that day/night cycle on the exterior light sources anyway.

 

http://static-2.nexusmods.com/15/images/110/31005-1446788250.jpg

 

Either way, even if an object is attached to one of those "other parents" it can easily be re-attached to its core parent as well, it would not make any difference.

Edited by Guest
Link to comment
Share on other sites

My messenger is disabled, I get to many unsolicited messages and I find it distracting when I'm working on things.
I end up with to many mid way through projects otherwise.
Well I should say it contributes to my to many mid way through projects, as can't just blame the messenger...lol
Be on it soon, just wrapping up a small project of my own (BTV = Be Trainer Vendor).

I have Tel_Nalta_v207, so I'll take a peek soon as i can free up some space to work on it.
Then i can post some basic script to handle it.
Is based of the original light script, just a small modification to make it work in your use.
I've already modded the script, I just need to test it see if it'll suit your situation.
It also uses another tiny script, so the original parent can still enable the child parent to the lights..

Edited by sLoPpYdOtBiGhOlE
Link to comment
Share on other sites

AC3S, Copy past exactly this (do not erage anithing):

 

 

ScriptName TimedLightSwitch extends ObjectReference

{Controls a set of lights with a master enable parent marker with this

script attached to turn on and off at the times of the day specified

by the properties LightsOffTime and LightsOnTime}

 

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() global

{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 Time

 

EndFunction

 

Function RegisterForSingleUpdateGameTimeAt(float GameTime)

{Registers for a single UpdateGameTime event at the next occurrence

of the specified GameTime (in hours since midnight)}

 

float CurrentTime = GetCurrentHourOfDay()

If (GameTime < CurrentTime)

GameTime += 24

EndIf

 

RegisterForSingleUpdateGameTime(GameTime - CurrentTime)

 

EndFunction

 

Event OnInit()

 

If (GetCurrentHourOfDay() > LightsOffTime)

GoToState("LightsOff")

Else

GoToState("LightsOn")

EndIf

 

EndEvent

 

State LightsOff

 

Event OnBeginState()

Disable()

RegisterForSingleUpdateGameTimeAt(LightsOnTime)

EndEvent

 

Event OnUpdateGameTime()

GoToState("LightsOn")

EndEvent

 

EndState

 

State LightsOn

 

Event OnBeginState()

Enable()

RegisterForSingleUpdateGameTimeAt(LightsOffTime)

EndEvent

 

Event OnUpdateGameTime()

GoToState("LightsOff")

EndEvent

 

EndState

Link to comment
Share on other sites

  • Recently Browsing   0 members

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