saintpaul1 Posted April 24, 2023 Share Posted April 24, 2023 This is what i use to detect if a player is nearby that can attack me and is wearing certain gear. Works great if anyone needs it . public boolean nearbyThreat() { int wildernessLevel = map.getWildernessLevel(); int myCombatLevel = myPlayer().getCombatLevel(); List<Player> nearbyPlayers = getPlayers().filter(p -> p != null && !p.equals(myPlayer()) && p.getPosition().distance(myPlayer().getPosition()) <= 25); for (Player player : nearbyPlayers) { int playerCombatLevel = player.getCombatLevel(); int combatLevelDiff = myCombatLevel - playerCombatLevel; if (Math.abs(combatLevelDiff) <= wildernessLevel) { String equipment = getOthersEquipment(player); if (equipment.contains("Staff") || equipment.contains("cape") || equipment.contains("Dark") || equipment.contains("Mystic") || equipment.contains("Xerix") || equipment.contains("Occult") || player.isInteracting(myPlayer())) { log("Player " + player.getName() + " has equipment: " + equipment); imInDanger = true; return true; // found a nearby player who is a threat } } } imInDanger = false; return false; // no nearby player is a threat } Current issue im having, cant seem to break my pathwalk if a threat is nearby. It will always finish the walk before teleporting. I have nearbyThreat running constantly in onLoop. if (!atDestination()) { try { walking.walkPath(areasAndPaths.pathToDestination); } catch (InterruptedException e) { throw new RuntimeException(e); } } Util.Sleep.sleepUntil(() -> atDestination() || nearbyThreat(), 5000); } Also tried using a while loop. Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted April 25, 2023 Share Posted April 25, 2023 7 hours ago, saintpaul1 said: This is what i use to detect if a player is nearby that can attack me and is wearing certain gear. Works great if anyone needs it . public boolean nearbyThreat() { int wildernessLevel = map.getWildernessLevel(); int myCombatLevel = myPlayer().getCombatLevel(); List<Player> nearbyPlayers = getPlayers().filter(p -> p != null && !p.equals(myPlayer()) && p.getPosition().distance(myPlayer().getPosition()) <= 25); for (Player player : nearbyPlayers) { int playerCombatLevel = player.getCombatLevel(); int combatLevelDiff = myCombatLevel - playerCombatLevel; if (Math.abs(combatLevelDiff) <= wildernessLevel) { String equipment = getOthersEquipment(player); if (equipment.contains("Staff") || equipment.contains("cape") || equipment.contains("Dark") || equipment.contains("Mystic") || equipment.contains("Xerix") || equipment.contains("Occult") || player.isInteracting(myPlayer())) { log("Player " + player.getName() + " has equipment: " + equipment); imInDanger = true; return true; // found a nearby player who is a threat } } } imInDanger = false; return false; // no nearby player is a threat } Current issue im having, cant seem to break my pathwalk if a threat is nearby. It will always finish the walk before teleporting. I have nearbyThreat running constantly in onLoop. if (!atDestination()) { try { walking.walkPath(areasAndPaths.pathToDestination); } catch (InterruptedException e) { throw new RuntimeException(e); } } Util.Sleep.sleepUntil(() -> atDestination() || nearbyThreat(), 5000); } Also tried using a while loop. I believe the walking code is a event and no other code of yours gets executed until it's done. If you print out some logs you can see that What you can do is create your own walkingevent: (Rough guess) WalkingEvent event = new WalkingEvent(); event.setPath(areasAndPaths.pathToDestination); event.setHighBreakPriority(true); event.setBreakCondition(new Condition() { @Override public boolean evaluate() { return atDestination() || nearbyThreat(); } }); Quote Link to comment Share on other sites More sharing options...
saintpaul1 Posted April 25, 2023 Author Share Posted April 25, 2023 2 hours ago, Khaleesi said: I believe the walking code is a event and no other code of yours gets executed until it's done. If you print out some logs you can see that What you can do is create your own walkingevent: (Rough guess) WalkingEvent event = new WalkingEvent(); event.setPath(areasAndPaths.pathToDestination); event.setHighBreakPriority(true); event.setBreakCondition(new Condition() { @Override public boolean evaluate() { return atDestination() || nearbyThreat(); } }); Ah brill thank you ! Walking event is what i needed much appreciated 1 Quote Link to comment Share on other sites More sharing options...
saintpaul1 Posted May 4, 2023 Author Share Posted May 4, 2023 On 4/25/2023 at 5:45 AM, Khaleesi said: I believe the walking code is a event and no other code of yours gets executed until it's done. If you print out some logs you can see that What you can do is create your own walkingevent: (Rough guess) WalkingEvent event = new WalkingEvent(); event.setPath(areasAndPaths.pathToDestination); event.setHighBreakPriority(true); event.setBreakCondition(new Condition() { @Override public boolean evaluate() { return atDestination() || nearbyThreat(); } }); Hey khal just coming back to this. The walkEvent breaks easily if a threat is nearby which is great. The issue i have with walkEvent is when walking sometimes it gets to the next tile in the path and then clicks the same tile again or takes a step backwards or to the side and then carrys on walking. I also had this issue with walkPath but i used a custom walk method, to keep walking before it reached the next tile. Not sure how to do this with walkEvent if its even possible? If you have any ideas i would be graetful. Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted May 6, 2023 Share Posted May 6, 2023 On 5/4/2023 at 10:35 PM, saintpaul1 said: Hey khal just coming back to this. The walkEvent breaks easily if a threat is nearby which is great. The issue i have with walkEvent is when walking sometimes it gets to the next tile in the path and then clicks the same tile again or takes a step backwards or to the side and then carrys on walking. I also had this issue with walkPath but i used a custom walk method, to keep walking before it reached the next tile. Not sure how to do this with walkEvent if its even possible? If you have any ideas i would be graetful. I have no idea about that, 'm not sure how the inner mechanics of the walkingevent works, you can tweak it some with other option you can add like minimapdistance, ... maybe that helps for you? Quote Link to comment Share on other sites More sharing options...
saintpaul1 Posted May 6, 2023 Author Share Posted May 6, 2023 2 hours ago, Khaleesi said: I have no idea about that, 'm not sure how the inner mechanics of the walkingevent works, you can tweak it some with other option you can add like minimapdistance, ... maybe that helps for you? Thanks for replying, i managed to sort it by creating a new path and setting distances to 0. 1 Quote Link to comment Share on other sites More sharing options...