How would I get around doing this?

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

LoneElf

Active Member
Apr 30, 2017
165
2
18
So, I am making an hourly reward type of thing for my donators, and I have it set to every second in "world", it removes 1 second from the timer variable. The problem is, when the player is offline, it stops removing the 1 second from the variable which is the uuid of the player's timer. I really need it to keep removing 1 second from that variable because then the player can go offline while knowing that in an hour, his reward will be ready. Thanks, and here is my code:
code_language.skript:
on right click on anvil:
        cancel event
        if player does not have the permission "knight.hourly.reward":
                message "&7Error&8> &7This reward is only available to the &8Knight &7rank!"
        else:
                if {hourly.reward.%uuid of player%} is greater than "0 seconds" parsed as a timespan:
                        open chest with 3 rows named "&e&lHOURLY REWARD" to player
                        wait 1 tick
                        format slot 13 of player with a 322:1 named "&c&lHOURLY REWARD" with lore "&7Reward Delay: 1 hour||&7Time Left: %{hourly.reward.%uuid of player%}%" to close then run [message "&7Error&8> &7You must wait a total of %{hourly.reward.%uuid of player%}% more until you can receive the hourly reward again!"]
                else:
                        open chest with 3 rows named "&e&lHOURLY REWARD" to player
                        wait 1 tick
                        format slot 13 of player with a 322:1 named "&e&lHOURLY REWARD" with lore "&7Click to receive your hourly reward!" to close then run [give player 1 322:1 named "&e&lHOURLY REWARD"]->[message "&7Reward&8> &7You have been given your hourly reward!"]->[make console execute command "hourlyrewardactivite %player%"]

command hourlyrewardactivite <player>:
    trigger:
        set {hourly.reward.%uuid of arg 1%} to "1 hour" parsed as a timespan

every second in "world":
        set {1} to "1 second" parsed as a timespan
        loop all players:
                if {hourly.reward.%uuid of loop-player%} is greater than "0 seconds" parsed as a timespan:
                        remove {1} from {hourly.reward.%uuid of loop-player%}

EDIT: Just a note that the timer stops when the player is off of the bungee server, for example, KitPvP, so if I do /hub, it will still stop. The player doesn't have to be off of the whole server for the timer on KitPvP to stop, but just the KitPvP server.
 
Last edited:
This is not how to create cooldowns. You should store the time when the player last claimed their reward and compare that time to the current time. An example can be found in the example script command with cooldown.sk (which should have been created when you first installed Skript, but I'll post it here as well):
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 should 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.