Author Topic: How do i detect midnight in a daycycle? SOLVED  (Read 754 times)

It seems to me like whenever i start a day-cycle the time it starts at is random, and not midnight like where the script starts the cycle, how can i detect when midnight is so i can trigger my time scripts?
« Last Edit: June 21, 2015, 05:09:47 AM by zombekillz »

You just changed the content of your topic, but to reply to the old question (setSkyBox without affecting some environment variables):
Use this as a reference for creating your own function for changing it without affecting that: https://gist.github.com/portify/74c81da52f1f64f36713



This is because the current time of the daycycle is based on the current time and DayCycle.dayOffset.
You may find this helpful for figuring out how the timing of the daycycle works: https://github.com/portify/bl-utils/blob/master/dayCycles.cs
« Last Edit: June 21, 2015, 03:46:20 AM by portify »

thats awsome, i found a workaround for that a bit ago, but i think ill remake it your way instead :)



as for detecting midnight i actually just figured that out myself by modifying code from lugnut's daycycle events, it dosent find midnight, but it will find 6am, which works for me
heres what i came up with:
Code: [Select]
function getDayCycleTime() //Returns the time in seconds from dawn from the current time
{
%curTime = $Sim::Time; // the day cycle is tied directly to the simTime of the server.
%length = $WeatherMod_Daylength; // this is how long in seconds the day will last. for example, 24 is a full 24 hour day in the space of 24 seconds.
%offset = DayCycle.dayOffset; // this is how much offset is applied to the day.
%offset = mfloor(%offset * %length); // this calculates how many seconds the offset actually affects, as the offset is defined in a range between 0 and 1.

if(%offset != 0)
%curTime = (%curTime + %offset) - %length; // this adds the offset into the equation.

%final = mFloor(%curTime % %length); // this determines the remainder of simTime divided by length, which is how far, in seconds, we are into the day.

if(%final < 0) //if the result is a negative, we need to subtract it from the total. this allows compatibility with offsets.
%final = %length - %final;

return %final;
}

function GetMidNight() // Find Midnight and schedule the Weathermod Time scripts.
{
%tod = getDayCycleTime(); // establish a starting point
%len = $WeatherMod_Daylength; // establish length of days

%seconds = %len - %tod;
%Miliseconds = %seconds * 1000;
$Sched_WeatherMod_Time = schedule(%Miliseconds,0,Time_6AM);
echo(%Miliseconds);
}
« Last Edit: June 21, 2015, 05:08:07 AM by zombekillz »