-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.lua
More file actions
85 lines (75 loc) · 1.97 KB
/
timer.lua
File metadata and controls
85 lines (75 loc) · 1.97 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
--------------------------------------------------------------------
-- Timer --
--------------------------------------------------------------------
--[[
Dependencies:
none
]]--
function SetupTimer()
timers = {}
StartSimpleJob("TimerJob");
end
function TimerJob()
for i = table.getn(timers), 1, -1 do
timers[i].startIn = timers[i].startIn - 1;
if timers[i].startIn == 0 then
local stopLoop = timers[i].func(timers[i].param) --funktion ausführen, gibt true/false zurück
if not stopLoop and timers[i].repeatTimes ~= 0 then
timers[i].repeatTimes = timers[i].repeatTimes - 1
timers[i].startIn = timers[i].loopTime --rücksetzen & neustarten
if timers[i].show then
MapLocal_StartCountDown(timers[i].loopTime)
end
else
if timers[i].show then
MapLocal_StopCountDown()
end
table.remove(timers, i)
end
end
end
end
function RegisterTimer(startIn, func, options)
options = options or {}
local ts = table.getn(timers)
local newTimer = {}
newTimer.func = func
newTimer.startIn = startIn
newTimer.repeatTimes = options.repeatTimes or 0
newTimer.param = options.param or 0
newTimer.show = false
if options.show then
newTimer.show = true
MapLocal_StartCountDown(startIn)
end
if newTimer.repeatTimes ~= 0 then
newTimer.loopTime = startIn
end
table.insert(timers, newTimer)
end
function UnregisterTimer(delFunc)
for i = table.getn(timers), 1, -1 do
if timers[i].func == delFunc then
if timers[i].show then
MapLocal_StopCountDown()
end
table.remove(timers, i)
return
end
end
end
function GetRemainingTime(func)
for i = table.getn(timers), 1, -1 do
if timers[i].func == func then
return timers[i].startIn
end
end
end
function SetRemainingTime(func, tim)
for i = table.getn(timers), 1, -1 do
if timers[i].func == func then
timers[i].startIn = tim
return
end
end
end