Solved how to set the cooldown to clicked sign

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

NameKun

Member
Mar 3, 2020
11
0
1
19
hi, I'm creating an Athletic Server and using skript.
I wanted to create the sign that has the cooldown after it sent message to player.
However it does not work, it means the function of the cooldown was ignored.
So could you tell me how to make it work correctly,please.

------BELOW IS THE CODE------

on rightclick:
block is a sign
world is "xxx"
line 1 of clicked block is "&e-|-&6&lGoal&e-|-"
line 2 of clicked block is "&2[RightClick]"
line 3 of clicked block is "&8%world%"
line 4 of clicked block is "&9===Athletic==="
set {point.%player%.%world%} to location of clicked block
set {_waittime} to difference between {lasttime.%player%} and now
if {_waittime} is less than a minute:
message "You have to wait %difference between a minute and {_waittime}% sec."
else:
broadcast "&a%player% cleared xxx!!"
set {lasttime.%player%} to now
 
Stick. To. The format.

FOOLISH MORTAL, YOU DARE CHALLENGE ME?!
Very unhelpful :eyes:
hi, I'm creating an Athletic Server and using skript.
I wanted to create the sign that has the cooldown after it sent message to player.
However it does not work, it means the function of the cooldown was ignored.
So could you tell me how to make it work correctly,please.

------BELOW IS THE CODE------

on rightclick:
block is a sign
world is "xxx"
line 1 of clicked block is "&e-|-&6&lGoal&e-|-"
line 2 of clicked block is "&2[RightClick]"
line 3 of clicked block is "&8%world%"
line 4 of clicked block is "&9===Athletic==="
set {point.%player%.%world%} to location of clicked block
set {_waittime} to difference between {lasttime.%player%} and now
if {_waittime} is less than a minute:
message "You have to wait %difference between a minute and {_waittime}% sec."
else:
broadcast "&a%player% cleared xxx!!"
set {lasttime.%player%} to now
Usually what I would do is make the player execute a command on click of the sign, like this:
Code:
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&6&lGoal&e-|-"
    line 2 of clicked block is "&2[RightClick]"
    line 3 of clicked block is "&8%world%"
    line 4 of clicked block is "&9===Athletic==="
    execute player command "cooldownsign"

command cooldownsign:
    cooldown: 0.01 hours
    trigger:
        broadcast "&a%player% cleared xxx!!"
 
Thank you, Goose!!
It worked correctly thanks to you!!

And I have an another question.
Could you answer it?
(sorry for my bad English...)
 
Sure, hit me up.
Thanks.
I wanna make the another function like time-measurement.
So I referred to this page: https://forums.skunity.com/threads/stopwatch.3282/
And I tried to rewrite, but it did not work well.
upload_2020-3-4_12-2-18.png

Like this, if I clicked finish-sign after start-sign, it said "<none>"

If there are points to fix, please tell me.

-----BELOW IS THE CODE-----

Code:
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&2ToStart&e-|-"
    reset {_diff}
    set {timer.%player%} to true
    set {_start} to now
    while {timer.%player%} is true:
        set {_diff} to difference between now and {_start}
        wait 1 second
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&6&lGoal&e-|-"
    set {timer.%player%} to false
    message "Time: %{_diff}%"
 
Thanks.
I wanna make the another function like time-measurement.
So I referred to this page: https://forums.skunity.com/threads/stopwatch.3282/
And I tried to rewrite, but it did not work well.
View attachment 4313
Like this, if I clicked finish-sign after start-sign, it said "<none>"

If there are points to fix, please tell me.

-----BELOW IS THE CODE-----

Code:
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&2ToStart&e-|-"
    reset {_diff}
    set {timer.%player%} to true
    set {_start} to now
    while {timer.%player%} is true:
        set {_diff} to difference between now and {_start}
        wait 1 second
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&6&lGoal&e-|-"
    set {timer.%player%} to false
    message "Time: %{_diff}%"
Local variables can only be used one time (Local = One trigger)
[doublepost=1583314471,1583314394][/doublepost]
code_language.skript:
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&2ToStart&e-|-"
    reset {diff::%uuid of player%}
    set {timer.%player%} to true
    set {_start} to now
    while {timer.%player%} is true:
        set {diff::%uuid of player%} to difference between now and {_start}
        wait 1 second
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&6&lGoal&e-|-"
    set {timer.%player%} to false
    message "Time: %{diff::%uuid of player%}%"
 
