• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

Eluna Extension: Cooldown Methods!

Foereaper

Founder
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:

Code:
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):

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

RegisterPlayerEvent(18, ChatTest)

3n29.png


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

Foereaper

Founder
Updated with optional argument for specific cooldown ID's, allowing multiple cooldowns per player, per script.
 
Top