forked from Refuge89/AzerothCore_Lua_compilation
-
Notifications
You must be signed in to change notification settings - Fork 2
/
World Message Broadcaster.lua
61 lines (52 loc) · 1.61 KB
/
World Message Broadcaster.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
local Broadcast = {
Register = {
-- {"String", day, time}
-- 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
{"Type your Message here", 0, 1800},
}
}
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 Broadcast.SendAndReset(msg, d, t)
SendWorldMessage(msg)
if(d > 0) then
local regtime = GetTimeDiff(d, SeparateTime(t))
CreateLuaEvent(function() Broadcast.SendAndReset(msg, d, t) end, regtime*1000, 1)
end
end
function Broadcast.OnLoad()
for i, v in ipairs(Broadcast.Register) do
local msg, d, t = table.unpack(Broadcast.Register[i])
if d == 0 then
CreateLuaEvent(function() Broadcast.SendAndReset(msg, d, t) end, t*1000, 0)
else
local regtime = GetTimeDiff(d, SeparateTime(t))
CreateLuaEvent(function() Broadcast.SendAndReset(msg, d, t) end, regtime*1000, 1)
end
end
end
Broadcast.OnLoad()