Solved How do you make a loop run until you run a command and then terminate the second that command is run

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

Status
Not open for further replies.

iLazer

Member
Apr 1, 2022
15
0
1
And make it so no matter what the thing will not happen again
[doublepost=1648851397,1648851192][/doublepost]you see, im tryin to make it so that random events occur in my kitpvp, but when i made a while script with a varible, when i quickly toggle on and off the script, it runs two of them, because the while loop resumes when i run the command, but even when i have an end loop, if i quickly toggle it then it doesnt sense the varible has changed in time.
here is the code in it:

command /pvpon:
trigger:
send "&2&lPowering on Pvp Events!"
set {Randomizer} to 0
set {events} to true
wait 5 seconds
while {events} is true:
set {Randomizer} to random integer between 2 and 4
set {_player} to random element of all players
if {Randomizer} = 2:
send "Giving &b&lswiftness 4 &rto &6%{_player}%!"
wait 5 second
apply swiftness 4 to {_player}
if {Randomizer} = 3:
send "Giving &a&ljump boost 7 &rto &6%{_player}%!"
wait 5 second
apply jump boost 7 to {_player}
if {Randomizer} = 4:
send "Giving &4&lstrength 10 &rto &6all players!"
wait 5 second
apply strength 10 to all players
if {Randomizer} = 5:
send "&5&lLEVITATION TIME IN 10 SECONDS!"
wait 5 second
send "&5&lLEVITATION TIME IN 5 SECONDS!"
wait 1 second
send "&5&lLEVITATION TIME IN 4 SECONDS!"
wait 1 second
send "&5&lLEVITATION TIME IN 3 SECONDS!"
wait 1 second
send "&5&lLEVITATION TIME IN 2 SECONDS!"
wait 1 second
send "&5&lLEVITATION TIME IN 1 SECONDS!"
wait 1 second
send "&5&l&nLEVITATION TIME!"
apply levitation 2 to all players
apply levitation 2 to all players
wait 10 seconds
apply slow falling 1 to all players
apply slow falling 1 to all players
if {Randomizer} = 6:
send "Giving &e&lAbsorption 10 &rto &6%{_player}%!"
wait 5 second
apply absorption 10 to {_player}
if {Randomizer} = 7:
send "Giving swiftness 2 to %{_player}%!"
wait 5 second
apply swiftness 2 to {_player}
if {Randomizer} = 8:
send "Giving swiftness 2 to %{_player}%!"
wait 5 second
apply swiftness 2 to {_player}
if {Randomizer} = 1:
send "Giving swiftness 2 to %{_player}%!"
wait 5 second
apply swiftness 2 to {_player}
wait 25 seconds
if {events} is false:
stop loop

command /pvpoff:
trigger:
send "&4&lPowering off Pvp Events!"
set {events} to false
command /test:
trigger:
set {events} to false
 
And make it so no matter what the thing will not happen again
[doublepost=1648851397,1648851192][/doublepost]you see, im tryin to make it so that random events occur in my kitpvp, but when i made a while script with a varible, when i quickly toggle on and off the script, it runs two of them, because the while loop resumes when i run the command, but even when i have an end loop, if i quickly toggle it then it doesnt sense the varible has changed in time.
here is the code in it:

