-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathObjectCooldownExtension.lua
41 lines (34 loc) · 1.07 KB
/
ObjectCooldownExtension.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
local cooldowns = {};
function Player:SetLuaCooldown(seconds, opt_id)
assert(type(self) == "userdata");
seconds = assert(tonumber(seconds));
opt_id = opt_id or 1;
local guid, source = self:GetGUIDLow(), debug.getinfo(2, 'S').short_src;
if (not cooldowns[guid]) then
cooldowns[guid] = { [source] = {}; };
end
cooldowns[guid][source][opt_id] = os.clock() + seconds;
end
function Player:GetLuaCooldown(opt_id)
assert(type(self) == "userdata");
local guid, source = self:GetGUIDLow(), debug.getinfo(2, 'S').short_src;
opt_id = opt_id or 1;
if (not cooldowns[guid]) then
cooldowns[guid] = { [source] = {}; };
end
local cd = cooldowns[guid][source][opt_id];
if (not cd or cd < os.clock()) then
cooldowns[guid][source][opt_id] = 0
return 0;
else
return cooldowns[guid][source][opt_id] - os.clock();
end
end
--[[ Example:
if(player:GetLuaCooldown() == 0) then -- Check if cooldown is present
player:SetLuaCooldown(30)
print("Cooldown is set to 30 seconds")
else
print("There are still "..player:GetLuaCooldown().." seconds remaining of your cooldown!")
end
]]