Problem with looping

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

SoMuchWessel

Active Member
Apr 3, 2017
147
3
18
47
Hello guys,
I got this code:


code_language.skript:
command /startclassic1:
    executable by: console and players
    trigger:
        loop all players:
            if {classic::players::*} contains loop-player:
                if {color::%loop-player%} is set:
                    set {_rol} to a random element out of {classic::rollen::*}
                    set {rol::%loop-player%} to {_rol}
                    remove {_rol} from {classic::rollen::*}
                    send "You are the %{_rol}%!" to loop-player
                    send "%loop-player% is %{_rol}%" to console
                    if {_rol} is "Godfather" or "Framer" or "Mafioso":
                        add loop-player to {classic::mafia::*}
                        send "&cClassic 1 Mafia: &f%{classic::mafia::*}%" to console
                    else if {_rol} is "Serial Killer":
                        add loop-player to {classic::evil::*}
                        send "&cClassic 1 Evil: &f%{classic::evil::*}%" to console
                    else if {_rol} is "Survivor":
                        add loop-player to {classic::neutral::*}
                        send "&cClassic 1 Neutral: &f%{classic::neutral::*}%" to console
                    else:
                        add loop-player to {classic::town::*}
                        send "&cClassic 1 Town: &f%{classic::town::*}%" to console
                    set {_countdown} to 10
                    wait 1 tick
                    send action bar from "Daytime: %{_countdown}%" to loop-player
                    loop 10 times:
                        remove 1 from {_countdown}
                        wait 1 second
                        send action bar from "Daytime: %{_countdown}%" to loop-player
                    wait a second   
                    send action bar from "&b" to loop-player
                set {classic.started} to true
                set {classic.night} to true

The problem with this code is that it takes to long.
I want that this code is running for every player at the same time, that this code does is run it for every player one by one.
Is there a way to fix this?
 
Hello guys,
I got this code:


code_language.skript:
command /startclassic1:
    executable by: console and players
    trigger:
        loop all players:
            if {classic::players::*} contains loop-player:
                if {color::%loop-player%} is set:
                    set {_rol} to a random element out of {classic::rollen::*}
                    set {rol::%loop-player%} to {_rol}
                    remove {_rol} from {classic::rollen::*}
                    send "You are the %{_rol}%!" to loop-player
                    send "%loop-player% is %{_rol}%" to console
                    if {_rol} is "Godfather" or "Framer" or "Mafioso":
                        add loop-player to {classic::mafia::*}
                        send "&cClassic 1 Mafia: &f%{classic::mafia::*}%" to console
                    else if {_rol} is "Serial Killer":
                        add loop-player to {classic::evil::*}
                        send "&cClassic 1 Evil: &f%{classic::evil::*}%" to console
                    else if {_rol} is "Survivor":
                        add loop-player to {classic::neutral::*}
                        send "&cClassic 1 Neutral: &f%{classic::neutral::*}%" to console
                    else:
                        add loop-player to {classic::town::*}
                        send "&cClassic 1 Town: &f%{classic::town::*}%" to console
                    set {_countdown} to 10
                    wait 1 tick
                    send action bar from "Daytime: %{_countdown}%" to loop-player
                    loop 10 times:
                        remove 1 from {_countdown}
                        wait 1 second
                        send action bar from "Daytime: %{_countdown}%" to loop-player
                    wait a second  
                    send action bar from "&b" to loop-player
                set {classic.started} to true
                set {classic.night} to true

The problem with this code is that it takes to long.
I want that this code is running for every player at the same time, that this code does is run it for every player one by one.
Is there a way to fix this?
I would recommend setting the actual code in a function, and in the command you loop all players and run that function on them
 
Status
Not open for further replies.