ID:162499
 
So how can I make these? Do i need to make object or mob with time proc running through or what?
Time? Well, you can always refer to the built-in variables such as world.timeofday :P

But if you have your own set defined time for when a day begins and when it ends, most likely than not, you would need an infinite loop sleep()ing for a certain amount of time than calling in whatever effect you want (ex: night overlay) and increasing whatever variable you want as well (ex: day++). This procedure should be called at world/New()
world/New()  //  Called when world starts up
LoadWorldVariables() // Calls a custom procedure to load saved global-related variables (such as day and year you would want to save)
spawn() TimeDaySystem() // To tell you the truth, I dunno if spawn() should be here >_> I usually spawn() off loops at the beginning <_<

world/Del() // When the game is shut down
SaveWorldVariables() // Would be a good idea to save the day and year that passed by.
..() // Without the parent procedure, the default action would not pass - which is needed to actually shutdown the server.\
You don't need ..() if there's no default action (usually mentioned in the DM Ref) or if you did not overwrite it elsewhere.


var // A few "global" variables
day = 1
year = 0
daytime = 1 // Boolean variable :) 1 = day, 0 = night in this example
proc/TimeDaySystem()
while(1) // Infinite Loop
sleep(20*600) // Define the time you want to pass before the day can change
daytime = !daytime // "Inverts" value. If it was 1 (day), it is now 0 (night) and vice-versa
if(daytime) // If the variable is true - read the link at the bottom - means it's daytime now... which means it's the next day!
if(++day >= 366) // day++ is like (day+=1) at once :) So if the added day is = or more than 366, a new year begins
day = 1 // It's a brand new day :)
++year // Increases year. Pre-increasement variables (++var) first returns the current value of var THEN adds 1 to the var. Post-increasement variables (var++) adds 1 to the var then returns the variable.
// For example: XX = 25
//Pre-increasement (++var)
// world << ++XX <-- 25 [announced to the world]
// world << XX <-- 26

//Post-increasement (var++)
// world << XX++ <-- 26
// world << XX <-- 26

For the age system, well... there are a few ways. You can increase the mobs age depending on how long they were logged in for (using world.time when they logged in and when they leave). An infinite loop should be used if you are looking if a certain time-point to pass if you want to change the icon, using sleep(). This procedure should be different than the day system (you don't want someone to get one year older when the year passes for a person logged on only for 5 minutes when the year takes 20 minutes, right?)
mob/Login() // Called when a client connects to a mob
..() // Calls the default action, such as placement in the world
TimeLoggedIn = world.time // world.time is the # of ticks the world was up for. You'll see why this is used soon.
spawn() AgeSystem()

mob/Logout() // Called when client leaves
TotalTimeLogged += world.time - TimeLoggedIn // Adds any remaining time before deletion of the mob.
del src

mob/proc/AgeSystem() // Know when to use usr! This is not the place. Read the link at the bottom.

var/TimeWait = TotalTimeLogged%(60*600) // 60*600 = 1 hour in 1/10 seconds (approx. 1 tick). % is NOT divide, it is modulus. Basically, the amount remaining...
// For example: 5%5 = 0 --> 5-5 = 0
// 10%2 = 0 --> 10-2 --> 8 - 2 --> ... --> 2-2 = 0
// 5%2 = 1 --> 5-2 --> 3-2 = 1 (it can not go negative)

// So, this will wait until the person has been logged in for 1 hour, to increase the age.

// Reason why this is OUTSIDE the loop is because we want TimeWait to be defined using TotalTimeLogged just once, since after that it'll be done exactly one hour.
while(1) // This lasts as long as the mob exists... when called.

if(!TimeWait) // If the modulus found the result is 0, meaning it has been exactly 1 hour
TimeWait = 60*600 // Time to wait another hour
age++ // Increase the age

sleep(TimeWait) // Waits for an hour, or however long it needs to be from the beginning to reach one hour play time.
// Here, the proc will loop back to under the while() after the necessary time passes by

Boolean info --> http://bwicki.byond.com/ByondBwicki.dmb?TrueFalse

What usr actually is --> http://bwicki.byond.com/ByondBwicki.dmb?WhatIsUsr
In response to GhostAnime
Thanks!
In response to GhostAnime
I hate nitpicking, but you should note that <code>if(day++ >= 366)</code> would start the new year when <code>day</code> is 367, since a post-incremention only increments after the original value is retrieved. You'd probably want that to be <code>++day</code> instead.
In response to DivineO'peanut
Ah, yes, you're correct. Heh, didn't notice that <_<
In response to GhostAnime
I get error that there are no SaveWorldVariables or LoadWorldVariables Procs,,,
In response to Syntty
That's because he's telling you to make them.
In response to Kaiochao2536
Oh :D

Edit: Would this work?

proc
SaveWorldVariables() // The proc that saves your character.
var/savefile/F = new("world.sav") // define the save file and create it
F["World"] << world // Outputs ALL of the character (var's, etc) into the list


But how can I make load proc?
In response to Syntty
Would this work?

No.

how can I make load proc?

Load what? The map? Player characters? The number of times cookies were baked in the last hour? For maps, take a look at hub://LummoxJR.SwapMaps. For saving characters, there is the excellent hub://Deadron.CharacterHandling.