Solved Creating a cooldown command system

  • 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!

Status
Not open for further replies.

JackyBoy

Member
Feb 4, 2017
104
1
18
Hey there! I have been creating my custom classes skript yet I need a cooldown time so players are unable to spam the command, is there a way I can do this?
 
Skript itself has a cooldown example when you run it. Here is it if you have deleted it:
code_language.skript:
#
# This script is a template for commands which have a cooldown.
# I will add a more intuitive way of handling cooldowns/countdowns in the future,
# But for now please use something like this.
# Make sure that you do not use delays for cooldowns as they stop when the server stops.
#

# This command allows each player to get infinite cakes
# but the command has a cooldown of one minute (per player)
command /cake:
    description: Recieve a cake, but you can only do this once per minute!
    permission: cake.is_a_lie
    executable by: players
    trigger:
        # stores how long it's been since the player last used this command
        set {_waited} to difference between {cake.%player%.lastused} and now
        # checks whether the player has used the command within the last minute
        if {_waited} is less than a minute:
            message "You have to wait %difference between a minute and {_waited}% before you can use this command again!"
            stop
       
        # some condition which sould not start the cooldown
        # (if the player doesn't get the cake he should be able to use the command again immediately)
        player doesn't have space for a cake:
            message "You do not have enough space in your inventory to hold the cake!"
            stop
           
        # do the action of the command
        give a cake to the player
       
        # and finally start the cooldown
        set {cake.%player%.lastused} to now
 
Status
Not open for further replies.