kerklais Posted February 26, 2018 Share Posted February 26, 2018 Hi, i have been working on my script for a while now and can't resolve how i can check if there is players nearby? I tried to do something with (AREA.contains(something.....) Quote Link to comment Share on other sites More sharing options...
Butters Posted February 26, 2018 Share Posted February 26, 2018 (edited) Didn't test, but this might work players.getAll().stream().anyMatch(f -> myPlayer().getArea(5).contains(f)); This will check if there's at least one player around in an area of radius 5 around your player. Returns a boolean true/false Edited February 26, 2018 by nosepicker Quote Link to comment Share on other sites More sharing options...
GPSwap Posted February 26, 2018 Share Posted February 26, 2018 Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer())); closest is != null if there is a player within detectable distance (just about the size of the minimap) Quote Link to comment Share on other sites More sharing options...
Butters Posted February 26, 2018 Share Posted February 26, 2018 4 minutes ago, GPSwap said: Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer())); closest is != null if there is a player within detectable distance (just about the size of the minimap) This should actually work quicker than my example. Adding a lil extra to filter by predefined distance Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer()) && myPlayer.getArea(5).contains(p)); 1 Quote Link to comment Share on other sites More sharing options...
kerklais Posted February 26, 2018 Author Share Posted February 26, 2018 public int onLoop() throws InterruptedException { if (AREA.contains(myPlayer())) { Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer())); if (closest !=null) log("Hopping...."); getWorlds().hopToP2PWorld(); wait(5000); //freezes here...? }else { log("Walking"); if (getWalking().walk(AREA)); new ConditionalSleep(3000, 1000) { @Override public boolean condition() throws InterruptedException { return (AREA.contains(myPlayer())); } }.sleep(); } return 100; I tested those and they work. But now I'm trying to compound that script with world hopping.. Any help? Quote Link to comment Share on other sites More sharing options...
liverare Posted February 26, 2018 Share Posted February 26, 2018 I'm guessing you're trying to find players who are nearby you? If so: private List<Player> getPlayersNearby(int distance) { final Player me = myPlayer(); return players.filter(p -> !me.equals(p) && me.getPosition().distance(p) <= distance); } Quote Link to comment Share on other sites More sharing options...
liverare Posted February 26, 2018 Share Posted February 26, 2018 3 hours ago, nosepicker said: This should actually work quicker than my example. Adding a lil extra to filter by predefined distance Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer()) && myPlayer.getArea(5).contains(p)); You're misusing getArea: You're creating a new Area object just to test whether someone is inside of it. What a total waste. You're creating that new Area object for each player you check. Additionally, the null check is redundant as OSBot won't pass you null values to begin with, and you should cache myPlayer() somewhere, as that's likely a function that interfaces with the game to grab your player information. You should only have to grab it once for the duration of your checking. Otherwise, it's just inefficient. 2 Quote Link to comment Share on other sites More sharing options...
kerklais Posted February 26, 2018 Author Share Posted February 26, 2018 30 minutes ago, liverare said: I'm guessing you're trying to find players who are nearby you? If so: private List<Player> getPlayersNearby(int distance) { final Player me = myPlayer(); return players.filter(p -> !me.equals(p) && me.getPosition().distance(p) <= distance); } Yep or actually trying to check if there's any players nearby if there is the script will hop.. Quote Link to comment Share on other sites More sharing options...
Alek Posted February 26, 2018 Share Posted February 26, 2018 4 hours ago, GPSwap said: Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer())); closest is != null if there is a player within detectable distance (just about the size of the minimap) or simply !getPlayers().getAll().isEmpty() Edit: to account for my player just check if size == 1 3 Quote Link to comment Share on other sites More sharing options...