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
  • Storing a bots desired level in a cache for later reference


    Z3b3e33

    Recommended Posts

    Hi guys,

    Basically I am trying to decide a "random" combat level (between 15 and 30) for my bots to get to. I'd like to select a number from random between 15 and 30 for each bot to level atk/str/def up to. Is there a good way to generate one and store it for the bots lifespan?

    Thanks

    -Z

    Link to comment
    Share on other sites

    Sure. Simply assign a value to a variable at script launch that you can refer to as the script progresses. Iirc there's a method in the Calculations class for getting a random value in a range.

     

    In regards to what Pixel stated above, you can just return -1 in your loop cycle if a condition is met to stop the program.

    Link to comment
    Share on other sites

    https://dreambot.org/javadocs/org/dreambot/api/methods/Calculations.html#random-int-int-

     

    public class TestScript extends AbstractScript {
    
        int stopAtLevel;
    
        @Override
        public void onStart() {
            //On script start generate a random number between 15 to 30
            stopAtLevel = Calculations.random(15, 30);
        }
    
        @Override
        public int onLoop() {
            //Do your stuff here
            if (Players.localPlayer().getLevel() >= stopAtLevel) {
                //return -1 will stop the script from looping
                //however you probably want to add more checks like to make sure you're not in combat etc. and then logout with Tabs.logout();
                return -1;
            }
            return 1000;
        }
    }

     

    Link to comment
    Share on other sites

    1 hour ago, Pixel_Life said:

    https://dreambot.org/javadocs/org/dreambot/api/methods/Calculations.html#random-int-int-

     

    
    public class TestScript extends AbstractScript {
    
        int stopAtLevel;
    
        @Override
        public void onStart() {
            //On script start generate a random number between 15 to 30
            stopAtLevel = Calculations.random(15, 30);
        }
    
        @Override
        public int onLoop() {
            //Do your stuff here
            if (Players.localPlayer().getLevel() >= stopAtLevel) {
                //return -1 will stop the script from looping
                //however you probably want to add more checks like to make sure you're not in combat etc. and then logout with Tabs.logout();
                return -1;
            }
            return 1000;
        }
    }

     

    spoon-feed.jpg

    Link to comment
    Share on other sites

    Maybe I'm missing the point of the post but it seems like you want to persist the random level over multiple sessions, but I don't really understand why? Are you trying to put everything for the accounts in one script or something? If not just use the above suggestions.

    If you need to persist variable(s), you could store variables in an external file and read it from there. Or you could use the first few letters of the account name and parse them into integers ranging from 15-30, for example:

    a=15, b=16, ... p=30, q=15, ... 0=15, 1=16, ...

    Account Name: dr3ambot

    Attack Level: d = 18

    Strength Level: r = 16

    Defence Level: 3 = 18

    This only works if your accounts generally have random-ish names. This is just one way to solve your problem if it does need to be solved.

    Link to comment
    Share on other sites

    On 11/9/2020 at 8:05 AM, Just Chill said:

    Maybe I'm missing the point of the post but it seems like you want to persist the random level over multiple sessions, but I don't really understand why? Are you trying to put everything for the accounts in one script or something? If not just use the above suggestions.

    If you need to persist variable(s), you could store variables in an external file and read it from there. Or you could use the first few letters of the account name and parse them into integers ranging from 15-30, for example:

    a=15, b=16, ... p=30, q=15, ... 0=15, 1=16, ...

    Account Name: dr3ambot

    Attack Level: d = 18

    Strength Level: r = 16

    Defence Level: 3 = 18

    This only works if your accounts generally have random-ish names. This is just one way to solve your problem if it does need to be solved.

    Yes, he wants to first get random int variables (which is ez), then store it inside a file and then with every boot, he wants the script to read from the file and have permanent variables, always available. I don't know how to do it in Java syntax though. It's pretty cool stuff, it's good for antiban, as every bot would train to different stats.

    Link to comment
    Share on other sites

    • 3 months later...

    Thanks for your replies all of you. I have not made a basic JSON I/O class and generated them with that.

    The purpose of persisting the levels over multiple sessions is because the script is an AIO account prepper script for a client that has reached the 3000+ lines of code and the levels had to be reffered to over multiple sessions, especially in the accept() of a task.

    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.