Solved looping all players at once?

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

Aberforth

Member
Jun 14, 2019
40
2
8
Canada
Hello,
Let's say I have an example command that loops all players and sends them a message.

Code:
command /test:
    trigger:
        loop all players:
            send "message 1" to loop-player
            wait 1 second
            send "message 2" to loop-player

Now this will loop the first player first, then the second one, and so on until it goes through all the players. What can I do to make it happen simultaneously for all players? Now I know I could send these messages without any loop, but this is just an example and I need to loop all the players at once...

I thought about putting all players in a list variable, but I think I'm doing it wrong... Any help?
 
I need to loop those players. The code I gave was just an example of the problem. It's not just sending messages cause I know I can do it this way, I need to loop those players simultaneously.
 
You can loop all players, have some conditions or whatever, then send the message. Then, after whole loop ends, you wait a second, and then loop again
 
But then, once again it is going to loop one player, finish with him and then loop the second player and so on, right?
What if instead I had something like this:
Code:
loop all players:
            execute console command "/minecraft:tp %loop-player% -76.85 116 134.22 55.2 -38.24"
            wait 1 tick
            execute console command "/minecraft:tp %loop-player% -76.85 116 134.22 54.68 -38.87"
            wait 1 tick
            execute console command "/minecraft:tp %loop-player% -76.85 116 134.22 54.68 -38.98"

Then it's gonna take first player, teleport him 3 times, then take the second player and teleport him 3 times. I want it to take both players at once and teleport them 3 times.

Code:
teleport all players to location...
I know I can teleport players with the skript teleport, but I also need to set some variables for those players and a bunch of other stuff, and it all works, only problem is it does that for one player after another, instead of with all at once...

Can I put all players in a list variable to do this? I heard this solution before but somehow I don't think it worked, maybe I did something wrong...

Maybe something like this?
Code:
loop {players::*}:     
    execute console command "/minecraft:tp %loop-value% -76.85 116 134.22 0 0"
 
But then, once again it is going to loop one player, finish with him and then loop the second player and so on, right?
What if instead I had something like this:
Code:
loop all players:
            execute console command "/minecraft:tp %loop-player% -76.85 116 134.22 55.2 -38.24"
            wait 1 tick
            execute console command "/minecraft:tp %loop-player% -76.85 116 134.22 54.68 -38.87"
            wait 1 tick
            execute console command "/minecraft:tp %loop-player% -76.85 116 134.22 54.68 -38.98"

Then it's gonna take first player, teleport him 3 times, then take the second player and teleport him 3 times. I want it to take both players at once and teleport them 3 times.

Code:
teleport all players to location...
I know I can teleport players with the skript teleport, but I also need to set some variables for those players and a bunch of other stuff, and it all works, only problem is it does that for one player after another, instead of with all at once...

Can I put all players in a list variable to do this? I heard this solution before but somehow I don't think it worked, maybe I did something wrong...

Maybe something like this?
Code:
loop {players::*}:    
    execute console command "/minecraft:tp %loop-value% -76.85 116 134.22 0 0"

code_language.skript:
function runmycode(p: player):
    send "message 1" to {_p}
    wait 1 second
    send "message 2" to {_p}

command /loopallplayers:
    trigger:
        loop all players:
            runmycode(loop-player)
 
Status
Not open for further replies.