Local variables can only be used one time (Local = One trigger)
[doublepost=1583314471,1583314394][/doublepost]
code_language.skript:
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&2ToStart&e-|-"
    reset {diff::%uuid of player%}
    set {timer.%player%} to true
    set {_start} to now
    while {timer.%player%} is true:
        set {diff::%uuid of player%} to difference between now and {_start}
        wait 1 second
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&6&lGoal&e-|-"
    set {timer.%player%} to false
    message "Time: %{diff::%uuid of player%}%"

Thanks, novastosha.
Actually, I have an another quesiton about time-measurement.
I'm sorry to bother again and again.

I want to save the biggest value.

For example,
First run: 20seconds
Second run: 22seconds

In this case, I do not want it to be overwrite the first-run's record.
In the opposite case about value, I do not want it to be overwrite the second-run's record.

Could you tell me how to make the function to compare between previous-record and next-record?

(I am so sorry not to communicate well.)
 
Thanks, novastosha.
Actually, I have an another quesiton about time-measurement.
I'm sorry to bother again and again.

I want to save the biggest value.

For example,
First run: 20seconds
Second run: 22seconds

In this case, I do not want it to be overwrite the first-run's record.
In the opposite case about value, I do not want it to be overwrite the second-run's record.

Could you tell me how to make the function to compare between previous-record and next-record?

(I am so sorry not to communicate well.)
Ok, i'll do it for ya
[doublepost=1583333223,1583333001][/doublepost]Is that what ya mean?

code_language.skript:
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&2ToStart&e-|-"
    reset {diff::%uuid of player%}
    set {timer.%player%} to true
    set {_start} to now
    while {timer.%player%} is true:
        set {_ok} to {runnedsometime::%uuid of player%} * 2
        set {diff::%uuid of player%} to difference between now and {_start} + {_ok}
        wait 1 second
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&6&lGoal&e-|-"
    set {timer.%player%} to false
    add 1 to {runnedsometime::%uuid of player%}
    message "Time: %{diff::%uuid of player%}%"
on join:
    if {runnedsometime::%uuid of player%} is not set:
        set {runnedsometime::%uuid of player%} to 1
[doublepost=1583333444][/doublepost]
Ok, i'll do it for ya
[doublepost=1583333223,1583333001][/doublepost]Is that what ya mean?

code_language.skript:
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&2ToStart&e-|-"
    reset {diff::%uuid of player%}
    set {timer.%player%} to true
    set {_start} to now
    while {timer.%player%} is true:
        set {_ok} to {runnedsometime::%uuid of player%} * 2
        set {diff::%uuid of player%} to difference between now and {_start} + {_ok}
        wait 1 second
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&6&lGoal&e-|-"
    set {timer.%player%} to false
    add 1 to {runnedsometime::%uuid of player%}
    message "Time: %{diff::%uuid of player%}%"
on join:
    if {runnedsometime::%uuid of player%} is not set:
        set {runnedsometime::%uuid of player%} to 1
If its worng, try to explain
 
Thanks.
I wanna make the another function like time-measurement.
So I referred to this page: https://forums.skunity.com/threads/stopwatch.3282/
And I tried to rewrite, but it did not work well.
View attachment 4313
Like this, if I clicked finish-sign after start-sign, it said "<none>"

If there are points to fix, please tell me.

-----BELOW IS THE CODE-----

Code:
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&2ToStart&e-|-"
    reset {_diff}
    set {timer.%player%} to true
    set {_start} to now
    while {timer.%player%} is true:
        set {_diff} to difference between now and {_start}
        wait 1 second
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&6&lGoal&e-|-"
    set {timer.%player%} to false
    message "Time: %{_diff}%"
{_diff} is a local variable. Local variables get deleted after a trigger ends, so you gotta use {diff::%player%}. (You can delete the {diff::%player%} later)
 
Thank you, Goose and novastosha.

Ok, i'll do it for ya
[doublepost=1583333223,1583333001][/doublepost]Is that what ya mean?

code_language.skript:
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&2ToStart&e-|-"
    reset {diff::%uuid of player%}
    set {timer.%player%} to true
    set {_start} to now
    while {timer.%player%} is true:
        set {_ok} to {runnedsometime::%uuid of player%} * 2
        set {diff::%uuid of player%} to difference between now and {_start} + {_ok}
        wait 1 second
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&6&lGoal&e-|-"
    set {timer.%player%} to false
    add 1 to {runnedsometime::%uuid of player%}
    message "Time: %{diff::%uuid of player%}%"
on join:
    if {runnedsometime::%uuid of player%} is not set:
        set {runnedsometime::%uuid of player%} to 1
