1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved looping all players at once?

Discussion in 'Skript' started by Aberforth, Jul 9, 2020.

Thread Status:
Not open for further replies.
  1. Aberforth

    Aberforth Member

    Joined:
    Jun 14, 2019
    Messages:
    40
    Likes Received:
    2
    Hello,
    Let's say I have an example command that loops all players and sends them a message.

    Code (Text):
    1. command /test:
    2.     trigger:
    3.         loop all players:
    4.             send "message 1" to loop-player
    5.             wait 1 second
    6.             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?

     
  2. Best Answer:
    Post #7 by Lego_freak1999, Jul 10, 2020
  3. MeHow

    MeHow Active Member

    Joined:
    Feb 6, 2017
    Messages:
    140
    Likes Received:
    13
    Code (Text):
    1. send "message 1" to all players
    2.  
     
  4. Aberforth

    Aberforth Member

    Joined:
    Jun 14, 2019
    Messages:
    40
    Likes Received:
    2
    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.
     
  5. malia

    malia Well-Known Member

    Joined:
    Jul 24, 2019
    Messages:
    314
    Likes Received:
    21
    the code the dude before you provided does the same shit as yours...
     
  6. TPGamesNL

    Moderator Supporter Addon Developer Dev Programme

    Joined:
    Jan 20, 2018
    Messages:
    1,501
    Likes Received:
    108
    Medals:
    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
     
  7. Aberforth

    Aberforth Member

    Joined:
    Jun 14, 2019
    Messages:
    40
    Likes Received:
    2
    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 (Text):
    1. loop all players:
    2.             execute console command "/minecraft:tp %loop-player% -76.85 116 134.22 55.2 -38.24"
    3.             wait 1 tick
    4.             execute console command "/minecraft:tp %loop-player% -76.85 116 134.22 54.68 -38.87"
    5.             wait 1 tick
    6.             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 (Text):
    1. 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 (Text):
    1. loop {players::*}:    
    2.     execute console command "/minecraft:tp %loop-value% -76.85 116 134.22 0 0"
     
  8. Lego_freak1999

    Lego_freak1999 Well-Known Member

    Joined:
    Jan 26, 2017
    Messages:
    664
    Likes Received:
    45
    Code (Skript):
    1. function runmycode(p: player):
    2.     send "message 1" to {_p}
    3.     wait 1 second
    4.     send "message 2" to {_p}
    5.  
    6. command /loopallplayers:
    7.     trigger:
    8.         loop all players:
    9.             runmycode(loop-player)
     
    Jacob105, Ennas, Blue and 1 other person like this.
  9. Aberforth

    Aberforth Member

    Joined:
    Jun 14, 2019
    Messages:
    40
    Likes Received:
    2
    Yes, that's exactly what I was looking for! Thank you very much.
     
    Lego_freak1999 likes this.
Thread Status:
Not open for further replies.

Share This Page

Loading...