Author Topic: [Resource] daycycles.cs - functions for daycycles and the sun  (Read 5317 times)

I wrote a quick little support script which provides a set of functions generally related to the daycycle and the sun.
daycycles.cs (106 raw LOC)



float getDayCycleTime()

Returns the current progress of the daycycle as a floating point value between 0 and 1 while properly accounting for daycycle length and offset. The start of a cycle (0) is the point where the sun sets (elevation at 0 degrees).

int getDayCycleStage(float time)

Using time as the progress of the cycle, returns the "stage" of the daycycle as an integer, which can be either 0, 1, 2 or 3. This represents each quarter of the cycle (dawn, day, dusk and night).

str getDayCycleStageName(int stage)

Returns a friendly name for the stage. 0 => dawn, 1 => day, 2 => dusk, 3 => night.

int getMSToNextDayCycleStage(float time)

Using time as the progress of the cycle, returns the precise total number of milliseconds until the next quarter of the cycle is reached as an integer.

str getDayCycleTimeString(float time[, bool mod12])

Formats the cycle progress time as a friendly string. For example, given 0.65, it returns "15:36". If mod12 is true, the time is formatted using 12 hour time - instead of "15:36", "3:36 PM" is returned.

Vector3F getSunVector()

Returns an unit vector pointing directly to the sun's current elevation and azimuth. Works both with the daycycle enabled and disabled.

bool isPointInShadow(Vector3F pos[, SimObject avoid])

Returns whether or not an object is casting a shadow on the position pos.

void syncDayCycle()

Assuming the daycycle is enabled and the daycycle length is 86400, adjusts the daycycle offset so that the in-game daycycle is synced with the host's timezone.




Yes, all functions in this are pinpoint accurate and do not crash servers like Lugnut's.
« Last Edit: September 06, 2013, 02:02:21 AM by Port »

this...
oh god this is so loving amazing
 :iceCream:

Mine does not crash servers. It used to crash servers. There have been no reports pmed or otherwise of it loving crashing servers.

forget, my script uses the same logic yours does except it takes up more lines for step by step and each step is commented for learning.

That means jack all though, no one's made any mods that work with this concept.

Mine does not crash servers. It used to crash servers. There have been no reports pmed or otherwise of it loving crashing servers.

forget, my script uses the same logic yours does except it takes up more lines for step by step and each step is commented for learning.

That means jack all though, no one's made any mods that work with this concept.
Lugnut, seriously, why are you so mad all of a sudden?
You can always work on your daycycle script and make it better than port's.

Lugnut, seriously, why are you so mad all of a sudden?
You can always work on your daycycle script and make it better than port's.
sorry, i was a little pissy this morning. i think it hit my ego or something, my bad

Does this mean we get cool events?
I thought Lugnut's were broken but it sounds like he fixed it.
« Last Edit: September 05, 2013, 03:21:35 PM by TristanLuigi »

The Event_DayCycles mod doesn't work for a select few people with unreproducible errors.

Wait, how did I miss this? Did I literally just spend all of today reproducing this resource ;_;
EDIT: Oh, nvm :P, scared me for a second
« Last Edit: September 07, 2013, 04:52:23 PM by DYLANzzz »

Holy stuff, this works like a charm.
dayyum.

they would be ints and floats if they could actually make it to 2 billion....

they would be ints and floats if they could actually make it to 2 billion....

Integer values and floating point values do not necessarily define a byte length - they're just types of numbers.

Integer values and floating point values do not necessarily define a byte length - they're just types of numbers.
i guess

This isn't really related to the script but it is related to daycycle. Is it possible to change when the sun rises and when it sets. Also what does the Day Time Offset slider do when you set the day cycle?

Also what does the Day Time Offset slider do when you set the day cycle?

It just offsets the current point in the daycycle.

It just offsets the current point in the daycycle.

Thanks, I was really confused by it. I thought that was what it did but I wasn't 100% sure.


Still I was wondering if it's possible to make it so you could change when the sun rised and set. So you can make the day longer.