HELLO guys, how could i launch a random event every hours on my server based on the server time?
[B]Untested. Hopefully the comments give you an idea of what it is supposed to do.[/B]
[lua]
// Calculate how many minutes left in the hour.
function calculateMinutes()
local minutes = 60 - tonumber( os.date("%M") );
return minutes;
end
function startEvent()
// Do whatever you want here.
timer.Simple( calculateMinutes() * 60, startEvent );
end
[/lua]
thank you, will test it
Unpractical when server crashes, needs static saving (files/sql).
Do you want it ON the hour or every hour in general? If you want it on the hour then you could probably come up with a solution that works between server crashes, otherwise you would have to save the information somehow.
Now if you want to do it on the hour then you will have to figure out a good way to test if there is a "new hour". Possibly just a timer.simple which runs once a minute to see if the hour changed. This won't be right on the hour but it will be within a minute of the hour changing. I assume even doing it every second wouldn't be that bad, although I'd avoid every tick.
You could use schedules, but that would do it on the physical server time..
Initalise hook, next event = tonumber( file.Read( "nextevent.txt" ) )
file.Write( "nextevent.txt" ) and you can check with that, don't use zack's stupid method.
Zack's methode is infact not stupid, the only problem is that the schedule module doesn't work.
Sorry, you need to Log In to post a reply to this thread.