Solved Cooldowns

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

golddi

Member
Oct 8, 2023
3
0
1
I know the basics of skript but I cant figure out how to do cooldowns for ability's

options:
locked: black dye named "&8&lʟᴏᴄᴋᴇᴅ &7sᴜᴍᴍᴏɴᴇʀ" with lore "&8&lᴊᴀɪʟ ᴛɪᴍᴇ", "", "&e&lʀɪɢʜᴛ ᴄʟɪᴄᴋ ᴛᴏ sᴡɪᴛᴄʜ ᴛʜᴇ sᴇʟᴇᴄᴛᴇᴅ ᴀʙɪʟɪᴛʏ", "&a&lʟᴇғᴛ ᴄʟɪᴄᴋ ᴛᴏ ᴀᴄᴛɪᴠᴀᴛᴇ ᴛʜᴇ sᴇʟᴇᴄᴛᴇᴅ ᴀʙɪʟɪᴛʏ", "", "&7ᴀʙɪʟɪᴛɪᴇs:", "&8&lᴄᴀᴘᴛɪᴠɪᴛʏ &7( ᴄᴏᴏʟᴅᴏᴡɴ: 3:30ᴍ )", "&8&o>> ᴜᴘᴏɴ ᴀᴄᴛɪᴠᴀᴛɪᴏɴ ᴡʜᴀᴛᴇᴠᴇʀ ᴘʟᴀʏᴇʀ ʏᴏᴜ ʜɪᴛ ɢᴇᴛs ʟᴏᴄᴋᴇᴅ ɪɴ ᴘʟᴀᴄᴇ ғᴏʀ 10 sᴇᴄᴏɴᴅs", "&8&lsǫᴜᴀᴅ ᴇʟɪᴍ &7( ᴄᴏᴏʟᴅᴏᴡɴ: 4:30ᴍ )", "&8&o>> ᴜᴘᴏɴ ᴀᴄᴛɪᴠᴀᴛɪᴏɴ ʟᴏᴄᴋs ᴇᴠᴇʀʏ ɴᴏɴ-ᴛʀᴜsᴛᴇᴅ ᴘʟᴀʏᴇʀ ɪɴ ᴀ 5 ʙʟᴏᴄᴋ ʀᴀᴅɪᴜs ᴏғ ʏᴏᴜ ғᴏʀ 10 sᴇᴄᴏɴᴅs"

on right click:
if player's held item is {@locked}:
set {_lockedCooldown1} to 210
set {_lockedCooldown2} to 270
set {_lockedSelectedAbility} to {ᴄᴀᴘᴛɪᴠɪᴛʏ: :%player%}
set {_lockedSelectedAbility} to {sǫᴜᴀᴅ ᴇʟɪᴍ: :%player%}
if {_lockedSelectedAbility} is {ᴄᴀᴘᴛɪᴠɪᴛʏ: :%player%}:
if {_lockedCooldown1} is 0:
send action bar "&8ᴄᴀᴘᴛɪᴠɪᴛʏ ( &aʀᴇᴀᴅʏ &8)"
else if {_lockedCooldown1} > 0:
send action bar "&8ᴄᴀᴘᴛɪᴠɪᴛʏ ( &4%_lockedCooldown1% &8)"
if {_lockedSelectedAbility} is {sǫᴜᴀᴅ ᴇʟɪᴍ: :%player%}:
if {_lockedCooldown2} is 0:
send action bar "&8sǫᴜᴀᴅ ᴇʟɪᴍ ( &aʀᴇᴀᴅʏ &8)"
else if {_lockedCooldown2} > 0:
send action bar "&8sǫᴜᴀᴅ ᴇʟɪᴍ ( &4%_lockedCooldown2% &8)"
 
Hello i would like to help you but its very hard to understand your code, mind putting it into code blocks?
 
Hello i would like to help you but its very hard to understand your code, mind putting it into code blocks?
basically what it does is it registers {@locked} as black dye with a set name and lore, and then I tried making it so when you right click with the {@locked} in your hand it switches from showing the first ability to the second, and if you do it again it switches back, also I made it so it shows "ʀᴇᴀᴅʏ" when the ability cooldown reaches 0
 
Hello,
next time you can try writing some pseudo code / a minimalistic and super simple version of the code.

Now to your problem, you can try making your own cooldown manager using unix.
Here is an example:

AppleScript:
# Utils
function getUnix() :: number:
    return unix timestamp of now

# Cooldown manager
function COOLDOWN_ADD_COOLDOWN(id: string, time: number):
    set {COOLDOWNS::%{_id}%} to getUnix() + {_time}

function COOLDOWN_GET_COOLDOWN(id: string) :: number:
    set {_cd} to {COOLDOWNS::%{_id}%}
    if {_cd} is set:
        return {_cd} - getUnix()

function COOLDOWN_IS_COOLDOWN_ACTIVE(id: string) :: boolean:
    set {_cooldown} to COOLDOWN_GET_COOLDOWN({_id})
    if {_cooldown} is set:
        if {_cooldown} > 0:
            return true
    return false

# Usage
on unload:
    clear {COOLDOWNS::*}

command /cooldown_test [<string>]:
    trigger:
        set {_cooldownId} to "my_cooldown"
        set {_isCooldownActive} to COOLDOWN_IS_COOLDOWN_ACTIVE({_cooldownId})
        if {_isCooldownActive} = true:
            set {_cooldown} to COOLDOWN_GET_COOLDOWN({_cooldownId})
            send "&cThe command is currently on cooldown (%{_cooldown}%s)"
        else:
            COOLDOWN_ADD_COOLDOWN({_cooldownId}, 5)
            send "&aAdded cooldown of 5s!"