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
  • Checking if an area contains a specified string


    UberJason

    Recommended Posts

    Since the script I'm trying to make isn't all that special and being my first script, if it'll help I'll share the current source in a bit after some more fiddling. I'm trying to make a muling script. Currently, I have it set to be able to walk to its destination, the GE if it currently isn't already there. That isn't an issue and seems to work just fine. I also have a dialog pop up that stores a players name to trade as a string, and I'm trying to get it to interact with the player by that name if in the area, but I'm not sure what the correct way to check if that player exists. Here's what I have for this right now which is wrong: if (tradeArea.contains(nameToTrade)) - if not contains, what else could I use to check a string in an area?

    Link to comment
    Share on other sites

    Meh, I've got nothing to hide. Still worth noting that this is going to be my first script so please no hurt. ;-; It seems not to work correctly anyway, so here's what I've got:

     

    import javax.swing.JOptionPane;
    
    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;
    
    @ScriptManifest(author = "4ng1f1sh", name = "Muler", version = 1.0, description = "Muler", category = Category.MONEYMAKING)
    
    public class Main extends AbstractScript {
    	
    	String nameToTrade;
        private final Area tradeArea = new Area(3160, 3487, 3169, 3481);
    
    	public void onStart() {
    		nameToTrade = JOptionPane.showInputDialog("Enter name of person to trade");
    	}
        
        @Override
        public int onLoop() {
            if (tradeArea.contains(getLocalPlayer())) {
            	log("AFKing at Grand Exchange");
            } else {
            	log("Walking to Grand Exchange");
                getWalking().walk(tradeArea.getRandomTile());
                sleep(Calculations.random((int) 1250.3000));
            }
            if (tradeArea.equals(nameToTrade)) {	
                getTrade().tradeWithPlayer(nameToTrade);
            	sleep(5000);
            	getTrade().acceptTrade(1);
            	sleep(5000);
            	getTrade().acceptTrade(2);
            } else {
            	log("Player not in trade area");
            }
            return 500;
        }
    
        public int onEnd() {
            return 0;
        }
    
    }

     

    Link to comment
    Share on other sites

    Hey,

    To check if player exists in yours area, you can iterate over every player in the area, just replace "name" with the name of a player you try to find.

    getPlayers().all().stream().anyMatch(player -> player != null && player.getName().equalsIgnoreCase(name))
    Link to comment
    Share on other sites

    Ok, update. Now I'm trying to get it to click accept. Nothing I've tried is working. Here's what I've got now: 

    import java.awt.Rectangle;
    
    import javax.swing.JOptionPane;
    
    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;
    
    @ScriptManifest(author = "4ng1f1sh", name = "Muler", version = 1.0, description = "Muler", category = Category.MONEYMAKING)
    
    public class Main extends AbstractScript {
    	
    	String nameToTrade;
        private final Area tradeArea = new Area(3160, 3487, 3169, 3481);
    
    	public void onStart() {
    		nameToTrade = JOptionPane.showInputDialog("Name of slave");
    	}
        
        @Override
        public int onLoop() {
            if (!tradeArea.contains(getLocalPlayer())) {
            	getWalking().walk(tradeArea.getRandomTile());
            } else if (tradeArea.contains(getLocalPlayer())) {
            	getTrade().tradeWithPlayer(nameToTrade);
            	sleep(Calculations.random(500, 1000));
            } else if (getTrade().isOpen()) {
            	sleep(100, 500);
            	getMouse().click(new Rectangle(228, 195, 287, 196));
            	sleep(Calculations.random(100, 250));
            	getMouse().click(new Rectangle(228, 195, 287, 196));
            } else {
    
            }
            return Calculations.random(1250, 3500);
        }
        public int onEnd() {
            return 0;
        }
    }

    What I'm now not understanding is why it ain't clicking those rectangles I have set. I thought that'd for sure work. 

    Link to comment
    Share on other sites

    2 minutes ago, Leanche said:

    Hey,

    To check if player exists in yours area, you can iterate over every player in the area, just replace "name" with the name of a player you try to find.

    
    getPlayers().all().stream().anyMatch(player -> player != null && player.getName().equalsIgnoreCase(name))

    Interesting. Thanks! :) I've already done away with trying to do something based on whether the target player is in the area, but with that I might try doing so again. 

    Link to comment
    Share on other sites

    With the mouse clicks, you can either increase Sleep Time, or try using

    sleepUntil(() -> getMouse().click(new Rectangle(228, 195, 287, 196)), 5000);
    

     

    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.