Xellic Posted March 2, 2015 Share Posted March 2, 2015 So I've managed to get the players around me and get their index #. But how do I right click the players around me, using the index # that I just collected? if(getPlayers().getAll() != null) { List<Player> p = getPlayers().getAll(); int j = p.get(0).getIndex(); log(j); } Quote Link to comment Share on other sites More sharing options...
Isolate Posted March 2, 2015 Share Posted March 2, 2015 Random rand = new Random(); if(getPlayers().getAll() != null) { java.util.List<Player> p = getPlayers().getAll(); int randomNum = rand.nextInt(((p.size()-1) - 0) + 1) + 0; Player randomPlayer = p.get(randomNum); if(randomPlayer != null){ randomPlayer.hover(); } } you could try something like this to get a random one, i dont know how accurate my random function is... i'm not good at it instead of hover you could do whatever you wanted, like right click on him or whatever Quote Link to comment Share on other sites More sharing options...
Xellic Posted March 2, 2015 Author Share Posted March 2, 2015 Random rand = new Random(); if(getPlayers().getAll() != null) { java.util.List<Player> p = getPlayers().getAll(); int randomNum = rand.nextInt(((p.size()-1) - 0) + 1) + 0; Player randomPlayer = p.get(randomNum); if(randomPlayer != null){ randomPlayer.hover(); } } you could try something like this to get a random one, i dont know how accurate my random function is... i'm not good at it instead of hover you could do whatever you wanted, like right click on him or whatever Ahh thank you very much! Quote Link to comment Share on other sites More sharing options...
Isolate Posted March 2, 2015 Share Posted March 2, 2015 Ahh thank you very much! feel free to remove the +0 :') Quote Link to comment Share on other sites More sharing options...
Mysteryy Posted March 2, 2015 Share Posted March 2, 2015 So I've managed to get the players around me and get their index #. But how do I right click the players around me, using the index # that I just collected? java.util.List<Player> p = getPlayers().getAll(); if(p != null) { int randomNum = script.random(0, p.size()-1); Player randomPlayer = p.get(randomNum); if(randomPlayer != null){ randomPlayer.hover(); } } you could try something like this to get a random one, i dont know how accurate my random function is... i'm not good at it instead of hover you could do whatever you wanted, like right click on him or whatever First you need to store the list, then null check the list. Making 2 calls is a common beginner mistake, which can result in a NPE when you thought you checked it. See the quote for the changed code. Also idk where u got this from: int randomNum = rand.nextInt(((p.size()-1) - 0) + 1) + 0; but that literally makes no sense. This is the same as p.size() -1 - 0 + 1 + 0 = 0 No clue what you were on when you wrote that but i need some. 5 Quote Link to comment Share on other sites More sharing options...
Isolate Posted March 2, 2015 Share Posted March 2, 2015 First you need to store the list, then null check the list. Making 2 calls is a common beginner mistake, which can result in a NPE when you thought you checked it. See the quote for the changed code. Also idk where u got this from: int randomNum = rand.nextInt(((p.size()-1) - 0) + 1) + 0; but that literally makes no sense. This is the same as p.size() -1 - 0 + 1 + 0 = 0 No clue what you were on when you wrote that but i need some. Last few days i've been pretty out of it. Didn't think it looked right at all, dunno why i bothere + or - 0's but ay i did :P Quote Link to comment Share on other sites More sharing options...
Extreme Scripts Posted March 2, 2015 Share Posted March 2, 2015 No clue what you were on when you wrote that but i need some. 3 Quote Link to comment Share on other sites More sharing options...