Choosing one random player

Discussion in 'Skript' started by DropTheHood, Apr 14, 2017.

  1. Hi! So, I am making a game where 1 player gets chosen to be IT. I have no clue how to do that so some help will be great! Thanks - Cheers
     
  2. Assuming you've added the players in the game to a arraylist or map. You would do something like this(Answered this question today)
    Code (Text):
    int selecting = new Random().nextInt(map.size());
                                            Object picked = map.get(selecting);
    For a map you'd probably have to loop through it and get one
     
    • Informative Informative x 1
  3. maldahleh

    Wiki Team

    This is posted in the Skript forum so I don't think he's looking for a Java solution.
     
    • Optimistic Optimistic x 1
  4. Code (Text):
    set {playerTarget} to a random player out of all players
     
  5. Ops! Sorry, I think I somehow clicked on this by accident, sorry.
     
    • Like Like x 1
  6. xD Its all good man! Thanks for the help guys! :)
     
  7. Sorry - How would I target someone ONLY if they have something true? For example: set {playerTarget} to a random player out of all players that have {playing.%player%} to true - Thanks for the help :)
     
  8. try:
    Code (code (Unknown Language)):

    loop all players:
        if {target.%loop-player%} is true:
            set {target} to loop-player
            stop
     
     
  9. You need a list variable to use the random feature.
    Code (Text):

    loop all players:
       if {playing.%player%} is true:
          add loop-player to {_playing::*}
    set {playerTarget} to a random player out of {_playing::*}
     
  10. It should be like this

    Code (Text):

    loop all players:
       if {playing.%loop-player%} is true:
          add loop-player to {_playing::*}
    set {playerTarget} to a random player out of {_playing::*}
     
    • Like Like x 1
  11. If someone could fix this, please help me! This is getting very annoying! Thanks
     
  12. What do you need help with? We already posted what to do.
     
    • Informative Informative x 1