Cooldowns

Cooldowns in Skript

So, suppose you wanted to make a stick, that when you right click it, shoots a fire ball. You want a 2 second cooldown though. Well, you're in luck. The code shown below will allow you to do that.

on right click with a stick:
    start cooldown "ST-%player%" for 5 seconds
    shoot a fireball from player

Well, there's an issue with the code above. That only starts the cooldown, it would not check if a cooldown with that name is going on. So, what we want to do, is check if a cooldown with that name is going on.

on right click with a stick:
    if cooldown "ST-%player%" exists:
        send "&cSorry, a cooldown is going on!"
    else:
        start cooldown "ST-%player%" for 5 seconds
        shoot a fireball from player

So, that works just fine. Now, how do we see how long until the cooldown ends? Well, you can use this:

time until cooldown "ST-%player%" expires

That will show us how long until that cooldown expires. So, what now? Lets improve the code above to tell us how long until the cooldown expires.

on right click with a stick:
    if cooldown "ST-%player%" exists:
        set {_this} to time until cooldown "ST-%player%" expires
        send "&cPlease wait %{_this}% seconds."
    else:
        start cooldown "ST-%player%" for 5 seconds
        shoot a fireball from player

Also, if you wanted to, you could just forcefully end the cooldown. SimpleSK allows you to do that. So, lets make code where if the player has the permission "cooldown.skip", it ends the cooldown for them.

on right click with a stick:
    if cooldown "ST-%player%" exists:
        if player has permission "cooldown.skip":
            force end cooldown "ST-%player%"
        else:
            set {_this} to time until cooldown "ST-%player%" expires
            send "&cPlease wait %{_this}% seconds."
    else:
        start cooldown "ST-%player%" for 5 seconds
        shoot a fireball from player

Perfect. Now, there's one last thing we didn't discuss. You can now see ALL of the cooldowns for the whole server. How? Well, lets make a command for it.

command /cooldowns:
    permission: cooldowns.list
    trigger:
        #Code here

All we need now, is one line. You can use all active cooldowns to see all of the current cooldowns the server is in.

command /cooldowns:
    permission: cooldowns.list
    trigger:
        message "&6Server Cooldowns: &c%all active cooldowns%"

Then, it looks like we're done! Play around with this features yourself, now!

Last updated

Was this helpful?