DragonTTK Posted May 2, 2016 Share Posted May 2, 2016 (edited) I am trying to make a script and it will constantly keep clicking on the NPC regardless of if its already in combat or not and will sometimes try to switch to another npc in combat how would i go about stopping this? Note im really new to this and would like to get into this sort of stuff. Heres the code im using (Guard killer) package GuardKiller;import org.osbot.rs07.api.model.GroundItem;import org.osbot.rs07.api.model.NPC;import org.osbot.rs07.script.Script;import org.osbot.rs07.script.ScriptManifest;import java.awt.*;import java.awt.image.BufferedImage;import java.io.IOException;import javax.imageio.ImageIO;@ScriptManifest(author = "Skeleton", info = "Kills falador guards", name = "Guard Killer", version = 1, logo = "http://osbot.org/images/logo.png")public class GuardKiller extends Script { BufferedImage background; @Override public void onStart() { try{background = ImageIO.read(GuardKiller.class.getResourceAsStream("/GuardKillers/images/bg.png"));} catch(IOException e){log(e);} } private enum State { KILL, LOOT, WAIT, BANK, WALK, }; private State getState() { NPC guard = npcs.closest("Guard"); GroundItem loot = groundItems.closest("{Medium} Clue Scroll"); if (guard != null) return State.KILL; if (loot != null) return State.LOOT; return State.WAIT; } @Override public int onLoop() throws InterruptedException { switch (getState()) { case KILL: NPC guard = npcs.closest("Guard"); if(guard != null){ guard.interact("Attack"); log("Status: Attacking..."); } break; case LOOT: GroundItem loot = groundItems.closest("{Medium} Clue Scroll"); if (loot != null) { loot.interact("Take"); log("Status: Looting..."); } break; case WAIT: log("Status: Waiting..."); sleep(random(500, 600)); break; case BANK: log("Status: Banking..."); break; case WALK: log("Status: Walking..."); break; } return random(200, 300); } @Override public void onExit() { } @Overridepublic void onPaint(Graphics2D g){ if(background != null){g.drawImage(background, null, 149, 154);g.drawString("Guard killer", 37, 270);}} } Edited May 2, 2016 by DragonTTK Quote Link to comment Share on other sites More sharing options...
Eagle Scripts Posted May 2, 2016 Share Posted May 2, 2016 You're only checking the guard != null. To get started; you should also check if your player is not under attack, if the guard is not under attack and if the guard is still alive (not doing the death emote, cause then its still not null while performing the emote) Quote Link to comment Share on other sites More sharing options...
IHB Posted May 2, 2016 Share Posted May 2, 2016 (edited) private State getState() { NPC guard = npcs.closest("Guard"); GroundItem loot = groundItems.closest("{Medium} Clue Scroll"); if (myPlayer().isUnderAttack()) { return State.WAIT; if (guard != null) return State.KILL; if (loot != null) return State.LOOT; return State.WAIT; } also try adding a sleep in your KILL state so when it clicks once it sleeps for a bit before trying to grab a new state Edited May 2, 2016 by IHB 1 Quote Link to comment Share on other sites More sharing options...
Woody Posted May 2, 2016 Share Posted May 2, 2016 (edited) if (guard != null && guard.isAttackable() && !myPlayer().isUnderAttack()) return State.KILL; You need more checks other than "guard != null" if you want to fight NPC. As IHB said, you should put a sleep after interaction; a conditional sleep. if(guard != null){ if(guard.interact("Attack")) { log("Status: Attacking..."); new ConditionalSleep(4000, 500) { @Override public boolean condition() throws InterruptedException { return api.myPlayer().isInteracting(guard); } }.sleep(); } } It will check the condition() every 500 ms and wait maximum 4000 ms before executing the interaction again. Edited May 2, 2016 by Woody 1 Quote Link to comment Share on other sites More sharing options...
DragonTTK Posted May 2, 2016 Author Share Posted May 2, 2016 Oh i see makes sense alright ill try this out and stuff thanks guys! Quote Link to comment Share on other sites More sharing options...