Jump to content

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


saintpaul1

Recommended Posts

 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 :)

Link to comment
Share on other sites

 

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

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

 

  • Like 2
Link to comment
Share on other sites

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! :>)

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