forked from mt-mods/missions
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cooldown.lua
35 lines (25 loc) · 801 Bytes
/
cooldown.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
local cooldown_timers = {} -- playername -> mission-name -> number(finish time)
-- resets the cooldown timer
missions.cooldown_reset = function(mission_name, playername)
local now = os.time(os.date("!*t"))
local mission_data = cooldown_timers[playername]
if not mission_data then
mission_data = {}
cooldown_timers[playername] = mission_data
end
mission_data[mission_name] = now
end
-- returns the seconds since the mission was finished or zero if never finished
missions.cooldown_get = function(mission_name, playername)
local now = os.time(os.date("!*t"))
local mission_data = cooldown_timers[playername]
if not mission_data then
return 0
end
local last_time = mission_data[mission_name]
if not last_time then
return 0
end
local diff = now - last_time
return diff
end