Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local EventEnforcer = {
- Register = {
- -- {event, day, time, startstate, description}
- -- Day is from 1 to 7, where Monday is 1 and Sunday is 7
- -- Time is either seconds if day is 0 or format hour.minutes if day is specified
- -- startstate is true to start the event, false to stop
- {15, 7, 14.00, true, "Stranglethorn Fishing Pools - Start"},
- {15, 7, 16.00, false, "Stranglethorn Fishing Pools - Stop"},
- {62, 7, 14.00, true, "Stranglethorn Fishing Turn In - Start"},
- {62, 7, 16.00, false, "Stranglethorn Fishing Turn In - Stop"},
- }
- }
- local function SeparateTime(t)
- local h = math.floor(t)
- local m = ((t*1000)-(h*1000))/10
- return h, m;
- end
- local function GetTimeDiff(weekday, h, m, s)
- local d = os.date("*t")
- d.sec = s or 0
- d.min = m
- d.hour = h
- local ddiff = weekday-d.wday+1
- d.day = d.day+ddiff
- local now = os.date("*t")
- if (ddiff < 0) then
- -- Take into consideration that it is tuesday and we want monday
- d.day = d.day+7
- elseif (ddiff == 0 and d.hour*60*60+d.min*60+d.sec < now.hour*60*60+now.min*60+now.sec) then
- -- Take into consideration that it is the same date, but its already past the wanted time
- d.day = d.day+7
- end
- -- get final times
- local e = os.time(d)
- local diff = e-os.time() -- this is the time in seconds until the wanted date is achieved
- return diff;
- end
- function EventEnforcer.HandleEvent(evt, d, t, state)
- if state and not IsGameEventActive(evt) then
- StartGameEvent(evt)
- elseif not state and IsGameEventActive(evt) then
- StopGameEvent(evt)
- end
- if(d > 0) then
- local regtime = GetTimeDiff(d, SeparateTime(t))
- CreateLuaEvent(function() EventEnforcer.HandleEvent(evt, d, t, state) end, regtime*1000, 1)
- end
- end
- function EventEnforcer.OnLoad()
- for i, v in ipairs(EventEnforcer.Register) do
- local evt, d, t, state = table.unpack(EventEnforcer.Register[i])
- if d == 0 then
- CreateLuaEvent(function() EventEnforcer.HandleEvent(evt, d, t, state) end, t*1000, 0)
- else
- local regtime = GetTimeDiff(d, SeparateTime(t))
- CreateLuaEvent(function() EventEnforcer.HandleEvent(evt, d, t, state) end, regtime*1000, 1)
- end
- end
- end
- EventEnforcer.OnLoad()
Advertisement
Add Comment
Please, Sign In to add comment