View Full Version : Eluna Extension: Cooldown Methods!

02-18-2014, 06:42 PM
Earlier today I figured I'd create an extension script to allow setting and getting a cooldown for all kinds of purposes in scripts! The two new methods are as follows:

player:SetLuaCooldown(seconds[, opt_id]) -- Sets the cooldown timer to X seconds, optionally a specific cooldown ID can be set. Default ID: 1

player:GetLuaCooldown([opt_id]) -- Returns cooldown or 0 if none, default cooldown checked is ID 1, unless other is specified.

By default, the methods use cooldown ID 1, unless another ID is specified within the method arguments.

Save the extension as a .lua file and place it in your lua script folder. IMPORTANT! Extensions should ALWAYS have a 0 as the first character in the script name! As the engine loads scripts alphanumerically, it will ensure the extension is loaded and present before other scripts may need it! I suggest using 0CooldownExtension.lua, so you know what the script is for! :)


I also created a small sample script to show how the cooldown methods work (screenshot below):

function ChatTest(event, plr, msg, type, lang)
if msg == "cooldown" then
if plr:GetLuaCooldown() == 0 then
plr:SendBroadcastMessage(string.format("No cooldown exists, setting cooldown to %s seconds", math.ceil(plr:GetLuaCooldown())))
plr:SendBroadcastMessage(string.format("Cooldown exists, %s seconds remaining", math.ceil(plr:GetLuaCooldown())))

RegisterPlayerEvent(18, ChatTest)


Thanks to Alex/Laurea for helping me out with this one :)

02-18-2014, 06:44 PM
woooohooooooo 1rst tnx :bump2:
nice job

02-18-2014, 06:46 PM
I would like to add that the cooldown is not a global cooldown.
Each script FILE has its own environment for the cooldown variable.

02-20-2014, 05:06 PM
Updated with optional argument for specific cooldown ID's, allowing multiple cooldowns per player, per script.