Solved Calculating time

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

michal12sk

New Member
Feb 5, 2017
5
0
0
Hello, I'm trying to calculate how much time until a player can vote again. I have a variable which uses the %now% to set the time of voting. Since one voting site has 2 hours between votes I need to subtract 2 hours from the time difference between the real-time and time of voting. But I can't get it to work. This works:
code_language.skript:
subtract 2 hours from {_time}
But this doesn't work:
code_language.skript:
subtract {_time} from 2 hours

I also tried to set it to variables and subtracting it that way but it just doesn't work. Any help will be appreciated.
 
create a variable canVote (yes/no)
On command /vote
Set canVote to no
Wait 24 hours
Set canVote to yes

It is easy
 
create a variable canVote (yes/no)
On command /vote
Set canVote to no
Wait 24 hours
Set canVote to yes

It is easy
Yea that would work, but I'm not asking for that, I'm asking, How to calculate the time until player can vote again
 
create a variable canVote (yes/no)
On command /vote
Set canVote to no
Wait 24 hours
Set canVote to yes

It is easy

Don't use something like this; if the server restarts any time within this period, the player will never be allowed to vote again. Also, this will create a new process for this every time someone votes that wouldn't end until a day later, which is just unnecessary.

The way I always do cooldowns is to set your player's wait var to now. Then check if the "difference between now and {waitvar.%player%}%" is greater than 2 hours. If it is, more than 2 hours have passed since they last voted. You only need to update the variable when they successfully vote and restart the cooldown.
 
Don't use something like this; if the server restarts any time within this period, the player will never be allowed to vote again. Also, this will create a new process for this every time someone votes that wouldn't end until a day later, which is just unnecessary.

The way I always do cooldowns is to set your player's wait var to now. Then check if the "difference between now and {waitvar.%player%}%" is greater than 2 hours. If it is, more than 2 hours have passed since they last voted. You only need to update the variable when they successfully vote and restart the cooldown.
That's exactly how I have it. The Question is how can I calculate the time until a player can vote again. So I need to calculate 2 hours - difference between {lastvoted} and now. But I don't know how
 
That's exactly how I have it. The Question is how can I calculate the time until a player can vote again. So I need to calculate 2 hours - difference between {lastvoted} and now. But I don't know how
exactly what you said:

code_language.skript:
# somewhere in your script you may set a variable like this:
set {vote::cooldown::%player's uuid%} to now

# Then, to get the difference
set {_difference} to difference between {vote::cooldown::%player's uuid%} and now
# And to get the remaining time
set {_remaining-time} to difference between {_difference} and 24 hours
 
exactly what you said:

code_language.skript:
# somewhere in your script you may set a variable like this:
set {vote::cooldown::%player's uuid%} to now

# Then, to get the difference
set {_difference} to difference between {vote::cooldown::%player's uuid%} and now
# And to get the remaining time
set {_remaining-time} to difference between {_difference} and 24 hours
Thank you. I didn't actually think of that.
 
Status
Not open for further replies.