Trunkss Posted October 28, 2015 Share Posted October 28, 2015 Hey guys, I'm trying To make a Thiever bot which Thieves, So far I can make the bot walk to the bank, collect food and start thieving, but once my hp gets low my bot don't eat. here is my code: if(myPlayer().getHealth() <= 30) return State.EAT; case EAT: this.inventory.interact(this.inventory.getSlot("Lobster"), "Eat"); break; no errors, just the bot don't eat. I'm also having trouble getting to check if a door is open and if it isn't getting the bot to open it public final static Area door_tile = new Area(3287, 3172, 3287, 3271); Entity door = objects.closest(door_tile, 6837); if (door.exists()) { log("Opening door."); door.interact("Open"); } else { log("Cannot find door."); The problem I'm having is if it sees the closed door It opens it, then hunts for nearby closed doors, opens them too then crashes once theres no more to open. I've looked through a few help threads but none seem to work Thanks in advance, Sherbie Quote Link to comment Share on other sites More sharing options...
FrostBug Posted October 28, 2015 Share Posted October 28, 2015 (edited) Probably gonna need to see some more of your code. Eating is probably a question of whether you've already returned a different state before executing the health check. Also be aware that getHealth returns a percentage value, not the actual hitpoints. Edited October 28, 2015 by FrostBug Quote Link to comment Share on other sites More sharing options...
Trunkss Posted October 28, 2015 Author Share Posted October 28, 2015 package theiving; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.util.concurrent.TimeUnit; import java.awt.*; @ScriptManifest(author = "Sherbie", info = "My first script", name = "Warrior thiever", version = 0.7, logo = "") public class main extends Script { private int count = 0; private int failed = 0; public int Lobster; private long timeBegan = System.currentTimeMillis(); private long timeRan; private int beginningXP; private int currentXp; private int xpGained; private int xpPerHour; private double nextLevelXp; private double xpTillNextLevel; private long timeTNL; public final static Area door_tile = new Area(3287, 3172, 3287, 3271); final int[] XP_TABLE = { 0, 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154, 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018, 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636, 184040, 203254, 224466, 247886, 273742, 302288, 333804, 368599, 407015, 449428, 496254, 547953, 605032, 668051, 737627, 814445, 899257, 992895, 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068, 2192818, 2421087, 2673114, 2951373, 3258594, 3597792, 3972294, 4385776, 4842295, 5346332, 5902831, 6517253, 7195629, 7944614, 8771558, 9684577, 10692629, 11805606, 13034431, 200000000 }; private Position[] path = { new Position(3290, 3174, 0), new Position(3293, 3178, 0), new Position(3288, 3181, 0), new Position(3281, 3180, 0), new Position(3276, 3175, 0), new Position(3274, 3170, 0), new Position(3270, 3166, 0), }; private Position[] path2 = { new Position(3270, 3166, 0), new Position(3274, 3170, 0), new Position(3276, 3175, 0), new Position(3281, 3180, 0), new Position(3288, 3181, 0), new Position(3293, 3178, 0), new Position(3290, 3174, 0), }; @Override public void onStart() { timeBegan = System.currentTimeMillis(); beginningXP = skills.getExperience(Skill.THIEVING); timeTNL = 0; log("Welcome to Simple Al-Kharid Warrior Pickpocketer"); log("If you experience any issues while running this script please report them to me on the forums."); log("Enjoy the script, gain some thieving levels!."); } private enum State { BANK, STEAL, EAT, WAIT }; private State getState() { if(inventory.isEmptyExcept("Coins")) return State.BANK; Entity warrior = npcs.closest("Al-Kharid warrior"); if (warrior != null) return State.STEAL; if(myPlayer().getHealth() <= 30) return State.EAT; return State.WAIT; } @Override public int onLoop() throws InterruptedException { switch (getState()) { case BANK: Entity door = objects.closest(door_tile, 6837); if (door.exists()) { log("Opening door."); door.interact("Open"); } else { log("Cannot find door."); localWalker.walkPath(path); sleep(random(400, 650)); objects.closest("Bank booth").interact("Bank"); sleep(random(300, 900)); if (getBank().isOpen()) { getBank().withdraw("Lobster", 10); } else { Entity b = objects.closest("Bank booth"); if (b != null && b.exists()) b.interact("Bank"); sleep(random(400, 600)); localWalker.walkPath(path2); } if (door.exists()) { log("Opening door."); door.interact("Open"); } else log("Cannot find door."); } break; case STEAL: Entity warrior = npcs.closest("Al-Kharid warrior"); if(myPlayer().getHeight() > 220) { sleep(random(5000, 7500)); failed = +1; } if (warrior != null) { warrior.interact("Pickpocket"); count = +1; sleep(random(300, 500)); } break; case EAT: this.inventory.interact(this.inventory.getSlot("Lobster"), "Eat"); break; case WAIT: sleep(random(200, 800)); break; } return random(200, 300); } @Override public void onExit() { log("Thanks for running my Thiever!"); } @Override public void onPaint(Graphics2D g) { timeRan = System.currentTimeMillis() - this.timeBegan; currentXp = skills.getExperience(Skill.THIEVING); xpPerHour = (int)( xpGained / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D)); xpGained = currentXp - beginningXP; xpTillNextLevel = nextLevelXp - currentXp; if (xpGained >= 1) { timeTNL = (long) ((xpTillNextLevel / xpPerHour) * 3600000); } super.onPaint(g); g.setColor(Color.WHITE); g.drawString("Start XP: " + beginningXP, 5, 280); g.drawString("Next Level" + ft(timeTNL), 5, 290); g.drawString("XP Gained" + xpGained, 5, 300); g.setColor(Color.GREEN); g.drawString("Pockets Attepmted: " + count, 5, 310); g.drawString(ft(timeRan), 5, 320); g.setColor(Color.ORANGE); g.drawString("Failed: " + failed, 5, 330); } private String ft(long duration) { String res = ""; long days = TimeUnit.MILLISECONDS.toDays(duration); long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration)); long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS .toHours(duration)); long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS .toMinutes(duration)); if (days == 0) { res = (hours + ":" + minutes + ":" + seconds); } else { res = (days + ":" + hours + ":" + minutes + ":" + seconds); } return res; } } I'm a complete noob, so I bet it's terrible.. That's my whole code for it If you see anything that can be done better please let me know aha Quote Link to comment Share on other sites More sharing options...
FrostBug Posted October 28, 2015 Share Posted October 28, 2015 to fix your eating problem, swap these 2 around: if (warrior != null) return State.STEAL; if(myPlayer().getHealth() <= 30) return State.EAT; -> if(myPlayer().getHealth() <= 30) return State.EAT; if (warrior != null) return State.STEAL; Your door problem is probably caused by a typo in the door_tile. public final static Area door_tile = new Area(3287, 3172, 3287, 3271); Are you sure it shouldn't be: public final static Area door_tile = new Area(3287, 3172, 3287, 3171); ? Quote Link to comment Share on other sites More sharing options...
Woody Posted October 28, 2015 Share Posted October 28, 2015 Remember, getHealth will only return to a value if your health bar is visible, if the character is fighting. You can use widgets to get the character's HP; find the correct parent and child id for HP widget and translate the string to an int. 1 Quote Link to comment Share on other sites More sharing options...
Paradox68 Posted October 28, 2015 Share Posted October 28, 2015 just use getSkills().getDynamic(Skill.HITPOINTS); for health. getHealth is ridiculously useless. Quote Link to comment Share on other sites More sharing options...
itzDot Posted October 28, 2015 Share Posted October 28, 2015 (edited) Noob, u need the action to be the first argument and then food for 2nd argumentargument. If u want to interact with the door you don't need the door position, just make it interact with the name of door or its Id the way to check if the door is open or closed u need to check for its orientation, or just use door handler class Edited October 28, 2015 by itzDot Quote Link to comment Share on other sites More sharing options...
FrostBug Posted October 28, 2015 Share Posted October 28, 2015 (edited) Noob, u need the action to be the first argument and then food for 2nd argumentargument. If u want to interact with the door you don't need the door position, just make it interact with the name of door or its Id the way to check if the door is open or closed u need to check for its orientation, or just use door handler class No and no.. When interacting with a door, it's perfectly valid to do it by position, if there are other doors of same name and ID nearby. He won't get the closed doors since those have different ID. ___ The way you're doing the interaction right now is essentially fine, but it would be slightly cleaner and more efficient to use this overload Edited October 28, 2015 by FrostBug Quote Link to comment Share on other sites More sharing options...
itzDot Posted October 28, 2015 Share Posted October 28, 2015 No and no.. When interacting with a door, it's perfectly valid to do it by position, if there are other doors of same name and ID nearby. He won't get the closed doors since those have different ID. ___ The way you're doing the interaction right now is essentially fine, but it would be slightly cleaner and more efficient to use this overload More like yes and no Quote Link to comment Share on other sites More sharing options...
FrostBug Posted October 28, 2015 Share Posted October 28, 2015 More like yes and no ? What's wrong with interaction by slot ID? 1 Quote Link to comment Share on other sites More sharing options...
itzDot Posted October 28, 2015 Share Posted October 28, 2015 ? What's wrong with interaction by slot ID? What's wrong with interact(action, string)? Quote Link to comment Share on other sites More sharing options...
FrostBug Posted October 28, 2015 Share Posted October 28, 2015 What's wrong with interact(action, string)? Nothing, but that doesn't make OP a noob for using something else lol Quote Link to comment Share on other sites More sharing options...
Trunkss Posted October 28, 2015 Author Share Posted October 28, 2015 (edited) to fix your eating problem, swap these 2 around: if (warrior != null) return State.STEAL; if(myPlayer().getHealth() <= 30) return State.EAT; -> if(myPlayer().getHealth() <= 30) return State.EAT; if (warrior != null) return State.STEAL; Your door problem is probably caused by a typo in the door_tile. public final static Area door_tile = new Area(3287, 3172, 3287, 3271); Are you sure it shouldn't be: public final static Area door_tile = new Area(3287, 3172, 3287, 3171); ? switched those two around, it now eats, but it now eats all my lobsters aha.. Also having the same problem with the doors, looks for closed doors, then crashes once its opened the doors just use getSkills().getDynamic(Skill.HITPOINTS); for health. getHealth is ridiculously useless. I used this beforehand but changed it cause it wasn't working, now realised its to do with my cases being the wrong way around, Thanks anyway bro Noob, u need the action to be the first argument and then food for 2nd argumentargument. If u want to interact with the door you don't need the door position, just make it interact with the name of door or its Id the way to check if the door is open or closed u need to check for its orientation, or just use door handler class None of this made any sence to me.. Edited October 28, 2015 by sherbie Quote Link to comment Share on other sites More sharing options...
FrostBug Posted October 28, 2015 Share Posted October 28, 2015 switched those two around, it now eats, but it now eats all my lobsters aha.. Also having the same problem with the doors, looks for closed doors, then crashes once its opened the doors I used this beforehand but changed it cause it wasn't working, now realised its to do with my cases being the wrong way around, Thanks anyway bro None of this made any sence to me.. The reason it eats all of your food is because getHealth() isn't updated outside of combat (so your 'health' will stay the same if you eat outside of combat). use something like this if you still want percentage: public int getHealthPercent() { int max = getSkills().getStatic(Skill.HITPOINTS); int dyn = getSkills().getDynamic(Skill.HITPOINTS); return (100 / max) * dyn; } Also, the reason you're getting an error is because you aren't nullchecking the door. if (door.exists()) { log("Opening door."); door.interact("Open"); } else { log("Cannot find door."); -> if (door != null && door.exists()) { log("Opening door."); door.interact("Open"); } else { log("Cannot find door."); 1 Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted October 28, 2015 Share Posted October 28, 2015 In your code, you also expect that your door is going to have the action "Open". Now yes, you search for ID, but have something like this: Entity door = getObjects().closest(door_tile, 6837); if (door != null && door.exists() && door.hasAction("Open")) door.interact("Open"); Quote Link to comment Share on other sites More sharing options...