Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Widgets


    Kristoffer

    Recommended Posts

    Could someone take a look at my code and point me in the right direction as to where I'm doing things incorrectly because this code isn't detecting the widgets I want to detect.

    public class Smelt {
    	
    	Area furnaceArea = new Area(2970, 3368, 2974, 3375);
    
    	public Smelt(AbstractScript script) {
    		
    		if (furnaceArea.contains(script.getPlayers().myPlayer())) {
    			
    			if (script.getPlayers().myPlayer().getAnimation() == -1) {
    				
    				if (!script.getPlayers().myPlayer().isMoving()) {
    					
    					GameObject furnace = script.getGameObjects().getClosest("Furnace");
    					
    					if (furnace != null && furnace.isOnScreen()) {
    						
    						if (script.getWidgets().getWidgetChildrenContainingText("Smelt X").isEmpty() && furnace.interact("Smelt")) {
    							MethodProvider.log("No widget containing 'Smelt X' detected");
    							MethodProvider.sleepUntil(() -> !script.getWidgets().getWidgetChildrenContainingText("Smelt X").isEmpty(), 500);
    						}	
    						
    						if (!script.getWidgets().getWidgetChildrenContainingText("Smelt X").isEmpty()) {
    							MethodProvider.log("Widget containing 'Smelt X' detected");
    							WidgetChild first = script.getWidgets().getWidgetChildrenContainingText("Smelt").get(0);
    							
    							if (first != null && first.interact("Smelt X")) {
    								
    								MethodProvider.sleepWhile(() -> script.getInventory().contains("Copper ore"), 500);
    								
    							}
    						}
    					}
    				}	
    			}	
    		}
    	}
    }
    

    Somewhat based on this source file: https://github.com/notoriouspp/OpenSource-Cooking/blob/master/src/cook/tasks/cook/Cook.java

     

    I've tried things like

    script.getWidgets().getWidget(int).getChild(int).isVisible();
    

    to detect widgets as well but it just kept throwing null pointer exceptions.

     

    Any suggestions?

    Link to comment
    Share on other sites

    Smelt X isn't in a widget, it's a menu action (right?).

     

    getWidgetChildrenContainingText returns widgets that have that in the text, not as their actions, and we don't return empty lists (just null).

     

    Could I get your full stack trace?

    Link to comment
    Share on other sites

    Could someone take a look at my code and point me in the right direction as to where I'm doing things incorrectly because this code isn't detecting the widgets I want to detect.

    public class Smelt {
    	
    	Area furnaceArea = new Area(2970, 3368, 2974, 3375);
    
    	public Smelt(AbstractScript script) {
    		
    		if (furnaceArea.contains(script.getPlayers().myPlayer())) {
    			
    			if (script.getPlayers().myPlayer().getAnimation() == -1) {
    				
    				if (!script.getPlayers().myPlayer().isMoving()) {
    					
    					GameObject furnace = script.getGameObjects().getClosest("Furnace");
    					
    					if (furnace != null && furnace.isOnScreen()) {
    						
    						if (script.getWidgets().getWidgetChildrenContainingText("Smelt X").isEmpty() && furnace.interact("Smelt")) {
    							MethodProvider.log("No widget containing 'Smelt X' detected");
    							MethodProvider.sleepUntil(() -> !script.getWidgets().getWidgetChildrenContainingText("Smelt X").isEmpty(), 500);
    						}	
    						
    						if (!script.getWidgets().getWidgetChildrenContainingText("Smelt X").isEmpty()) {
    							MethodProvider.log("Widget containing 'Smelt X' detected");
    							WidgetChild first = script.getWidgets().getWidgetChildrenContainingText("Smelt").get(0);
    							
    							if (first != null && first.interact("Smelt X")) {
    								
    								MethodProvider.sleepWhile(() -> script.getInventory().contains("Copper ore"), 500);
    								
    							}
    						}
    					}
    				}	
    			}	
    		}
    	}
    }
    

    Somewhat based on this source file: https://github.com/notoriouspp/OpenSource-Cooking/blob/master/src/cook/tasks/cook/Cook.java

     

    I've tried things like

    script.getWidgets().getWidget(int).getChild(int).isVisible();
    

    to detect widgets as well but it just kept throwing null pointer exceptions.

     

    Any suggestions?

     

     

    Smelt X isn't in a widget, it's a menu action (right?).

     

    getWidgetChildrenContainingText returns widgets that have that in the text, not as their actions, and we don't return empty lists (just null).

     

    Could I get your full stack trace?

    Ignore Pan on his middle statement. We do return empty lists, not null for that function. >_>

     

    We'd have to see your stack trace for the NPE to give you any advice on that.

     

    furnace.interact might not be returning true, I know we had an issue with that previously and I'm not sure if it's been fixed. Try testing that?

    Otherwise as Pan said, "Smelt X" isn't part of the text of the widget, it's an action. So there's that, too.

     

    script.getWidgets().getWidget(int).getChild(int).isVisible();

     

    If the parent widget is null, you'll get an NPE.

    If the child is null, you'll get an NPE.

    I'd suggest more null checks. If the parent does not exist when you try to get it (when furnace isn't open), it will probably be null.

    You should add null checks. 

    Link to comment
    Share on other sites

    Changed the code a bit:

    public class Smelt {
    
    	Area furnaceArea = new Area(2970, 3368, 2974, 3375);
    
    	public Smelt(AbstractScript script) {
    			
    		if (furnaceArea.contains(script.getPlayers().myPlayer())) {
    			
    			if (!script.getPlayers().myPlayer().isMoving()) {
    				
    				if (script.getPlayers().myPlayer().getAnimation() == -1) {
    					
    					GameObject furnace = script.getGameObjects().getClosest("Furnace");
    					
    					if (furnace.interact("Smelt")) {
    						
    						AbstractScript.sleepUntil(new Condition() {
    
    							@Override
    							public boolean verify() {
    								return !script.getWidgets().getWidgetChildrenContainingText("What would you like to smelt?").isEmpty();
    							}
    							
    						}, 1000);
    						
    						try {
    							if (!script.getWidgets().getWidgetChildrenContainingText("What would you like to smelt?").isEmpty()) {
    								
    								WidgetChild child = script.getWidgets().getWidgetChildrenContainingText("Bronze").get(0);
    								if (child != null) {
    									child.interact("Smelt X");
    								}
    							} 
    						} catch (IndexOutOfBoundsException e){
    							e.printStackTrace();
    						}
    	
    					}
    					
    				}
    				
    			}
    			
    		}
    
    	}
    
    }
    

    As you can see it's not interacting with the bronze bar widget: http://gyazo.com/397985f22f83ae85bb38cc767d1589e4

    Link to comment
    Share on other sites

    The stack trace prints in the cmd window if you run the client through cmd.

     

    I'd suggest running the client through cmd to see if it throws any errors.

    You could also log to make sure the interact is getting hit which I assume it is because it moves to the widget.

    So the action might be wrong.

     

    I'll take a look later today as well.

    Link to comment
    Share on other sites

    Just tried running it through cmd and I'm getting this error: 

     

    java.lang.IllegalArgumentException: Can not set int field cb.w to cc
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
    at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(Unknown Source)
    at sun.reflect.UnsafeIntegerFieldAccessorImpl.getInt(Unknown Source)
    at sun.reflect.UnsafeIntegerFieldAccessorImpl.get(Unknown Source)
    at java.lang.reflect.Field.get(Unknown Source)
    at org.dreambot.core.b.a.b.a(b.java:47)
    at org.dreambot.core.b.a.b.a(b.java:40)
    at org.dreambot.api.wrappers.interactive.GameObject.getID(GameObject.java:71)
    at org.dreambot.api.wrappers.interactive.GameObject.getRealID(GameObject.java:115)
    at org.dreambot.api.wrappers.interactive.GameObject.getComposite(GameObject.java:125)
    at org.dreambot.api.wrappers.interactive.GameObject.getName(GameObject.java:145)
    at org.dreambot.api.methods.filter.impl.NameFilter.match(NameFilter.java:30)
    at org.dreambot.api.methods.filter.impl.NameFilter.match(NameFilter.java:19)
    at org.dreambot.api.methods.interactive.GameObjects.lambda$closest$40(GameObjects.java:160)
    at org.dreambot.api.methods.interactive.GameObjects$$Lambda$540/1724023880.test(Unknown Source)
    at java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    at java.util.stream.ReferencePipeline.forEach(Unknown Source)
    at org.dreambot.api.methods.interactive.GameObjects.closest(GameObjects.java:160)
    at org.dreambot.api.methods.interactive.GameObjects.getClosest(GameObjects.java:141)
    at tasks.Smelt.<init>(Smelt.java:21)
    at core.Smelter.onLoop(Smelter.java:19)
    at org.dreambot.api.script.AbstractScript.run(AbstractScript.java:167)
    at java.lang.Thread.run(Unknown Source)
     
    Pretty sure it doesn't have anything to do with widgets this time.
    Link to comment
    Share on other sites

    This should work:

    		public class Smelt {
    
    			Area furnaceArea = new Area(2970, 3368, 2974, 3375);
    
    			public Smelt(AbstractScript script) {
    					
    				if (furnaceArea.contains(script.getPlayers().myPlayer())) {
    					
    					if (!script.getPlayers().myPlayer().isMoving()) {
    						
    						if (script.getPlayers().myPlayer().getAnimation() == -1) {
    							
    							GameObject furnace = script.getGameObjects().closest("Furnace");
    							
    							if (furnace.interact("Smelt")) {
    								
    								AbstractScript.sleepUntil(new Condition() {
    
    									@Override
    									public boolean verify() {
    										return !script.getWidgets().getWidgetChildrenContainingText("What would you like to smelt?").isEmpty();
    									}
    									
    								}, 1000);
    								
    								try {
    									if (!script.getWidgets().getWidgetChildrenContainingText("What would you like to smelt?").isEmpty()) {
    										
    										WidgetChild child = script.getWidgets().getWidgetChildrenContainingText("Bronze").get(0);
    										if (child != null) {
    											Rectangle rect = new Rectangle(child.getRectangle().x, child.getRectangle().y, child.getRectangle().width-1, 67);
    											script.getMouse().move(rect, script.getMouse().getMouseSettings());
    											script.sleep(500);
    											script.getMouse().click(true);
    											sleep(500);
    											script.getClient().getMenu().clickAction("Smelt X Bronze");
    										}
    									} 
    								} catch (IndexOutOfBoundsException e){
    									e.printStackTrace();
    								}
    			
    							}
    							
    						}
    						
    					}
    					
    				}
    
    			}
    
    		}
    
    Link to comment
    Share on other sites

     

    Just tried running it through cmd and I'm getting this error: 

     

    java.lang.IllegalArgumentException: Can not set int field cb.w to cc
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
    at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(Unknown Source)
    at sun.reflect.UnsafeIntegerFieldAccessorImpl.getInt(Unknown Source)
    at sun.reflect.UnsafeIntegerFieldAccessorImpl.get(Unknown Source)
    at java.lang.reflect.Field.get(Unknown Source)
    at org.dreambot.core.b.a.b.a(b.java:47)
    at org.dreambot.core.b.a.b.a(b.java:40)
    at org.dreambot.api.wrappers.interactive.GameObject.getID(GameObject.java:71)
    at org.dreambot.api.wrappers.interactive.GameObject.getRealID(GameObject.java:115)
    at org.dreambot.api.wrappers.interactive.GameObject.getComposite(GameObject.java:125)
    at org.dreambot.api.wrappers.interactive.GameObject.getName(GameObject.java:145)
    at org.dreambot.api.methods.filter.impl.NameFilter.match(NameFilter.java:30)
    at org.dreambot.api.methods.filter.impl.NameFilter.match(NameFilter.java:19)
    at org.dreambot.api.methods.interactive.GameObjects.lambda$closest$40(GameObjects.java:160)
    at org.dreambot.api.methods.interactive.GameObjects$$Lambda$540/1724023880.test(Unknown Source)
    at java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    at java.util.stream.ReferencePipeline.forEach(Unknown Source)
    at org.dreambot.api.methods.interactive.GameObjects.closest(GameObjects.java:160)
    at org.dreambot.api.methods.interactive.GameObjects.getClosest(GameObjects.java:141)
    at tasks.Smelt.(Smelt.java:21)
    at core.Smelter.onLoop(Smelter.java:19)
    at org.dreambot.api.script.AbstractScript.run(AbstractScript.java:167)
    at java.lang.Thread.run(Unknown Source)
     
    Pretty sure it doesn't have anything to do with widgets this time.

     

     

    That's been fixed, restart and you'll be fine :)

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.