Jump to content

How to click local players around you?


Xellic

Recommended Posts

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

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

 

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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