Need help with 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!

duziy

Member
Nov 15, 2024
1
0
1
How do I make it so that when the set amount of players is not met, the cooldown doesnt take effect until the command is successfully executed when the right amount of players is met?

Here is the skirpt that I wrote

command giveall-lootbox:
cooldown: 30 minute
cooldown message: &cYou have to wait %remaining time% before using that again!
cooldown bypass: keyall.lootbox.bypass.cooldown
permission: keyall.lootbox
permission message: &cYou don't have permission to use that
trigger:
if size of all players >= 4:
execute console command "excellentcrates key giveall lootbox 1"
broadcast "&bEveryone has been given 1 lootbox key by &6%player%"
else:
message "&cThere need to be 4 players online to give a lootbox!"

command giveall-lootbox-2:
cooldown: 60 minute
cooldown message: &cYou have to wait %remaining time% before using that again!
cooldown bypass: keyall.lootbox2.bypass.cooldown
permission: keyall.lootbox2
permission message: &cYou don't have permission to use that
trigger:
if size of all players >= 4:
execute console command "excellentcrates key giveall lootbox 2"
broadcast "&bEveryone has been given 2 lootbox keys by &6%player%"
else:
message "&cThere need to be 4 players online to give lootboxes!"
 
Last edited:
How do I make it so that when the set amount of players is not met, the cooldown doesnt take effect until the command is successfully executed when the right amount of players is met?

Here is the skirpt that I wrote

command giveall-lootbox:
cooldown: 30 minute
cooldown message: &cYou have to wait %remaining time% before using that again!
cooldown bypass: keyall.lootbox.bypass.cooldown
permission: keyall.lootbox
permission message: &cYou don't have permission to use that
trigger:
if size of all players >= 4:
execute console command "excellentcrates key giveall lootbox 1"
broadcast "&bEveryone has been given 1 lootbox key by &6%player%"
else:
message "&cThere need to be 4 players online to give a lootbox!"

command giveall-lootbox-2:
cooldown: 60 minute
cooldown message: &cYou have to wait %remaining time% before using that again!
cooldown bypass: keyall.lootbox2.bypass.cooldown
permission: keyall.lootbox2
permission message: &cYou don't have permission to use that
trigger:
if size of all players >= 4:
execute console command "excellentcrates key giveall lootbox 2"
broadcast "&bEveryone has been given 2 lootbox keys by &6%player%"
else:
message "&cThere need to be 4 players online to give lootboxes!"

Alrighty... First off, put your code in a code block.

Screenshot 2024-11-15 213854.png


Next, you can use the cancel command cooldown expression, like so:

Code:
command /lootbox:
    cooldown: 10 seconds
    trigger:
        if size of all players < 2:
            cancel cooldown
            send "Not enough players!"
            stop
        execute console command "excellentcrates key giveall lootbox"

Also, what I would recommend doing is combining the code for both of these commands (because it's kinda useless having two if they do basically the same thing, especially when it's easy to combine them).

It's not that hard, you can just use an argument (example: command /lootbox <number> and then based off of the number, you can set how many keys to hand out.

For example:

Code:
command /diamonds [<number=1>]: # the "=1" part is setting a default amount if arg-1 was not set.
    trigger:
        loop all players:
            give player arg-1 of diamond
            set {_amount} to ""
            set {_amount} to "s" if arg-1 is not equal to 1
            broadcast "Each player has recieved %arg-1% diamond%{_amount}%!"
          
            # if arg-1 was two, would broadcast:
            # "Each player has recieved 2 diamonds!"
            # if arg-1 was not set, would broadcast:
            # "Each player has recieved 1 diamond!"

(Also, you can set the cooldown time using this expression.)

Let me know if you need any more help.
 
Last edited: