saintpaul1 Posted April 24, 2023 Share Posted April 24, 2023 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 Quote Link to comment Share on other sites More sharing options...
07ETHFarmer Posted April 24, 2023 Share Posted April 24, 2023 (edited) 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 April 24, 2023 by 07ETHFarmer Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted April 25, 2023 Share Posted April 25, 2023 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)); 2 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: 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! :>) 1 Quote Link to comment Share on other sites More sharing options...