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
  • Butchered my entire script after threads, any insight?


    brbxd

    Recommended Posts

    package org.dreambot.brbXD;
    
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.map.Tile;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.script.listener.MessageListener;
    import org.dreambot.api.utilities.Timer;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.interactive.NPC;
    import org.dreambot.api.wrappers.widgets.message.Message;
    
    @ScriptManifest(category = Category.COMBAT, name = "RockCrabsBRB", author = "BrbXD", version = 1.0)
    
    public class RockCrabsMain extends AbstractScript implements MessageListener {
    
    	// class EatingThread implements Runnable {
    	//
    	// @Override
    	// public void run() {
    	// if (getInventory().contains("Tuna")) {
    	// getInventory().interact("Tuna", "Eat");
    	// }
    	//
    	// }
    	//
    	// }
    
    	Area crabArea = new Area(2693, 3730, 2715, 3714);
    	Area resetArea = new Area(2695, 3704, 2709, 3700);
    	Tile cannonTile = new Tile(2709, 3721, 0);
    
    	public int cannonballTimer = 0;
    	public Timer time;
    
    	@Override
    	public void onStart() {
    		time = new Timer();
    	}
    
    	@Override
    	public int onLoop() {
    
    		// // Health check.
    		// if (getLocalPlayer().getHealthPercent() <= 35) {
    		// EatingThread eat = new EatingThread();
    		// Thread eatThread = new Thread(eat);
    		// eatThread.start();
    		// }
    
    		// Food check.
    		if (!getInventory().contains("Tuna")) {
    			pickupCannon();
    			getWalking().walk(resetArea.getRandomTile());
    		}
    		if (resetArea.contains(getLocalPlayer()) && !getInventory().contains("Tuna")) {
    			sleep(10000, 15000);
    			getTabs().logout();
    			stop();
    		}
    
    		// Cannonball check.
    		if (!getInventory().contains("Cannonball")) {
    			if (!resetArea.contains(getLocalPlayer())) {
    				getWalking().walk(resetArea.getRandomTile());
    			} else {
    				sleep(10000, 15000);
    				getTabs().logout();
    			}
    		}
    
    		// Set-up cannon.
    		if (getInventory().contains("Cannon base") && getLocalPlayer().getHealthPercent() > 40
    				&& getInventory().contains("Tuna")) {
    			if (cannonTile.distance(getLocalPlayer()) != 0) {
    				getWalking().walk(cannonTile);
    				sleep(1500, 3000);
    			} else {
    				getInventory().interact("Cannon base", "Set-up");
    				sleep(8000, 10000);
    				GameObject cannon = getGameObjects().closest("Dwarf multicannon");
    				if (cannon != null && (int) cannonTile.distance(cannon) <= 3) {
    					cannon.interact("Fire");
    				}
    			}
    		}
    
    		// Run around :).
    		if (!getInventory().contains("Cannon base")) {
    			log("Doing something");
    			cannonballTimer++;
    			log(Integer.toString(cannonballTimer));
    			if (cannonballTimer > 20) {
    				fillCannon();
    			}
    			NPC nextCrab = getNpcs()
    					.closest(rocks -> rocks != null && rocks.getName().contains("Rocks") && crabArea.contains(rocks));
    			if (nextCrab != null) {
    				getWalking().walk(nextCrab.getTile());
    			} else {
    				if (cannonTile.distance(getLocalPlayer()) != 0) {
    					getWalking().walk(cannonTile);
    					sleep(1000, 3000);
    					return 0;
    				} else {
    					sleep(1000);
    					return 0;
    				}
    			}
    			sleep(500, 1000);
    			if (getWalking().getDestination() != null) {
    				sleepUntil(() -> getWalking().getDestination().distance(getLocalPlayer()) < 3, 4000);
    			}
    		}
    
    		return 0;
    	}
    
    	private void fillCannon() {
    		if (!getWalking().isRunEnabled()) {
    			getWalking().toggleRun();
    		}
    		if (cannonTile.distance(getLocalPlayer()) > 8) {
    			getWalking().walk(cannonTile);
    			sleepUntil(() -> cannonTile.distance(getLocalPlayer()) < 8, 10000);
    		}
    		if (cannonTile.distance(getLocalPlayer()) < 8) {
    			GameObject cannon = getGameObjects().closest("Dwarf multicannon");
    			if (cannon != null && (int) cannonTile.distance(cannon) <= 3) {
    				cannon.interact("Fire");
    				sleep(9000, 10000);
    			}
    		}
    		cannonballTimer = 0;
    	}
    
    	private void pickupCannon() {
    		if (!getWalking().isRunEnabled()) {
    			getWalking().toggleRun();
    		}
    		if (cannonTile.distance(getLocalPlayer()) > 8) {
    			getWalking().walk(cannonTile);
    			sleepUntil(() -> cannonTile.distance(getLocalPlayer()) < 8, 10000);
    		}
    		if (cannonTile.distance(getLocalPlayer()) < 8) {
    			GameObject cannon = getGameObjects().closest("Dwarf multicannon");
    			if (cannon != null && (int) cannonTile.distance(cannon) <= 3) {
    				cannon.interact("Pick-up");
    				sleepUntil(() -> getInventory().contains("Cannon base"), 15000);
    			}
    		}
    	}
    
    	@Override
    	public void onGameMessage(Message arg0) {
    		if (arg0.getMessage().contains("Your cannon is out of ammo!")) {
    			fillCannon();
    		}
    	}
    
    	@Override
    	public void onPlayerMessage(Message arg0) {
    		// TODO Auto-generated method stub
    
    	}
    
    	@Override
    	public void onPrivateInMessage(Message arg0) {
    		// TODO Auto-generated method stub
    
    	}
    
    	@Override
    	public void onPrivateOutMessage(Message arg0) {
    		// TODO Auto-generated method stub
    
    	}
    
    	@Override
    	public void onTradeMessage(Message arg0) {
    		// TODO Auto-generated method stub
    
    	}
    
    	@Override
    	public void run() {
    		// TODO Auto-generated method stub
    
    	}
    
    }

    Hey guys/gals, so I had my script running just fine before I started coding in the threading parts that are now commented out. Once I put those in for some reason my script won't even start. I thought it had something to do with brackets being messed up but it all seems to check out there.

    If you guys have any insight please let me know so I can finish this damn script! :)

    Thanks!

    Link to comment
    Share on other sites

    Okay I actually just checked and it isn't this specific script. It's client side because none of my scripts are running. I've restarted my client and done fresh start. What other steps can I take?

    Link to comment
    Share on other sites

    12 minutes ago, brbxd said:

    Okay I actually just checked and it isn't this specific script. It's client side because none of my scripts are running. I've restarted my client and done fresh start. What other steps can I take?

    Try running fresh start.

    Also, do not have actions in your listener thread, it will create tons of problems... make it switch a boolean on your main loop to do that action then set it false after it's done.

    Example of what not to do 

    	@Override
    	public void onGameMessage(Message arg0) {
    		if (arg0.getMessage().contains("Your cannon is out of ammo!")) {
    			fillCannon();// Instead do: fillcannon = true;
    		}
    	}
    Link to comment
    Share on other sites

    theres almost nothing u should be using threads for while scripting. 

     

    They should only ever be used for purely observational tasks.   You can only do 1 interaction at a time so theres no reason for it to be concurrent.  Even for observational tasks, their use is niche.  off the top of my head, the only common situations you should use threads are counting zulrah jad phase attacks or pk detection. however,  zulrah form counting should not be on a separate thread as it adds no value. 

    Link to comment
    Share on other sites

    13 hours ago, Koschei said:

    Try running fresh start.

    Also, do not have actions in your listener thread, it will create tons of problems... make it switch a boolean on your main loop to do that action then set it false after it's done.

    Example of what not to do 

    
    	@Override
    	public void onGameMessage(Message arg0) {
    		if (arg0.getMessage().contains("Your cannon is out of ammo!")) {
    			fillCannon();// Instead do: fillcannon = true;
    		}
    	}

    I tried fresh start multiple times, deleted DreamBot folder and launcher and re-downloaded. Still, no progress. Also, thanks for the note on the listener thread I'll fix that up.

     

    6 hours ago, dQw4w9WgXcQ said:

    theres almost nothing u should be using threads for while scripting. 

     

    They should only ever be used for purely observational tasks.   You can only do 1 interaction at a time so theres no reason for it to be concurrent.  Even for observational tasks, their use is niche.  off the top of my head, the only common situations you should use threads are counting zulrah jad phase attacks or pk detection. however,  zulrah form counting should not be on a separate thread as it adds no value. 

    I completely understand where you're coming from and I don't think you're wrong. I've come to realize this isn't the problem though, I'm having a problem starting my script let alone any script. This doesn't have to do with threading anymore I don't believe.

    Link to comment
    Share on other sites

    If it helps at all, even with an account selected and a script chosen and ran the login solver used by the client won't even boot.

    Link to comment
    Share on other sites

    3 minutes ago, brbxd said:

    I tried fresh start multiple times, deleted DreamBot folder and launcher and re-downloaded. Still, no progress. Also, thanks for the note on the listener thread I'll fix that up.

     

    I completely understand where you're coming from and I don't think you're wrong. I've come to realize this isn't the problem though, I'm having a problem starting my script let alone any script. This doesn't have to do with threading anymore I don't believe.

    Try removing, not sure why it's there.  

    @Override
    	public void run() {
    		// TODO Auto-generated method stub
    
    	}
    Link to comment
    Share on other sites

    16 minutes ago, Koschei said:

    Try removing, not sure why it's there.  

    
    @Override
    	public void run() {
    		// TODO Auto-generated method stub
    
    	}

    Jesus Christ.... I couldn't tell you why that was there but it fixed everything deleting it.

    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.