-
Notifications
You must be signed in to change notification settings - Fork 9
Home
swkeep edited this page Jul 2, 2022
·
2 revisions
Welcome to the keep-cooldown wiki!
a brief tutorial on how to use the script:
- there are two types of cooldown. temporary or persistent.
- temporary cooldowns are only available during runtime.
- persistent cooldowns their state will be saved to the database and loaded back after the server started.
local CD = exports["keep-cooldown"]:CD()
- you can specify a predefined id. if you don't define the id script will return a random Id.
- cooldownLength is required and determines the length of the cooldown. CD.setOnCooldown(ID) will set timer to this value.
- cType can be either 'temporary' or 'persistent'.
local cd_id =
CD.add(
{
id = "cooldown_1",
cooldownLength = 30,
cType = "temporary"
}
)
- you can check cooldown state and remaining by calling CD.isOnCooldown(ID).
- it will return state and remaining time but if there is an error it will return nil, nil.
local state, remaining = CD.isOnCooldown(cd_id)
if state then
print("Still on cooldown remaining: " .. remaining)
return
end
- it will return true after successful execution and return false if the id was invalid or the function failed.
CD.setOnCooldown(cd_id)
- it will return true after successful execution and return false if the id was invalid or the function failed.
CD.remove(cd_id)
- cooldown usage counts how many times CD.setOnCooldown() called for a cooldown.
- doing this will set cooldown usage to 0.
CD.resetCooldownUsage(id)
- countActiveCooldowns() is only available serve-side.
CD.countActiveCooldowns()
- there are two events that are triggered by changes in the state of cooldowns.
- keep-cooldown:server:cooldownStateChange and keep-cooldown:client:cooldownStateChange
- the first arg is state and the second one is Id of cooldown
-- client-side-event
RegisterNetEvent('keep-cooldown:client:cooldownStateChange', function(CD, ID)
print(CD, ID)
end)
-- server-side-event
AddEventHandler('keep-cooldown:server:cooldownStateChange', function(CD, ID)
print(CD, ID)
end)
- client-side
local CD = exports["keep-cooldown"]:CD()
local cd_id =
CD.add(
{
id = "keep_blackmarket_payphone" .. PlayerPedId(),
cooldownLength = 30,
cType = "temporary" -- or persistent
}
)
local state, remaining = CD.isOnCooldown(cd_id)
if state then
print("on CD " .. remaining)
return
end
if not state then
CD.setOnCooldown(cd_id)
end
- server-side
local CD = exports["keep-cooldown"]:CD()
local cd_id =
CD.add(
{
id = "keep_blackmarket_payphone_2",
cooldownLength = 30,
cType = "persistent" -- or persistent
}
)
local state, remaining = CD.isOnCooldown(cd_id)
print(state, remaining)
if state then
print("on CD " .. remaining)
return
end
if not state then
CD.setOnCooldown(cd_id)
end
state, remaining = CD.isOnCooldown(cd_id)
print(state, remaining)