Jump to content

How to click local players around you?


Recommended Posts

Posted

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

 

Posted
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!

Posted

 

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. 

  • Like 5
Posted

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

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...