ID:1868483
 
(See the best response by Pirion.)
Code:


Problem description:Hello coders out there i need a small help from you guys

i want to make a verb(event schedule) for player when they click it show them when a event was last held or at which time will the next event will start


Like: in my game if there is a tourney system and the tourney starts after every 45 min

i want to make a verb for players like when they use it it will show them when the tourney is with the game in time

eg :- when is the next event again - name of the event

Thank you any kind of help appreciated

Look into the "timeofday" var. Using some simple subtraction, you can figure this out easily enough :)

just world/var/time might work for you as well
In response to Braekyn
Braekyn wrote:
Look into the "timeofday" var. Using some simple subtraction, you can figure this out easily enough :)

just world/var/time might work for you as well

i have dealt with timeofday var but didnt get what you tryna say

srry wanted to say in this manner like the event is executed at 12:00 then next event 12:45 like it will show
time for next event when it will be held again
sorry i wrote time for next event to start
Best response
First, some definitions for time:
#define     DAY             (HOUR * 24)
#define HOUR (MINUTE * 60)
#define MINUTE (SECOND * 60)
#define SECOND (TICK * 10)
#define TICK 1

//and to simply our formatting

#define RIGHT(s,l) (copytext(s,length(s)-l+1,0))


Next Scheduling
Let us say we're creating a new datum to handle events. This datum will include the last time an event ran, and the next time an event will run.

var/EventManager/EventManager

world/New()
..()
EventManager = new()

EventManager
var
LastEvent = 0;
NextEvent = 0;


The first thing we need to do is setup the first run. This will be 45 * 60 * 10 ticks (Minutes/Seconds/Ticks) - using the defined values above, we can write this as '45 * MINUTE'

To determine when this will run, you will want to use world.time. This is because this value will never reset, unless the server has a restart. This will make sure that we don't have to handle logic between different days when checking the value.
EventManager

New()
//schedule 45 minutes from now
//45 'minutes'
ScheduleRun(45 * MINUTE)

proc/ScheduleRun(ticks)
//add to the server uptime to get the start time.
NextEvent = world.time + ticks


Now we have it scheduled, we'd want to be able to display this to our users. Simply enough, we'll get the delta from now, and add it to world.timeofday. This will show in server time, the time of the next run.

        //NextEvent - Current Server Time = duration...offset the timeofday and handle day looping
proc/NextEventTimeOfDay()
. = world.timeofday + (NextEvent - world.time)
. = . % DAY //remove anything over a day (resetting to 0)
//LastEvent - Current Server Time = duration...offset the timeofday and handle day looping
proc/LastEventTimeOfDay()
. = world.timeofday + (LastEvent - world.time)
. = . % DAY //remove anything over a day (resetting to 0)

//allow people to see them
mob/verb/ShowEventTimes()
world << "Last Event: "+time2text(EventManager.LastEventTimeOfDay(),"hh:mm:ss")
world << "Next Event: "+time2text(EventManager.NextEventTimeOfDay(),"hh:mm:ss")


Now, not all users are in the timezone, so we may want to show a duration too.

proc/FormatDuration(ticks)
var
hours = text("[]",round(ticks/HOUR)) //give us number of minutes
minutes = RIGHT("00"+text("[]",round(ticks/MINUTE) % 60),2) //create minutes, and pad to two zeros
seconds = RIGHT("00"+text("[]",round(ticks/SECOND) % 60),2)//create seconds, and pad to two zeros
return text("[]:[]:[]",hours,minutes,seconds)

EventManager
proc
NextEventRemaining()
return FormatDuration(NextEvent - world.time)


//allow people to see them
mob/verb/ShowEventTimes()
world << "Last Event: "+time2text(EventManager.LastEventTimeOfDay(),"hh:mm:ss")
world << "Next Event: "+time2text(EventManager.NextEventTimeOfDay(),"hh:mm:ss")
world << "Remaining: "+EventManager.NextEventRemaining()



That would allow you to display the information you're looking for.
Thank you buddy for help i saw your code did some changesto it and make it working

it was a good one i need another thing

can i make a proc spawn every hour at the same minute like

1:20 not it happens then 2:20 again it gets executed

i tried to do using world.timeofday and text2time but didnt work out making too much cpu damage
This would be the work of some sort of Event Scheduler.

Lucky that there are a few that have been released as libraries. http://www.byond.com/developer/Stephen001/EventScheduling
but I want the proc to be executed according to the time zone not by the uptime of the game
Fair enough, in order to do that - you'd want to create a custom scheduler that is based of from world.timeofday, converting to world.time.

The post here details how it would work with world.time.
http://www.byond.com/members/DreamMakers/ forum?id=729915&view=1&display=1#729877