command /pvpon:
trigger:
send "&2&lPowering on Pvp Events!"
set {Randomizer} to 0
set {events} to true
wait 5 seconds
while {events} is true:
set {Randomizer} to random integer between 2 and 4
set {_player} to random element of all players
if {Randomizer} = 2:
send "Giving &b&lswiftness 4 &rto &6%{_player}%!"
wait 5 second
apply swiftness 4 to {_player}
if {Randomizer} = 3:
send "Giving &a&ljump boost 7 &rto &6%{_player}%!"
wait 5 second
apply jump boost 7 to {_player}
if {Randomizer} = 4:
send "Giving &4&lstrength 10 &rto &6all players!"
wait 5 second
apply strength 10 to all players
if {Randomizer} = 5:
send "&5&lLEVITATION TIME IN 10 SECONDS!"
wait 5 second
send "&5&lLEVITATION TIME IN 5 SECONDS!"
wait 1 second
send "&5&lLEVITATION TIME IN 4 SECONDS!"
wait 1 second
send "&5&lLEVITATION TIME IN 3 SECONDS!"
wait 1 second
send "&5&lLEVITATION TIME IN 2 SECONDS!"
wait 1 second
send "&5&lLEVITATION TIME IN 1 SECONDS!"
wait 1 second
send "&5&l&nLEVITATION TIME!"
apply levitation 2 to all players
apply levitation 2 to all players
wait 10 seconds
apply slow falling 1 to all players
apply slow falling 1 to all players
if {Randomizer} = 6:
send "Giving &e&lAbsorption 10 &rto &6%{_player}%!"
wait 5 second
apply absorption 10 to {_player}
if {Randomizer} = 7:
send "Giving swiftness 2 to %{_player}%!"
wait 5 second
apply swiftness 2 to {_player}
if {Randomizer} = 8:
send "Giving swiftness 2 to %{_player}%!"
wait 5 second
apply swiftness 2 to {_player}
if {Randomizer} = 1:
send "Giving swiftness 2 to %{_player}%!"
wait 5 second
apply swiftness 2 to {_player}
wait 25 seconds
if {events} is false:
stop loop

command /pvpoff:
trigger:
send "&4&lPowering off Pvp Events!"
set {events} to false
command /test:
trigger:
set {events} to false
Code:
function pvpevents():
    wait 5 seconds
    while {events} exists:
        set {Randomizer} to random integer between 2 and 4
        set {_player} to random element of all players
        if {Randomizer} = 2:
            send "Giving &b&lswiftness 4 &rto &6%{_player}%!" to {_player} #in this case you have to specify who recives the message
            wait 5 second
            apply swiftness 4 to {_player}
        else if {Randomizer} = 3:
            broadcast "Giving &a&ljump boost 7 &rto &6%{_player}%!" #if you want everyone to se the message do broadcast. If you just want the player to see this message specify to {_player}
            wait 5 second
            apply jump boost 7 to {_player}
        else if {Randomizer} = 4:
            broadcast "Giving &4&lstrength 10 &rto &6all players!"
            wait 5 second
            apply strength 10 to all players
        else if {Randomizer} = 5:
            broadcast "&5&lLEVITATION TIME IN 10 SECONDS!"
            wait 5 second
            broadcast "&5&lLEVITATION TIME IN 5 SECONDS!"
            wait 1 second
            broadcast "&5&lLEVITATION TIME IN 4 SECONDS!"
            wait 1 second
            broadcast "&5&lLEVITATION TIME IN 3 SECONDS!"
            wait 1 second
            broadcast "&5&lLEVITATION TIME IN 2 SECONDS!"
            wait 1 second
            broadcast "&5&lLEVITATION TIME IN 1 SECONDS!"
            wait 1 second
            broadcast "&5&l&nLEVITATION TIME!"
            apply levitation 2 to all players
            apply levitation 2 to all players
            wait 10 seconds
            apply slow falling 1 to all players
            apply slow falling 1 to all players
        else if {Randomizer} = 6:
            broadcast "Giving &e&lAbsorption 10 &rto &6%{_player}%!"
            wait 5 second
            apply absorption 10 to {_player}
        else if {Randomizer} = 7:
            broadcast "Giving swiftness 2 to %{_player}%!"
            wait 5 second
            apply swiftness 2 to {_player}
        else if {Randomizer} = 8:
            broadcast "Giving swiftness 2 to %{_player}%!"
            wait 5 second
            apply swiftness 2 to {_player}
        else if {Randomizer} = 1:
            broadcast "Giving swiftness 2 to %{_player}%!"
            wait 5 second
            apply swiftness 2 to {_player}
            wait 25 seconds
        #if {events} is false: you dont need this
            #stop loop
command /pvpon:
    trigger:
    broadcast "&2&lPowering on Pvp Events!"
    set {Randomizer} to 0
    set {events} to true
    pvpevents()#call the function

command /pvpoff:
    trigger:
        broadcast "&4&lPowering off Pvp Events!"#this wll massage just who execute the command to message everyone do bradcast "message"
        delete {events}
        
        
command /test:
    trigger:
        delete {events}
 
Status
Not open for further replies.