[doublepost=1583333444][/doublepost]
If its worng, try to explain

novastosha, you gave me great code.
I'm glad, but it's wrong a little bit.
I try to explain.(I'll use translation. If it's weird sentence, I'm sorry.)


I want to keep the largest record of the numbers measured by clicking on the sign.
In other words, it is not just a sign that resets the record, but it is possible to refer to the previous record and compare it with whether to overwrite the record or not to overwrite the record.

As in the previous example,
Suppose that the first measurement resulted in a record of 20 seconds.
The second measurement showed a record of 22 seconds.
In this case, I want to display the first record in a message instead of the second record.

I want to make the record shown in the message the smallest ever.
Sorry again and again.
Please let me know if you have any questions.

I look forward to your reply.
 
{_diff} is a local variable. Local variables get deleted after a trigger ends, so you gotta use {diff::%player%}. (You can delete the {diff::%player%} later)
Kinda late Goose
Is that what you mean, I didn't understand correctly

code_language.skript:
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&2ToStart&e-|-"
    reset {diff::%uuid of player%}
    set {timer.%player%} to true
    set {_start} to now
    while {timer.%player%} is true:
        set {_new} to difference between now and {_start} + {_ok}
        set {_ok} to {runnedsometime::%uuid of player%} * 2
        if {diff::%uuid of player%} is not set:
            set {diff::%uuid of player%} to difference between now and {_start} + {_ok}
        else:
            if {diff::%uuid of player%} is bigger than {_new}:
                stop trigger
            else:
                set {diff::%uuid of player%} to {_new}
        wait 1 second
on rightclick on a sign:
    line 1 of clicked block is "&e-|-&6&lGoal&e-|-"
    set {timer.%player%} to false
    add 1 to {runnedsometime::%uuid of player%}
    set {_ok} to {runnedsometime::%uuid of player%} * 2
    message "Original Time: %{diff::%uuid of player%}%"
on join:
    if {runnedsometime::%uuid of player%} is not set:
        set {runnedsometime::%uuid of player%} to 1
 
Thank you, Goose and novastosha.



novastosha, you gave me great code.
I'm glad, but it's wrong a little bit.
I try to explain.(I'll use translation. If it's weird sentence, I'm sorry.)


I want to keep the largest record of the numbers measured by clicking on the sign.
In other words, it is not just a sign that resets the record, but it is possible to refer to the previous record and compare it with whether to overwrite the record or not to overwrite the record.

As in the previous example,
Suppose that the first measurement resulted in a record of 20 seconds.
The second measurement showed a record of 22 seconds.
In this case, I want to display the first record in a message instead of the second record.

I want to make the record shown in the message the smallest ever.
Sorry again and again.
Please let me know if you have any questions.

I look forward to your reply.

Guess u wanted this + optimized

Code:
on right click on sign:
    line 1 of clicked block "&e-|-&2ToStart&e-|-"
    #check if there isnt already a timer busy
    {Timer::%uuid of player%} is not set
    set {Timer::%uuid of player%} to now
    send "Ur Timer started"

    #While loop not needed unless u want a live counter (While loop not recommended with 100+ players online using the timer)
    #while {Timer::%uuid of player%} is set:
    #    set {_current} to difference between now and {Timer::%uuid of player%}
    #    send "current: %{_current}%"
    #    wait 1 second

on quit:
    #Stops/deletes the players timer wenn they leave
    delete {Timer::%uuid of player%}

on right click on sign:
    line 1 of clicked block is "&e-|-&6&lGoal&e-|-"
    #check if the player even has a timmer running
    if {Timer::%uuid of player%} is set:
        set {_prev} to {Record::%uuid of player%}
        set {_current} to difference between now and {Timer::%uuid of player%}
        delete {Timer::%uuid of player%}
        #check if the previous time is longer than the current try
        if {_prev} > {_current}:
            set {Record::%uuid of player%} to {_current}
        send "Old Record:%{_prev}% Current:%{_current}% Current Record:%{Record::%uuid of player%}%"
    else:
        send "U don't have a timer running."

#replace with on skript load: if u want it to only delete this data on server restart/reload not with /skript reload <script>
on script load:
    #Deletes all timers that got stuck due to a crash or a player not clicked the goal sign
    #So also stops all timers current running
    delete {Timer::*}
 
Thank you very much, everyone.

I'll try to rework in my way based on the code I've received.

The topic of this thread was about the cooldown, so I chose Mr.Goose as the best answer this time.

Thank you for many answers.
 
Status
Not open for further replies.