Trying to create a script that gives the player a reward every 24 hours

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

SirMario

Member
Dec 28, 2023
1
0
1
Hello, I'm having difficulty creating a script for my minecraft server. I want a script that gives players a reward every 24 hours if they log on that day. So basically a daily reward for anyone that logs in that day and it has a 24 hour cooldown after they've received the reward.

This is the code I made with help of chatgpt:

Code:
on first join:
    set {lastreward.%uuid of player%} to now - 24 hours

on join:
    if {lastreward.%uuid of player%} is not set:
        set {lastreward.%uuid of player%} to now - 24 hours
  
every minute:
    loop all players:
        if difference between now and {lastreward.%uuid of player%} is greater than 24 hours:
            set {lastreward.%uuid of player%} to now
            execute console command "addbalance %player% Shards 1"
            send "&a&lThank you for playing United Factions today! 1 Shard has been added to your balance" to p
        else:
            set {_timeLeft} to 24 hours - (difference between now and {lastreward.%uuid of player%})
            send "&eYou need to wait %{_timeLeft}% more hours to reclaim your next daily reward" to p

However, when I reload this skript, I get multiple errors in my console:

Code:
[17:12:48 INFO]: Line 2: (dailyreward.sk)
[17:12:48 INFO]:     Can't understand this expression: 'now - 24 hours'
[17:12:48 INFO]:     Line: set {lastreward.%uuid of player%} to now - 24 hours
[17:12:48 INFO]:
[17:12:48 INFO]: Line 6: (dailyreward.sk)
[17:12:48 INFO]:     Can't understand this expression: 'now - 24 hours'
[17:12:48 INFO]:     Line: set {lastreward.%uuid of player%} to now - 24 hours
[17:12:48 INFO]:
[17:12:48 INFO]: Line 11: (dailyreward.sk)
[17:12:48 INFO]:     There's no player in a periodical event
[17:12:48 INFO]:     Line: if difference between now and {lastreward.%uuid of player%} is greater than 24 hours:
[17:12:48 INFO]:
[17:12:48 INFO]: Line 15: (dailyreward.sk)
[17:12:48 INFO]:     'else' has to be placed just after another 'if' or 'else if' section
[17:12:48 INFO]:     Line: else:
[17:12:48 INFO]:
[17:12:48 INFO]: [Skript] Encountered 5 errors while reloading the config, aliases and all scripts! (4293ms)

It seems to be having difficulty with the substraction of now - 24 hours. I don't understand how mathematical operations work within skript. I'm new to coding using skript and I have difficulty finding documentation of these kinds of things. If someone can direct me to good documentation for basic operations like this one I would be very gratefull!
 
Hello, I'm having difficulty creating a script for my minecraft server. I want a script that gives players a reward every 24 hours if they log on that day. So basically a daily reward for anyone that logs in that day and it has a 24 hour cooldown after they've received the reward.

This is the code I made with help of chatgpt:

Code:
on first join:
    set {lastreward.%uuid of player%} to now - 24 hours

on join:
    if {lastreward.%uuid of player%} is not set:
        set {lastreward.%uuid of player%} to now - 24 hours
 
every minute:
    loop all players:
        if difference between now and {lastreward.%uuid of player%} is greater than 24 hours:
            set {lastreward.%uuid of player%} to now
            execute console command "addbalance %player% Shards 1"
            send "&a&lThank you for playing United Factions today! 1 Shard has been added to your balance" to p
        else:
            set {_timeLeft} to 24 hours - (difference between now and {lastreward.%uuid of player%})
            send "&eYou need to wait %{_timeLeft}% more hours to reclaim your next daily reward" to p

However, when I reload this skript, I get multiple errors in my console:

Code:
[17:12:48 INFO]: Line 2: (dailyreward.sk)
[17:12:48 INFO]:     Can't understand this expression: 'now - 24 hours'
[17:12:48 INFO]:     Line: set {lastreward.%uuid of player%} to now - 24 hours
[17:12:48 INFO]:
[17:12:48 INFO]: Line 6: (dailyreward.sk)
[17:12:48 INFO]:     Can't understand this expression: 'now - 24 hours'
[17:12:48 INFO]:     Line: set {lastreward.%uuid of player%} to now - 24 hours
[17:12:48 INFO]:
[17:12:48 INFO]: Line 11: (dailyreward.sk)
[17:12:48 INFO]:     There's no player in a periodical event
[17:12:48 INFO]:     Line: if difference between now and {lastreward.%uuid of player%} is greater than 24 hours:
[17:12:48 INFO]:
[17:12:48 INFO]: Line 15: (dailyreward.sk)
[17:12:48 INFO]:     'else' has to be placed just after another 'if' or 'else if' section
[17:12:48 INFO]:     Line: else:
[17:12:48 INFO]:
[17:12:48 INFO]: [Skript] Encountered 5 errors while reloading the config, aliases and all scripts! (4293ms)

It seems to be having difficulty with the substraction of now - 24 hours. I don't understand how mathematical operations work within skript. I'm new to coding using skript and I have difficulty finding documentation of these kinds of things. If someone can direct me to good documentation for basic operations like this one I would be very gratefull!
There's a command option that exists out there that lets you save data in the way you'd want. It's called 'cooldown storage'. It lets you save values for a command for a certain amount of time. You can simply use that option in a command, have the player run the command the instance they join then boom, you should have what you're looking for. Also read the Docs if this sounds confusing, there's lots more info there than I could cover here.