February 6, 20197 yr I'm guessing the issue has something to do with your from-boat-to-Void-Knight logic. I say that because you're using both a state-based system and a task node system, which has made your script difficult to follow. I wrote an ad-hoc alternative that might help: Spoiler import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.Character; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Script; public class PestControl extends Script { Position outsideBoat = new Position(2657,2639,0); Area insideBoat = new Area(2660,2638,2663,2643); Position whereToGo; @Override public int onLoop() throws InterruptedException { if (myPosition().equals(outsideBoat)) { enterTheBoat(); } else if (insideBoat.contains(myPlayer())) { whereToGo = null; // reset before the next game waitOnTheBoat(); } else { // assume we're in the minigame playMinigame(); } return 250; } private void enterTheBoat() { RS2Object plank = objects.closest("Gangplank"); if (plank != null) { log("I am crossing the plank"); plank.interact("Cross"); } } private void waitOnTheBoat() throws InterruptedException { log("I am waiting on the Boat"); sleep(5000); } private void playMinigame() { if (whereToGo == null) { // generate a dynamic tile where void knight is at NPC squire = npcs.closest("Squire"); if (squire != null) { log("I can see the Squire"); whereToGo = squire.getPosition().translate(0, -15); } } else if (map.realDistance(whereToGo) > 10) { // go to void knight log("I am walking to where the Void Knight should be"); walking.walk(whereToGo); } else { // protect void knight NPC voidKnight = npcs.closest("Void Knight"); if (voidKnight != null) { if (!myPlayer().isUnderAttack() && myPlayer().getInteracting() == null) { log("Attacking"); NPC enemy = findEnemy(); if (enemy != null) { enemy.interact("Attack"); } } } } } private NPC findEnemy() { return npcs.getAll().stream() // only get Pest Control foes .filter(PestControl::isEnemy) // and make sure they're alive .filter(npc -> npc.getHealthPercent() > 0) // and that they're nearby to where we want to be .filter(npc -> npc.getPosition().distance(whereToGo) < 10) // then sort our enemies by whether or not they're attacking void knight .sorted(PestControl::prioritiseOnEnemiesAttackingVoidKnight) // then get the first enemy in the list .findFirst() // or return null .orElse(null); } private static boolean isEnemy(NPC npc) { String name = npc.getName(); return name.equals("Spinner") || name.equals("Shifter") || name.equals("Portal") || name.equals("Defiler") || name.equals("Splatter") || name.equals("Torcher") || name.equals("Brawler"); } private static int prioritiseOnEnemiesAttackingVoidKnight(NPC npc1, NPC npc2) { Character<?> c1 = npc1.getInteracting(); Character<?> c2 = npc2.getInteracting(); return Boolean.compare(isVoidKnight(c1), isVoidKnight(c2)); } private static boolean isVoidKnight(Character<?> c) { return c != null && c instanceof NPC && c.getName().equals("Void Knight"); } }
Create an account or sign in to comment