February 26, 20187 yr 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.....)
February 26, 20187 yr 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, 20187 yr by nosepicker
February 26, 20187 yr 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)
February 26, 20187 yr 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));
February 26, 20187 yr Author 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?
February 26, 20187 yr 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); }
February 26, 20187 yr 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.
February 26, 20187 yr Author 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..
February 26, 20187 yr 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
Create an account or sign in to comment