Solved Simple start and stop timer

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

Ariuw

Member
Sep 6, 2017
42
1
8
30
Hello again, I've created a Countdown timer but I don't know how to stop it when I want, I want to do something like /timer stop so it stops. Here's my code so far:

Code:
command /timer [<text>] <integer>:
    trigger:
        if arg-1 is "start":
            set {_countdown} to arg 2
            wait 1 tick
            broadcast "&eCountdonw: &7%{_countdown}%"
            loop arg 2 times:
                remove 1 from {_countdown}
                wait 1 second
                broadcast "&eCountdonw: &7%{_countdown}%"
        if arg-1 is "stop"
            cancel event ???

also is there anyway to execute a command after countdown has ended?
 
simple... just set a variable... like {countdown} to true
use your /timer stop command to delete the variable
then, in your loop, add an if statement, .... if variable is true... do code, else... stop the loop
code_language.skript:
command /timer [<text>] [<integer>]:
    trigger:
        if arg-1 is "start":
            set {_countdown} to arg 2
            set {countdown} to true
            wait 1 tick
            loop arg 2 times:
                if {countdown} is true:
                    broadcast "&eCountdonw: &7%{_countdown}%"
                    remove 1 from {_countdown}
                    wait 1 second
                else:
                    stop
        if arg-1 is "stop":
            delete {countdown}
            send "TIMER STOPPED"
 
simple... just set a variable... like {countdown} to true
use your /timer stop command to delete the variable
then, in your loop, add an if statement, .... if variable is true... do code, else... stop the loop
code_language.skript:
command /timer [<text>] [<integer>]:
    trigger:
        if arg-1 is "start":
            set {_countdown} to arg 2
            set {countdown} to true
            wait 1 tick
            loop arg 2 times:
                if {countdown} is true:
                    broadcast "&eCountdonw: &7%{_countdown}%"
                    remove 1 from {_countdown}
                    wait 1 second
                else:
                    stop
        if arg-1 is "stop":
            delete {countdown}
            send "TIMER STOPPED"

Thank you!, commands after the countdown ended will go on this line? :

Code:
            loop arg 2 times:
                if {countdown} is true:
                    broadcast "&eCountdonw: &7%{_countdown}%"
                    remove 1 from {_countdown}
                    wait 1 second
                    command line
 
no, because that would run the command within the loop... so delete 2 indentations .... which will make the command run when the loop has finished
 
Status
Not open for further replies.