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
  • Script noob needing help


    TheHinges

    Recommended Posts

    As the title states I am a total noob when it comes to scripting/coding. I have been watching the videos and reading the info here on the site and on a few others and have been able to get most of the way through my script (with help from @Hashtag  :wub:

    If anyone would mind taking a look at this and giving me a few pointers or helping explain why line 12 with the BANK_AREA isn't working I would be most appreciative! Feel free to post here or PM me :)

    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.items.Item;
    
    @ScriptManifest(author = "TheHinges", category = Category.MISC, name = "Crystal_Keyz", version = 1.0)
    public class CrystalKeyz extends AbstractScript {
    
    	private final Area BANK_AREA = new Area();
    
    	private State state;
    
    	private enum State {
    		BANK, COMBINE, WAIT;
    
    	}
    
    	private State getState() {
    		if (getBank().isOpen())
    			return State.BANK;
    		if (getInventory().getEmptySlots() == 28)
    			return State.COMBINE	;
    		return State.WAIT;
    
    	}
    
    
    	public void onStart() {
    
    	}
    
    	@Override
    	public int onLoop() {
    		state = getState();
    		switch (state) {
    		case BANK:
    			log("on bank");
    			GameObject bank = getGameObjects().closest("Bank booth");
    			if (!getBank().isOpen()) {
    				bank.interact("Bank");
    			}
    			if (getBank().isOpen()) {
    				getBank().depositAllItems();
    				sleep(Calculations.random(200, 400));
    				getBank().withdraw(2414, 14);
    				sleep(Calculations.random(200, 400));
    				getBank().withdraw(2415, 14);
    				getBank().close();
    
    			}
    			sleep(Calculations.random(100, 600));
    			break;
    		case COMBINE:
    			log("Combination");
    			Item tooth = getInventory().get("Tooth Half of Key");
    			if (tooth != null) {
    				if (tooth.useOn("Loop Half of Key")) {
    					sleep(Calculations.random(200, 500));
    				}
    			}
    			break;
    		case WAIT:
    			log("Waiting");
    			sleep(Calculations.random(20000, 25000));
    			break;
    		}
    
    		return Calculations.random(200, 350);
    	}
    }
    
    
    Link to comment
    Share on other sites

    You want to return State.BANK in your getState() method if inventory does not containt half keys. If it does contain, you want to return State.COMBINE

    Link to comment
    Share on other sites

    You need to add position values to your Area object. You can find your player position in the client debugger. First two numbers are northeast tile x, y position(1234,1234), other two are south west tile x, y position( 4567,4567)

    https://dreambot.org/javadocs/org/dreambot/api/methods/map/Area.html#Area-int-int-int-int-

    private final Area BANK_AREA = new Area(1234,1234,4567,4567);
    Link to comment
    Share on other sites

     

    You need to add position values to your Area object. You can find your player position in the client debugger. First two numbers are northeast tile x, y position(1234,1234), other two are south west tile x, y position( 4567,4567)

    https://dreambot.org/javadocs/org/dreambot/api/methods/map/Area.html#Area-int-int-int-int-

    private final Area BANK_AREA = new Area(1234,1234,4567,4567);

     

     

    You want to return State.BANK in your getState() method if inventory does not containt half keys. If it does contain, you want to return State.COMBINE

     

     

    Thank you guys so much!! Can't believe I missed something so silly :P could I just use something along the lines of .getPlayerlocation() or something?

     

    Also showing my noobess here, I have the debugger open but how do I pull my location? 

    I believe the spelling is important, so before you believe your script isnt working the actual names are

    Tooth half of key and Loop half of key

    Nice catch! This case sensitive stuff is really new to me lol

    Link to comment
    Share on other sites

    Click Tools, Debugging, Position: Player

    That should give you something looking like this in the top left corner of your Client

    cef3d5c960206a28fd69b2c522d41f8f.png

    Jesus H. Christ I am just blind.  :wub:

    You want to return State.BANK in your getState() method if inventory does not containt half keys. If it does contain, you want to return State.COMBINE

    Thanks @@Gains didnt realize I had it trying to combine only when my inv was empty lol. does this look more like what I need?:

     

     

    	private State getState() {
    		if (getBank().isOpen())
    			return State.BANK;
    		if (getInventory().getEmptySlots() == 0)
    			return State.COMBINE;
    		if (getInventory().getEmptySlots() == 28)
    			return State.BANK;
    		return State.WAIT;
    
    	}
    
    

     

    You need to add position values to your Area object. You can find your player position in the client debugger. First two numbers are northeast tile x, y position(1234,1234), other two are south west tile x, y position( 4567,4567)

    https://dreambot.org/javadocs/org/dreambot/api/methods/map/Area.html#Area-int-int-int-int-

    private final Area BANK_AREA = new Area(1234,1234,4567,4567);

    So I have the debugger open and can see 3 int numbers (3162, 3489, 0) standing at the ge, why do I not have a 4th number? The script wants 4 numbers, do i just put 0,0 for the 3rd and 4th number?

    Link to comment
    Share on other sites

    Jesus H. Christ I am just blind.  :wub:

    Thanks @@Gains didnt realize I had it trying to combine only when my inv was empty lol. does this look more like what I need?:

     

     

    	private State getState() {
    		if (getBank().isOpen())
    			return State.BANK;
    		if (getInventory().getEmptySlots() == 0)
    			return State.COMBINE;
    		if (getInventory().getEmptySlots() == 28)
    			return State.BANK;
    		return State.WAIT;
    
    	}
    
    

    So I have the debugger open and can see 3 int numbers (3162, 3489, 0) standing at the ge, why do I not have a 4th number? The script wants 4 numbers, do i just put 0,0 for the 3rd and 4th number?

     

    x, y, x, y 0

    Link to comment
    Share on other sites

    2512b7657a9247cc8381099fc61394c2.png

    This, thank you! It makes total sense now seriously.  :wub:

    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.items.Item;
    
    @ScriptManifest(author = "TheHinges", category = Category.MISC, name = "Crystal_Keyz", version = 1.0)
    public class CrystalKeyz extends AbstractScript {
    
    	// private final Area BANK_AREA = new Area(3162, 3489, 0, 0);
    
    	private State state;
    
    	private enum State {
    		DEPOSIT, COMBINE, WAIT, WITHDRAW;
    
    	}
    
    	private State getState() {
    		if (getBank().isOpen())
    			return State.DEPOSIT;
    		if (getInventory().getEmptySlots() == 0)
    			return State.COMBINE;
    		if (getInventory().getEmptySlots() == 28)
    			return State.WITHDRAW;
    		return State.WAIT;
    
    	}
    
    	public void onStart() {
    
    	}
    
    	@Override
    	public int onLoop() {
    		state = getState();
    		switch (state) {
    		case DEPOSIT:
    			log("on bank");
    			GameObject bank = getGameObjects().closest("Bank booth");
    			if (!getBank().isOpen()) {
    				bank.interact("Bank");
    			}
    			if (getBank().isOpen()) {
    				getBank().depositAllItems();
    
    
    			}
    			sleep(Calculations.random(100, 600));
    			break;
    
    		case WITHDRAW:
    			log("Withdrawing");
    			if (!getBank().isOpen()) {
    				bank.interact("Bank");
    			}
    
    			if  (getBank().isOpen()){
    				sleep(Calculations.random(200, 400));
    				getBank().withdraw(2414, 14);
    				sleep(Calculations.random(200, 400));
    				getBank().withdraw(2415, 14);
    				getBank().close();
    
    			
    			sleep(Calculations.random(100, 600));
    			break;
    			
    		case COMBINE:
    				log("Combination");
    				Item tooth = getInventory().get("Tooth Half of Key");
    				if (tooth != null) {
    					if (tooth.useOn("Loop Half of Key")) {
    						sleep(Calculations.random(200, 500));
    					}
    				}
    				break;
    		case WAIT:
    				log("Waiting");
    				sleep(Calculations.random(20000, 25000));
    				break;
    			}
    
    			return Calculations.random(200, 350);
    		}
    

    UPDATE: so the script was now walking to the nearest bank, open, deposit all, close bank and loop. But now have a syntax error but cannot for the life of me find it, Also I Changed and added some of the states and the COMBINE, & WAIT states arent lighting up blue like the others??

    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.