guseggers Posted September 5, 2015 Share Posted September 5, 2015 Hi This is my first script, and I believe I have it compiled right and everything... But whenever I run it from OSBot it makes OSBot stop responding and closes it... Is it my crappy script or what? I don't want it to bank or anything, just sit in the goblin hut and kill them... Help please? Thanks so much. import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(author = "Jards", info = "A Script", name = "Goblin Killer", version = 0.01, logo = "") public class main extends Script { @Override public void onStart() { log("Welcome to gusegger's bot!"); } // all the states we can be in private enum State { IDLE, ATTACKING_GOBLIN, IN_COMBAT, AT_FIELD }; // if player is by the goblin field public boolean atField() { Player player = myPlayer(); int x = player.getPosition().getX(); int y = player.getPosition().getY(); //stating if we're in these positions if ((x > 3242) && (x < 3249) && (y > 3243) && (y < 3249)) { log("x : " + x + " y " + y); log("You're at the goblins son!"); return true; } log("x : " + x + " y : " + y); return false; } // seeing if we're in combat public boolean inCombat() { if(myPlayer().isUnderAttack()) { log("We're in combat!"); return true; } log("We're not in combat yet, punk!"); return false; } public void killingGoblin() { NPC Goblin = npcs.closest("Goblin"); if (Goblin != null && Goblin.getHealth() != 0 && Goblin.isAttackable() && Goblin.getName().contains("Goblin")) { if (map.canReach(Goblin)) { log("Attacking that punk ass goblin!"); Goblin.interact("Attack"); } } else { log("No goblins found!"); } } private State getstate() { // if we are at the field of goblins but not in combat // if we are at the field and in combat, set to in_combat if (atField() && !inCombat()) return State.ATTACKING_GOBLIN; // if we are under attack, set to in_combat if (myPlayer().isUnderAttack()) return State.IN_COMBAT; //if nothing is happening, set to idle return State.IDLE; } @Override public int onLoop() throws InterruptedException { switch (getstate()) { case IN_COMBAT: break; case ATTACKING_GOBLIN: log("Start killing a goblin!"); killingGoblin(); break; } return random(100,300); } @Override public void onExit() { log("Thanks for using gusegger's bot!"); } @Override public void onPaint(Graphics2D g) { //NYI } } Quote Link to comment Share on other sites More sharing options...
Chris Posted September 5, 2015 Share Posted September 5, 2015 import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(author = "Jards", info = "A Script", name = "Goblin Killer", version = 0.01, logo = "") public class main extends Script { @Override public void onStart() { log("Welcome to gusegger's bot!"); } // all the states we can be in private enum State { IDLE, ATTACKING_GOBLIN, IN_COMBAT, AT_FIELD }; // if player is by the goblin field public boolean atField() { Player player = myPlayer(); int x = player.getPosition().getX(); int y = player.getPosition().getY(); //stating if we're in these positions if ((x > 3242) && (x < 3249) && (y > 3243) && (y < 3249)) { log("x : " + x + " y " + y); log("You're at the goblins son!"); return true; } log("x : " + x + " y : " + y); return false; } // seeing if we're in combat public boolean inCombat() { if(myPlayer().isUnderAttack()) { log("We're in combat!"); return true; } log("We're not in combat yet, punk!"); return false; } public void killingGoblin() { NPC Goblin = npcs.closest("Goblin"); if (Goblin != null && Goblin.getHealth() != 0 && Goblin.isAttackable() && Goblin.getName().contains("Goblin")) { if (map.canReach(Goblin)) { log("Attacking that punk ass goblin!"); Goblin.interact("Attack"); } } else { log("No goblins found!"); } } private State getstate() { // if we are at the field of goblins but not in combat // if we are at the field and in combat, set to in_combat if (atField() && !inCombat()) return State.ATTACKING_GOBLIN; // if we are under attack, set to in_combat if (myPlayer().isUnderAttack()) return State.IN_COMBAT; //if nothing is happening, set to idle return State.IDLE; } @Override public int onLoop() throws InterruptedException { switch (getstate()) { case IN_COMBAT: break; case ATTACKING_GOBLIN: log("Start killing a goblin!"); killingGoblin(); break; } return random(100,300); } @Override public void onExit() { log("Thanks for using gusegger's bot!"); } @Override public void onPaint(Graphics2D g) { //NYI } } 3 Quote Link to comment Share on other sites More sharing options...
Token Posted September 5, 2015 Share Posted September 5, 2015 Try deleting the Goblin.getHealth() != 0. I'm not sure but I think you can only check their health if they are already in combat which is not the case. 1 Quote Link to comment Share on other sites More sharing options...
Dark Magician Posted September 9, 2015 Share Posted September 9, 2015 (edited) It's because you need to have sleep functions / return random values. Also a big help is to run the console, and find if there are any errors while running the script. This can cause the client to freeze like you have said. Edited September 9, 2015 by Dark Magician Quote Link to comment Share on other sites More sharing options...