Jump to content

Breaking walkPath when there is a player nearby?


saintpaul1

Recommended Posts

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.

Link to comment
Share on other sites

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


 

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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