Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Real Life Timer
Author Message
ShiryuX
Journeyman
*

Posts: 249
Likes Given: 1
Likes Received: 16 in 14 posts
Joined: Mar 2010
Reputation: 4



Post: #1
Real Life Timer
Hi,
I didn't find an exact title for this, but anyway, this is a timer that is synced with your real life clock, it fires once per hour and you can configure specific functions for each day at a specific hour. Pretty simple actually. The clock will start automatically when the server is launched, you don't have to do anything, if anything happens (it gets deleted or something), a check is made at every world save. And last, if it gets out of sync, at each @Timer it will get synced again for the next hour. Every event is logged.

Special thanks for the guys (Soulless and Xun) in Discord who gave me the idea to use rTime functions.
Which I didn't know it existed Lol

NOTES:
It will only work on o'clock timers. You can fire it at 16.00 but not at 16.15.
Functions are fired on SERV, not on the object or anything else.
Days start a 0 = Sunday, 1 = Monday and so on...
Defname is provided with examples.
YOU NEED TO CONFIGURE YOUR TIME ZONE CORRECTLY!


Example defname:
Code:
[DEFNAME dWorldClockFunctions]
WorldClock_0_20        "f_AutomatedPVP" // Will fire on sunday at 20hs
WorldClock_5_16        "f_AutomatedCTF" // Will fire on friday at 16hs

Item for timer:
Code:
[ITEMDEF i_WorldClock]
ID=i_gravestone_4
TYPE=t_normal

ON=@Create
attr = attr_move_never|attr_decay

ON=@Timer
serv.log @WorldClock: Timer triggered at <serv.rtime.format %T>
local.ToCall = _<serv.rtime.format %w>_<serv.rtime.format %H>
if !<isempty <def.WorldClock<local.ToCall>>>
    serv.<def.WorldClock<local.ToCall>>
    serv.log @WorldClock: Called function <def.WorldClock<local.ToCall>>.
endif
local.WaitToNext = <eval 60 - <serv.rtime.format %M>>
timer = <eval (<local.WaitToNext> * 60) - <serv.rtime.format %S>>
serv.log @WorldClock: Next timer in <eval <timer>/60>:<eval <timer>%60>
return 1


Look for f_onserver_save function in your default script pack.
Or add it if you don't have one.
Add the following code:
Code:
if (<uid.<var0.WorldClock>> == 0)
    serv.log @WorldClock: TIMER WAS REMOVED! Created new timer.
    newitem i_WorldClock
    new.p = 11,11
    local.WaitToNext = <eval 60 - <serv.rtime.format %M>>
    new.timer = <eval (<local.WaitToNext> * 60) - <serv.rtime.format %S>>
    new.sector.flags = 01
    var.WorldClock = <new.uid>
    serv.log @WorldClock: Synced at <serv.rtime.format %T> will trigger in <eval <new.timer> / 60>:<eval <new.timer> % 60> minutes.
endif


Look for f_onserver_start function. Same as before.
Add the following code:
Code:
if ((<var0.WorldClock> == 0) || (<uid.<var0.WorldClock>> == 0))
    serv.log @WorldClock: Created new timer.
    newitem i_WorldClock
    new.p = 11,11
    local.WaitToNext = <eval 60 - <serv.rtime.format %M>>
    new.timer = <eval (<local.WaitToNext> * 60) - <serv.rtime.format %S>>
    new.sector.flags = 01
    var.WorldClock = <new.uid>
    serv.log @WorldClock: Synced at <serv.rtime.format %T> will trigger in <eval <new.timer> / 60>:<eval <new.timer> % 60> minutes.
else
    local.WaitToNext = <eval 60 - <serv.rtime.format %M>>
    uid.<var.WorldClock>.timer = <eval (<local.WaitToNext> * 60) - <serv.rtime.format %S>>
    serv.log @WorldClock: Synced at <serv.rtime.format %T> will trigger in <eval <uid.<var.WorldClock>.timer> /60>:<eval <uid.<var.WorldClock>.timer> % 60> minutes.
endif
(This post was last modified: 04-04-2020 07:37 AM by ShiryuX.)
04-04-2020 05:08 AM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes ShiryuX's post
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

This forum uses Lukasz Tkacz MyBB addons.