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
  • Try asking for help in the chatbox
  • Errors when starting script


    MachineAIExp
     Share

    Recommended Posts

    Hello to all!

    I have a problem with my following code, where the initialization causes errors, maybe someone who can assist?

    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.container.impl.bank.BankLocation;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;

    @ScriptManifest(author = "TheHacker", description = "Ge Trading", name = "GETrader", category = Category.MAGIC, version = 1)
    public class GETrader extends AbstractScript{

        State state;
        int COINS = 995; //gets COINS Item ID
        BankLocation GEBank = BankLocation.GRAND_EXCHANGE;
        int upperprice = 2000;
        int lowerprice = 1;
        
        @Override //Infinite loop
        public int onLoop() {
            
            //Determined by which state gets returned by getState() then do that case.
            switch(getState()) {
            case MARGINCHECK:
                log("Checking the Margins");
                
                fetchFunds();
                
                if (getGrandExchange().isGeneralOpen()) {
                    getGrandExchange().openBuyScreen(1);
                    getGrandExchange().searchItem("Lobster");
                    getGrandExchange().buyItem("Lobster", 1, upperprice);
                    getGrandExchange().goBack();
                    sleep(Calculations.random(1000, 5000));
                 }
                
                if (getGrandExchange().isReadyToCollect(1)) {
                    getGrandExchange().collect();
                    getGrandExchange().goBack();
                    sleep(Calculations.random(1000, 5000));
                }
                
                if (getInventory().contains("Lobster")); {
                    getGrandExchange().openSellScreen(1);
                    getGrandExchange().sellItem("Lobster", 1, lowerprice);
                    getGrandExchange().goBack();
                    sleep(Calculations.random(1000, 5000));
                }
                
                if (getGrandExchange().isReadyToCollect(1)) {
                    getGrandExchange().collect();
                    getGrandExchange().goBack();
                    sleep(Calculations.random(1000, 5000));
                }
                
                break;
            }
            return 0;
        }
        
        //State names
        private enum State{
            MARGINCHECK
        }
        
        //Checks if a certain condition is met, then return that state.
        private State getState() {
            if (GEBank.getArea(5).contains(getLocalPlayer()) && getGrandExchange().isOpen() == false) {
                getGrandExchange().open("Exchange");
            }
            if (GEBank.getArea(5).contains(getLocalPlayer()) && getGrandExchange().isGeneralOpen()) {
                state = State.MARGINCHECK;
            }
            return state;
        }
        
        private void fetchFunds() { //Only regarding the Buying state

            if(!getInventory().contains(COINS)) { //checks if the inventory contains COINS
                getBank().openClosest(); //Opens closest bank, you can set it to open(GEBank) if you want.
                getBank().withdrawAll(COINS); // withdraws all coins, you can set it to withdraw(COINS, int quantity) if you want.
                getBank().close(); //closes bank interface
            }

        }
        
        //When script start load this.
        public void onStart() {
            log("Bot Started");
        }
        
        //When script ends do this.
        public void onExit() {
            log("Bot Ended");
        }

        public int randomNum(int i, int k) {
            int num = (int)(Math.random() * (k - i + 1)) + i;
            return num;
        }
    }
     

    Link to comment
    Share on other sites

    2 minutes ago, MachineAIExp said:

    Hello to all!

    I have a problem with my following code, where the initialization causes errors, maybe someone who can assist?

    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.container.impl.bank.BankLocation;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;

    @ScriptManifest(author = "TheHacker", description = "Ge Trading", name = "GETrader", category = Category.MAGIC, version = 1)
    public class GETrader extends AbstractScript{

        State state;
        int COINS = 995; //gets COINS Item ID
        BankLocation GEBank = BankLocation.GRAND_EXCHANGE;
        int upperprice = 2000;
        int lowerprice = 1;
        
        @Override //Infinite loop
        public int onLoop() {
            
            //Determined by which state gets returned by getState() then do that case.
            switch(getState()) {
            case MARGINCHECK:
                log("Checking the Margins");
                
                fetchFunds();
                
                if (getGrandExchange().isGeneralOpen()) {
                    getGrandExchange().openBuyScreen(1);
                    getGrandExchange().searchItem("Lobster");
                    getGrandExchange().buyItem("Lobster", 1, upperprice);
                    getGrandExchange().goBack();
                    sleep(Calculations.random(1000, 5000));
                 }
                
                if (getGrandExchange().isReadyToCollect(1)) {
                    getGrandExchange().collect();
                    getGrandExchange().goBack();
                    sleep(Calculations.random(1000, 5000));
                }
                
                if (getInventory().contains("Lobster")); {
                    getGrandExchange().openSellScreen(1);
                    getGrandExchange().sellItem("Lobster", 1, lowerprice);
                    getGrandExchange().goBack();
                    sleep(Calculations.random(1000, 5000));
                }
                
                if (getGrandExchange().isReadyToCollect(1)) {
                    getGrandExchange().collect();
                    getGrandExchange().goBack();
                    sleep(Calculations.random(1000, 5000));
                }
                
                break;
            }
            return 0;
        }
        
        //State names
        private enum State{
            MARGINCHECK
        }
        
        //Checks if a certain condition is met, then return that state.
        private State getState() {
            if (GEBank.getArea(5).contains(getLocalPlayer()) && getGrandExchange().isOpen() == false) {
                getGrandExchange().open("Exchange");
            }
            if (GEBank.getArea(5).contains(getLocalPlayer()) && getGrandExchange().isGeneralOpen()) {
                state = State.MARGINCHECK;
            }
            return state;
        }
        
        private void fetchFunds() { //Only regarding the Buying state

            if(!getInventory().contains(COINS)) { //checks if the inventory contains COINS
                getBank().openClosest(); //Opens closest bank, you can set it to open(GEBank) if you want.
                getBank().withdrawAll(COINS); // withdraws all coins, you can set it to withdraw(COINS, int quantity) if you want.
                getBank().close(); //closes bank interface
            }

        }
        
        //When script start load this.
        public void onStart() {
            log("Bot Started");
        }
        
        //When script ends do this.
        public void onExit() {
            log("Bot Ended");
        }

        public int randomNum(int i, int k) {
            int num = (int)(Math.random() * (k - i + 1)) + i;
            return num;
        }
    }
     

    Never mind, solved it already

     

    Link to comment
    Share on other sites

    6 hours ago, MachineAIExp said:

    Never mind, solved it already

     

    just a tip. You should never call the getState() function where you don't need to. Instead, assign it to a variable within your onLoop and call the variable.

    Edited by NovaGTX
    Link to comment
    Share on other sites

    18 hours ago, NovaGTX said:

    just a tip. You should never call the getState() function where you don't need to. Instead, assign it to a variable within your onLoop and call the variable.

    Yeah, I removed it, so basically what I have now is a script where the bot buys e.g. an iron ore at max price, sells it at its lowest price, then goes to the history and selects the lowest price. I made the bot able to buy then the limit of iron ores at the lowest price, but what I would like to do is to add a margin between the lowest and highest price and check whether that margin is e.g. > 2 (to be for example profitable enough). The way I wrote it is like this (I work through the Widget debugger):


                WidgetChild history = getWidgets().getWidget(465).getChild(3);            
                if (history != null) {
                    history.interact();
                    sleep(Calculations.random(1000, 3000));
                }
                
                String upper = getWidgets().getWidgetChild(383,3,11).getText();
                String lower = getWidgets().getWidgetChild(383,3,5).getText();
                String upperv = upper.replace("coins", "");
                String lowerv = lower.replace("coins", "");
                
                int uppervalue = Integer.parseInt(upperv);
                log(Integer.toString(uppervalue));
                int lowervalue = Integer.parseInt(lowerv);
              
                int margin = uppervalue - lowervalue;
                
                WidgetChild lowest = getWidgets().getWidget(383).getChild(3).getChild(5);            
                if (lowest != null && margin > 2) {
                    lowest.interact();
                    sleep(Calculations.random(3000, 4000));
                    WidgetChild limit = getWidgets().getWidget(465).getChild(24).getChild(49); 
                    if (limit != null) {
                        limit.interact();
                        getKeyboard().type(Integer.toString(GElim));
                        sleep(Calculations.random(1000, 1500));
                    }
                    WidgetChild confirm = getWidgets().getWidget(465).getChild(24).getChild(54); 
                    if (confirm != null) {
                        confirm.interact();
                        
                        sleep(Calculations.random(1000, 1500));
                    }
                } else {
                  WidgetChild exchange = getWidgets().getWidget(383).getChild(2);            
                  if (exchange != null) {
                      exchange.interact();
                      sleep(Calculations.random(1000, 3000));
                  }
                }

     

    But it seems that my bot is crashing at the moment when the strings of the widgets are turned into integers. Maybe someone knows how to solve it? I can send you the full code if needed!

     

    Thanks in advance!

    Link to comment
    Share on other sites

    On 5/20/2020 at 2:24 PM, MachineAIExp said:

    But it seems that my bot is crashing at the moment when the strings of the widgets are turned into integers. Maybe someone knows how to solve it? I can send you the full code if needed!

     

    Thanks in advance!

    Have you verified that the widget's string only contains numbers?
    Edit: I think you left the space between coins and the value. Change "coins" to " coins" perhaps?

    Edited by NovaGTX
    Link to comment
    Share on other sites

    15 hours ago, NovaGTX said:

    Have you verified that the widget's string only contains numbers?
    Edit: I think you left the space between coins and the value. Change "coins" to " coins" perhaps?

    Interesting! That is probably a mistake as well, so I changed it, but it seems that the replacement statement breaks it. It does not replace " coins" by "". When I print the value of a new variable (with the replacement) then it returns again the " coins", so e.g. "48 coins" instead of "48". That is also why the parsing to an integer won't work...

    Any ideas how I can remove " coins" from the string?

    Thanks man!

    Link to comment
    Share on other sites

    15 hours ago, NovaGTX said:

    Have you verified that the widget's string only contains numbers?
    Edit: I think you left the space between coins and the value. Change "coins" to " coins" perhaps?

    Also btw: I want to bot a little bit on my main, but right now I use a proxy for my botting accounts, but I can't find an easy option to quickly switch to your home IP when you decide to bot a little bit on your main? (it would be weird to have your main account login somewhere on the otherside of the world right?) How should I do this?

    Link to comment
    Share on other sites

    15 hours ago, NovaGTX said:

    Have you verified that the widget's string only contains numbers?
    Edit: I think you left the space between coins and the value. Change "coins" to " coins" perhaps?

    Wait, I actually got it working! So as I mentioned, the replacement was incorrect, so I changed it into replacing all letters, so only numbers would remain by: 

    String upperv = upper.replaceAll("[^0-9.]","");

    Now it totally works fine!

    Remains the question about the IP though 😜

    Link to comment
    Share on other sites

    12 hours ago, MachineAIExp said:

    Also btw: I want to bot a little bit on my main, but right now I use a proxy for my botting accounts, but I can't find an easy option to quickly switch to your home IP when you decide to bot a little bit on your main? (it would be weird to have your main account login somewhere on the otherside of the world right?) How should I do this?

    If you bot on account it's not a matter of IF you will be banned but WHEN. If you don't want the account banned (your main) don't bot on it.

    But yes you would need to use a regex for replace. Or just use a substring and find the space.

    Link to comment
    Share on other sites

    4 hours ago, NovaGTX said:

    If you bot on account it's not a matter of IF you will be banned but WHEN. If you don't want the account banned (your main) don't bot on it.

    But yes you would need to use a regex for replace. Or just use a substring and find the space.

    Yeah, I think I wont risk it, but mining in motherlode is such a painfull grind 😜
    One more question: I am currently trying to implementing the following:

    String[] items = {};
    			items[0] = "Death rune";
    			items[1] = "Law rune";
    			items[2] = "Nature rune";
    			items[3] = "Chaos rune";
    			items[4] = "Steel bar";
    			items[5] = "Yew logs";
    
    int[] limits = {};
    			limits[0] = 10000;
    			limits[1] = 12000;
    			limits[2] = 12000;
    			limits[3] = 12000;
    			limits[4] = 10000;
    			limits[5] = 12000;
    
    String buyitem = null;
    int GElim = 0;
    			
    for (String item : items) {
    	buyitem = item;
    }
    for (int limit : limits) {
    	GElim = limit;
    }
    
    if (getGrandExchange().isGeneralOpen()) {
        getGrandExchange().openBuyScreen(1);
        getGrandExchange().searchItem(buyitem);
        getGrandExchange().buyItem(buyitem, 1, upperprice);
        getGrandExchange().goBack();
        sleep(Calculations.random(3000, 4000));
    }

    So to explain: I try to make 2 kind of lists, 1 for each item and 1 for the GE limit of that item. I then try to assign each value in a for loop to a new variable that I call in the STATE methods. I hope you get what I mean? 

    The problem is that this is not really possible and I do not really know how to solve this, or whether there is maybe a much easier way to solve this problem.

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • 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.