March 2, 201510 yr 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); }
March 2, 201510 yr 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
March 2, 201510 yr Author 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!
March 2, 201510 yr 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.
March 2, 201510 yr 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
Create an account or sign in to comment