ID:1669347
 
Keywords: time, timelimits
(See the best response by Eternal_Memories.)
So I want to make a long lasting time limit for my game, something like 4 hours. At 4 hours I want a proc to run that will 'encourage' players to finish up. But that's not important.

What's important is that I don't know how to do this, at least in a way that's not going to bog down the server with something that just runs for 4 hours. I'd also like for it to available to checking, that is, let players see how long it has left.
Otherwise I'd probably do something terrible like run a proc that just sleeps/spawns for 144000.

Any and all help is appreciated.
If you want players to see the timer, you will need a loop that continually updates the timer. This should not bog down the server at all since it is incredibly simple, and you only need to update the timer every second (I am assuming you don't need thousandths-place precision on a four hour game :D).
In response to Magicsofa
Best response
Magicsofa wrote:
If you want players to see the timer, you will need a loop that continually updates the timer. This should not bog down the server at all since it is incredibly simple, and you only need to update the timer every second (I am assuming you don't need thousandths-place precision on a four hour game :D).

Not really, you only need to store in a var the server's time and then compare it to the current one to see the difference. You don't really need to do all the updating stuff (plus that'd be ruined if it rebooted the Server)
That's true. However, to see the clock ticking away you would at least have to have it start an update loop when a player looks at it. If the update was resource intensive you would definitely want to only update when necessary. I just think in this case it would be much simpler to have a timer object that updates once per second.

The rebooting thing is not really relevant to either approach. No matter what path SodiumShine takes, they will have to save the elapsed time (as well as a lot of other stuff) in order to recover from a reboot successfully.
// Danger! Untested code.

// Route output through a proc so you can override if needed.
/proc/send_message(recipients, message)
recipients << message

// How many ticks to wait inbetween cycles? Every cycle the tasks are checked against the current time.
/var/const/TASK_POLL_TIME = 600

/var/list/tasks

/datum/task
var
nextrun = 0
proc
execute()

setNextRun()
src.nextrun = world.realtime + 9000 // default: 15 minutes

/proc/taskPoller()
while (1)
sleep (TASK_POLL_TIME)

if (tasks)
for (var/datum/task/task in tasks)
if (task.nextrun >= world.realtime)
task.setNextRun()

spawn task.execute()

/proc/addTask(var/datum/task/task)
if (!tasks) tasks = new/list()

tasks.Add(task)

/datum/task/cheerleader
execute()
// <satire>
send_message(world, "We would like to encourage everyone to keep playing...")

sleep(10)

var/ok = FALSE
for (var/client/C)
if (C.inactivity >= 3000)
ok = TRUE
send_message(world, "[C.key] has been kicked from the game.")
del C

if (ok) spawn(30) send_message(world, "See you in 4 hours time.")
// </satire>

setNextRun()
src.nextrun = world.realtime + 57600 // 4 hours

// Tip: Only define /world/New, /world/Del, /client/New, /client/Del, /mob/Login and /mob/Logout once in your project.
/world/New()
. = ..()

addTask(new /datum/task/cheerleader())