aeondenied Posted June 11, 2016 Share Posted June 11, 2016 /** * @(#)Smither.java * * * @author Construct Dylons * @version 1.00 2016/6/10 */ import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.input.mouse.EntityDestination; import org.osbot.rs07.input.mouse.MiniMapTileDestination; import org.osbot.rs07.utility.Area; import java.awt.*; @ScriptManifest(author = "Construct Dylons", info = "Not So Basic Smither.", name = "Smither", version = 0, logo = "") public class Smither extends Script{ private static final Area SMITHING_AREA = new Area(3185,3420,3190,3427); private static final String useItem = "Iron bar"; private static final String itemMade = "Iron knife"; private static final int xCo = 370; private static final int yCo = 180; private enum State{ SMITH, BANK, WALK_TO_SMITH, WALK_TO_BANK }; private State getState(){ if(inventory.contains(useItem) && SMITHING_AREA.contains(myPlayer().getPosition())){ return State.SMITH; } else if(!inventory.contains(useItem) && !SMITHING_AREA.contains(myPlayer().getPosition())){ return State.BANK; } else if(inventory.contains(useItem) && !SMITHING_AREA.contains(myPlayer().getPosition())){ return State.WALK_TO_SMITH; } else{ return State.WALK_TO_BANK; } } public int onLoop() throws InterruptedException{ switch(getState()){ case SMITH: outerIf: if(!myPlayer().isAnimating()){ sleep(1000); if(!inventory.contains(useItem)){ sleep(500); break outerIf; } int failSafe = 0; while(!myPlayer().isAnimating()){ sleep(50); failSafe++; if(failSafe >= 10){ inventory.interactWithNameThatContains("Use", useItem); RS2Object anvil = objects.closest(2097); mouse.click(new EntityDestination(bot, anvil)); if(interfaces.get(312) != null){ } sleep(1500); mouse.move(xCo,yCo); mouse.click(true); sleep(250); mouse.move(365,250); mouse.click(false); sleep(1000); keyboard.typeString("27"); sleep(500); break outerIf; } } } break; case BANK: RS2Object bankBooth = objects.closest("Bank booth"); if (bankBooth != null) { if (bankBooth.interact("Bank")) { while(!bank.isOpen()){ sleep(250); } bank.depositAll(itemMade); if(bank.contains(useItem)){ bank.withdraw(useItem, 27); } else{ stop(); } bank.close(); } } break; case WALK_TO_BANK: walkTile(new Position(3185,3436,0)); break; case WALK_TO_SMITH: walkTile(new Position(3185,3426,0)); break; } return random(200,300); } private boolean walkTile(Position p) throws InterruptedException { mouse.move(new MiniMapTileDestination(bot, p), false); sleep(random(150, 250)); mouse.click(false); int failsafe = 0; while (failsafe < 10 && myPlayer().getPosition().distance(p) > 2) { sleep(200); failsafe++; if (myPlayer().isMoving()) failsafe = 0; } if (failsafe == 10) return false; return true; } public void onPaint(Graphics2D g) { } } 1 Quote Link to comment Share on other sites More sharing options...
Token Posted June 11, 2016 Share Posted June 11, 2016 Try looking at the ConditionalSleep class, which you should use until the dialogue box is open. A static 1000 ms sleep will not always guarantee that this opened, a simple lag will cause it not to appear within 1 tick (600-630 ms) which will result in typing in the chatbox. You can also replace those mouse moves and clicks with a right click on a WidgetDestination and then select a menu option via the Menu class. Quote Link to comment Share on other sites More sharing options...
Strange_Fk Posted June 14, 2016 Share Posted June 14, 2016 (edited) As he has stated above, use widget debugger to find a widget ID that pertains specifically to the box that you intend on the bot to type in. So that way if the widget is not visible or is null then it will not type until it is visible or !null. For example: if (widgets.get(162, 32) !=null && widgets.get(162, 32).isVisible()) { keyboard.typeString("28"); } Edited June 14, 2016 by Strange_Fk Quote Link to comment Share on other sites More sharing options...