| Blockland Forums > Modification Help |
| Manipulating time of day and telling time? |
| (1/1) |
| rggbnnnnn:
I'm making a game mode that relies heavily on telling you the time of day, and moving the sun accordingly. Past 10pm is nighttime, and after 6am is daytime. I also need to be able to tell what time of day it is to the player. What functions can I use to do this? I remember it being a pain for a friend I know. |
| Rally:
What I have here is basically spaghetti code, somebody else should probably take a look and tell me what I did wrong. It's probably patched together from multiple places (i worked on the same concept for a gamemode) This should return you a number pertaining to the time of day (0 is ~6AM, 500 is ~6PM I guess, 1000 is ~6AM of the next day) --- Code: ---function getDayTime() { %time = $Sim::Time / DayCycle.dayLength + DayCycle.dayOffset; $DayTime = (%time - mFloor(%time)) *1000; return $DayTime; } --- End code --- This is a method I used to convert that number into a string like "6:00 AM". This might only work for 300 second days but I'm not sure. 24 hour clock is probably less complicated --- Code: ---function getClock() { // 41.6666666667 = 1 hour %hours = (getDayTime() + 249) / 41.5; %remainder = %hours - mFloor(%hours); %seconds = (%remainder * 60); // convert hours to 12 hour clock if(%hours > 12) { %noonString = "PM"; %hours = %hours - 12; if(%hours > 12) { %noonString = "AM"; %hours = %hours - 12; } } else { %noonString = "AM"; } %hourOfDay = mFloor(%hours); if(%hourOfDay == 0) { %hourOfDay = 12; } %secondOfHour = mFloor(%seconds); if(%secondOfHour < 10) { %secondOfHour = "0" @ %secondOfHour; } %time = %hourOfDay @ ":" @ %secondOfHour SPC %noonString; return %time; } --- End code --- This function just sets the time to 6AM and enables/resets the daycycle --- Code: ---function serverCmdAdvanceDay(%client) { if(!%client.isAdmin) return; serverCmdEnvGui_SetVar(%client,"DayCycleEnabled",1); serverCmdEnvGui_SetVar(%client, DayLength, $DayLength); serverCmdEnvGui_SetVar(%client, DayOffset, 1); %time = getDayTime() / 1000; serverCmdEnvGui_SetVar(%client, DayOffset, 1 - %time); } --- End code --- |
| Conan:
useful default function you can use: getTimeString(seconds) returns a minute:second time representation of the vaue |
| rggbnnnnn:
Alright, thanks. That should be enough. Locking. |
| Navigation |
| Message Index |