Solved First join in game of day ( daily bonus )

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

    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.

jomjonejame

Member
Jan 26, 2017
54
1
8
29
I want to system daily bonus

code_language.skript:
on join:
   if first join of day:
      send "you get reward"
 
... >_< Documentions can help you...

code_language.skript:
on join:
    if {TIme::%player%} is not set:
        set {Time::%player%} to true
        send "You got rewards of daily"

on script load: #IF YOU NEVER Reload the Script. Would it reset evertime at your Server restart (0PM?)
    delete {Time::*}

Else you need check time difference more than 24 hours
 
... >_< Documentions can help you...

code_language.skript:
on join:
    if {TIme::%player%} is not set:
        set {Time::%player%} to true
        send "You got rewards of daily"

on script load: #IF YOU NEVER Reload the Script. Would it reset evertime at your Server restart (0PM?)
    delete {Time::*}

Else you need check time difference more than 24 hours

It seems kind of odd to do it like that. I don't see a reason not to just check the time difference. Your code requires the server/script to restart/reload every 24 hours; at least it seems like it- or else {Time::*} would never get cleared.

This can be used if "daily" suggest every 24 hours:
code_language.skript:
on join:
    # if not set, set variable to yesterday
    if {dailyBonus::%player%} is not set:
        set {dailyBonus::%player%} to now
        subtract 1 day from {dailyBonus::%player%}
    # if it's been a day or more since the last reward was given
    if (difference between {dailyBonus::%player%} and now) >= 24 hours:
        # make sure to update variable
        set {dailyBonus::%player%} to now
        # then, we can do stuff
        send "You've earned your Daily Bonus!"

Else, if you define "daily" as being different days, but not necessarily being 24 hours apart, you can use this:
code_language.skript:
on join:
    # if not set, set variable to yesterday
    if {dailyBonus::%player%} is not set:
        set {dailyBonus::%player%} to now
        subtract 1 day from {dailyBonus::%player%}
    # if the day between now and the variable are different
    if (day of year from date now) is not (day of year from date {dailyBonus::%player%}):
        # make sure to update variable
        set {dailyBonus::%player%} to now
        # then, we can do stuff
        send "You've earned your Daily Bonus!"
Note: the day of year from date expression is from skUtilities
 
Last edited by a moderator:
It seems kind of odd to do it like that. I don't see a reason not to just check the time difference. Your code requires the server/script to restart/reload every 24 hours; at least it seems like it- or else {Time::*} would never get cleared.


My code should be works. Ever server most restart evertime at 0 pm, because of laggs reduce or some things, So its called every day will the varaibles reset. Why will it never get cleared? Of course.

With your code i can just tell. BRUH! A lot variables. Example i joined 1x on the server. and never joined. there is a useless variables there. and somewhen will it bigger and bigger and bigger...
 
My code should be works. Ever server most restart evertime at 0 pm, because of laggs reduce or some things, So its called every day will the varaibles reset. Why will it never get cleared? Of course.

With your code i can just tell. BRUH! A lot variables. Example i joined 1x on the server. and never joined. there is a useless variables there. and somewhen will it bigger and bigger and bigger...

Your code will definitely work; I am not debating that. But making it so the server needs to restart (or the script to reload) in order to reset all cooldowns seems dangerous (i.e. emergency server restarts, server crashes, accidental reloading).

If it's space efficiency you're worried about, it's possible to implement a garbage collector like this:
code_language.skript:
every 24 hours:
    loop {dailyBonus::*}:
        if (difference between loop-value and now) >= 24 hours:
            delete {dailyBonus::%loop-index%}
 
Thank you @Orendigo @ChisleLP

I'm use this script and Delete variables at 12 AM ,it work

... >_< Documentions can help you...

code_language.skript:
on join:
    if {TIme::%player%} is not set:
        set {Time::%player%} to true
        send "You got rewards of daily"

on script load: #IF YOU NEVER Reload the Script. Would it reset evertime at your Server restart (0PM?)
    delete {Time::*}

Else you need check time difference more than 24 hours
 
... >_< Documentions can help you...

code_language.skript:
on join:
    if {TIme::%player%} is not set:
        set {Time::%player%} to true
        send "You got rewards of daily"

on script load: #IF YOU NEVER Reload the Script. Would it reset evertime at your Server restart (0PM?)
    delete {Time::*}

Else you need check time difference more than 24 hours
If you're trying to cut down on variables theres much better ways to do it
 
Status
Not open for further replies.