Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Every once in a while my player will attack another npc while already under attack.. why?

Featured Replies

 NPC cow = main.getNpcs().closest(npc -> npc.getName().startsWith("cow") && npc.isAttackable());
            if (cow != null) {
                main.log("cow not null");
                if (!main.myPlayer().isInteracting(cow) && !cow.isInteracting(main.myPlayer()) && !main.myPlayer().isUnderAttack()) {
                    InteractionEvent e = new InteractionEvent(cow, "Attack");
                    e.setHover(false);
                    e.setMaximumAttempts(1);
                    e.setOperateCamera(true);
                    e.setWalkTo(false);
                    main.execute(e);
                    Util.Sleep.sleepUntil(() -> e.hasFailed() || main.myPlayer().isInteracting(cow) || cow.isInteracting(main.myPlayer()), 3000);
                }

95 percent of the time it can run for ages no problem, but every once in a while it will try to attack another npc and then get stuck trying to attack it while being attacked. Also this process only runs if !getCombat.isfighting, so theres another check. 

 

Just dont know what else i can do.

 

Insight welcome pls :)

 

44 minutes ago, saintpaul1 said:
 NPC cow = main.getNpcs().closest(npc -> npc.getName().startsWith("cow") && npc.isAttackable());
            if (cow != null) {
                main.log("cow not null");
                if (!main.myPlayer().isInteracting(cow) && !cow.isInteracting(main.myPlayer()) && !main.myPlayer().isUnderAttack()) {
                    InteractionEvent e = new InteractionEvent(cow, "Attack");
                    e.setHover(false);
                    e.setMaximumAttempts(1);
                    e.setOperateCamera(true);
                    e.setWalkTo(false);
                    main.execute(e);
                    Util.Sleep.sleepUntil(() -> e.hasFailed() || main.myPlayer().isInteracting(cow) || cow.isInteracting(main.myPlayer()), 3000);
                }

95 percent of the time it can run for ages no problem, but every once in a while it will try to attack another npc and then get stuck trying to attack it while being attacked. Also this process only runs if !getCombat.isfighting, so theres another check. 

 

Just dont know what else i can do.

 

Insight welcome pls :)

Have your script sleep 5-7+ seconds after you get hit OR hit a cow so that it accounts for connection lag. Seems like that's what might be breaking your script. 

Edited by 07ETHFarmer

11 hours ago, saintpaul1 said:
 NPC cow = main.getNpcs().closest(npc -> npc.getName().startsWith("cow") && npc.isAttackable());
            if (cow != null) {
                main.log("cow not null");
                if (!main.myPlayer().isInteracting(cow) && !cow.isInteracting(main.myPlayer()) && !main.myPlayer().isUnderAttack()) {
                    InteractionEvent e = new InteractionEvent(cow, "Attack");
                    e.setHover(false);
                    e.setMaximumAttempts(1);
                    e.setOperateCamera(true);
                    e.setWalkTo(false);
                    main.execute(e);
                    Util.Sleep.sleepUntil(() -> e.hasFailed() || main.myPlayer().isInteracting(cow) || cow.isInteracting(main.myPlayer()), 3000);
                }

95 percent of the time it can run for ages no problem, but every once in a while it will try to attack another npc and then get stuck trying to attack it while being attacked. Also this process only runs if !getCombat.isfighting, so theres another check. 

 

Just dont know what else i can do.

 

Insight welcome pls :)

Because you are loading the cloest cow with this code, that won't always be the cow you are fighting if another ones get into the same range as the one you are already fighting.

 NPC cow = main.getNpcs().closest(npc -> npc.getName().startsWith("cow") && npc.isAttackable());


What you can do is check if you are under attack by a cow, if so don't do anything, else attack a new one

NPC npcAttackingMe = script.getNpcs().closest(npc -> npc.isInteracting(script.myPlayer()) && npc.hasAction("Attack") && npc.getHealthPercent() > 0 && script.getMap().canReach(npc));

 

  • Author
2 hours ago, Khaleesi said:

Because you are loading the cloest cow with this code, that won't always be the cow you are fighting if another ones get into the same range as the one you are already fighting.

 NPC cow = main.getNpcs().closest(npc -> npc.getName().startsWith("cow") && npc.isAttackable());


What you can do is check if you are under attack by a cow, if so don't do anything, else attack a new one

NPC npcAttackingMe = script.getNpcs().closest(npc -> npc.isInteracting(script.myPlayer()) && npc.hasAction("Attack") && npc.getHealthPercent() > 0 && script.getMap().canReach(npc));

 

Thanks khal thats exactly my problem! Thanks for explaining! :>)

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.