Jump to content

Breaking walkPath when there is a player nearby?


Recommended Posts

Posted

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.

Posted
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();
    }
 });


 

Posted
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

  • Heart 1
  • 2 weeks later...
Posted
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.

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

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

 

:)

  • Like 1

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...