Jump to content
Sign in to follow this  
IDontActuallyLift

Hard coding breaks into my scirpt

Recommended Posts

****

TL;DR:

Trying to hard code breaks into my script, I want the script to break for a random amount of time between 20 and 40 minutes every 1.5 to 1.75 hours that it has run.  The program will run for ~8 hours per day so I need to script to break about 4 times.  any help is much appreciated.  Thanks!

****

 

Good Evening,

I have a bit of an issue.  I do not like the break handler that is hard coded into the tribot client, I would much prefer to code breaking conditions into my code for specific scripts.  My issue is that I am having trouble with the logic of some of what I have coded already.  Here is what I have:

            long timeRanBreak = System.currentTimeMillis() - startTime;
            long timeSinceLastBreak = System.currentTimeMillis() - timeOfLastBreak;
            long breakTime = General.randomLong(1200000, 2400000);

            if (General.randomLong(5400000, 6300000) < timeRanBreak && firstBreak < 1) {
                println("Initiating first break");
                println("We ran for " + Timing.msToString(timeRanBreak) + " taking a break for " + (breakTime / 60000)
                        + " minutes.");
                General.sleep(3000);
                teleToBank();
                General.sleep(6000);
                Login.logout();
                this.setLoginBotState(false);
                General.sleep(breakTime);
                breakCounter++;
                timeOfLastBreak = System.currentTimeMillis();
                println("Break Finished, logging in.");
                this.setLoginBotState(true);
                Login.login();
                firstBreak++;
                
            }

            if (General.randomLong(5400000, 6300000) < timeSinceLastBreak && timeOfLastBreak < 1) {
                println("Initiating tertiary break");
                println("We ran for " + Timing.msToString(timeSinceLastBreak)
                        + " since last break, taking another break for " + (breakTime / 60000) + " minutes.");
                General.sleep(3000);
                teleToBank();
                General.sleep(6000);
                Login.logout();
                this.setLoginBotState(false);
                General.sleep(breakTime);
                breakCounter++;
                timeOfLastBreak = System.currentTimeMillis();
                println("Break Finished, logging in.");
                this.setLoginBotState(true);
                Login.login();
            }

 

All of the above code is contained in my main run while loop, I haven't gotten around to learning node task framework yet its on my list of things to tackle one at a time :).  So if I can walk you though the basic logic this is what I've come up with:

timeRanBreak = Total time elapsed by the script in ms, once this value is greater than some randomly generated integer between an 1.5 hours and 1.75 hours take a break for another randomly generated value between 20 and 40 minutes.

The first break runs no problem, however my problem is that time elapsed wont reinitialize at zero after the first break so I tried to be cool and initialize a tertiary variable called "timeOfLastBreak" which is supposed to keep track of the time that has elapsed since the last time we took a break and once that hits 1.5hours to 1.75 hours we should break for another 20 to 40 minutes.  So as I said the first break runs and sleeps for a the amount desired however when the script starts back up from the break the script will initiate the tertiary break immediately and the print line reads as follows:

                println("We ran for " + Timing.msToString(timeSinceLastBreak)
                        + " since last break, taking another break for " + (breakTime / 60000) + " minutes.");

will read:

  • [00:22:11] We ran for 422621:20:56 since last break, taking another break for 28 minutes.

So from what I can gather the random amount of time that I want the script to break for will generate every time, however the function is not realizing that I want it to wait an additional period of time of 1.5 hours to 1.75 hours before initiating the tertiary break. 

 

Sorry for my spaghetti code, I'm kind of embarrassed by it and try not to post too many issues until I've thoroughly checked for solutions but I want to see if someone can help me with what I am trying to do here.  I'm sure someone can come in here and code this all in about 10 lines but I'm fairly inexperienced and trying to learn.  Thanks in advanced guys, you are a great community. 

 

****

TL;DR:

Trying to hard code breaks into my script, I want the script to break for a random amount of time between 20 and 40 minutes every 1.5 to 1.75 hours that it has run.  The program will run for ~8 hours per day so I need to script to break about 4 times.  any help is much appreciated.  Thanks!

****

 

Share this post


Link to post
Share on other sites

You should just have it generate your next break when your first one triggers. E.G. :

-Start script, you record current time. Generate how long until first break randomly.

-When break time comes, have it do what it needs to, and logout, and take the break.

-When the break completes, reset your time tracker, and generate a new amount of time to pass before breaking again.

If you want it to stop after a certain number of breaks/time passed, have it kill the script after X number of breaks, or after X amount of time passes from the time you generated when you started.

Share this post


Link to post
Share on other sites
Posted (edited)

Here is some pseudo for you to help get the idea

onStart() Script

    => Generate a breakStartTime [General.randomDouble(1.00, 1.5) * 60.0 * 60.0 * 1000.0] + Timing.currentTimeMillis()

run() Script

    => if (Timing.currentTimeMillis() > breakStartTime)

            => Generate a breakLength [General.random(20, 40) * 60.0 * 1000.0]

            => Do Actions Before Break (Can be before you generate the breakLength, depends on how you want to implement it)

            => General.sleep(breakLength)

            => Generate the next breakStartTime [General.randomDouble(1.00, 1.5) * 60.0 * 60.0 * 1000.0] + Timing.currentTimeMillis()

Edited by JoeDezzy1

Share this post


Link to post
Share on other sites
3 hours ago, JoeDezzy1 said:

           => Generate the next breakStartTime [General.randomDouble(1.00, 1.5) * 60.0 * 60.0 * 1000.0] + Timing.currentTimeMillis()

Thank you for taking the time to respond.  When you say generate the next break you mean reassign the value of breakStartTime inside the break function?  For example something like this:

            if (Timing.currentTimeMillis() > breakStartTime) {
                long breakTime = General.randomLong(1200000, 2400000);
                println("Initiating first break");
                println("We ran for " + Timing.msToString(timeRanBreak) + " taking a break for " + (breakTime / 60000)
                        + " minutes.");
                General.sleep(3000);
                teleToBank();
                General.sleep(6000);
                Login.logout();
                this.setLoginBotState(false);
                General.sleep(breakTime);
                breakCounter++;
                timeOfLastBreak = System.currentTimeMillis();
                println("Break Finished, logging in.");
                this.setLoginBotState(true);
                Login.login();
                firstBreak++;
                double breakStartTime = General.randomDouble(5400000, 6300000) + Timing.currentTimeMillis();
            }

Share this post


Link to post
Share on other sites
Just now, HeyImJamie said:

I'd focus on actually writing some code that is follow-able and won't break before moving onto implementing your own breaking system.

In regards to your question though, yes that's what he means.

I have a script that can function for 8+ hours at a time, I feel as though I have done a good job on it.  At this point I was just struggling with the breaking logic.  Usually I don't like to be a bother to the community so I try to figure it out myself.  Thank you for clarifying though, I just implemented it and it works great.

Share this post


Link to post
Share on other sites
1 minute ago, IDontActuallyLift said:

I have a script that can function for 8+ hours at a time, I feel as though I have done a good job on it.  At this point I was just struggling with the breaking logic.  Usually I don't like to be a bother to the community so I try to figure it out myself.  Thank you for clarifying though, I just implemented it and it works great.

Any script can function for an average amount of time and run relatively ok as long as your community is running fine. The way you're currently executing your code, assuming it's all written like your break class, is as follows.

If we should break

- tele to bank 

- sleep

- logout

- etc.

You're relying on everything to work 100% of the time, what if we don't tele to the bank or logout? If you were in the wilderness, you could end up sleeping for your break while still logged in and unable to defend yourself.

Share this post


Link to post
Share on other sites
1 minute ago, HeyImJamie said:

Any script can function for an average amount of time and run relatively ok as long as your community is running fine. The way you're currently executing your code, assuming it's all written like your break class, is as follows.

If we should break

- tele to bank 

- sleep

- logout

- etc.

You're relying on everything to work 100% of the time, what if we don't tele to the bank or logout? If you were in the wilderness, you could end up sleeping for your break while still logged in and unable to defend yourself.

Oh I understand you're point now, I apologize.  You are correct, getting the framework to run is a big part of writing a program there needs to be checks to the system in order to ensure the task is complete.  This break function is very simple because I was trying to get the logic down before continuing and making it more complex.  That is my next step right now. 

Share this post


Link to post
Share on other sites
Just now, IDontActuallyLift said:

Oh I understand you're point now, I apologize.  You are correct, getting the framework to run is a big part of writing a program there needs to be checks to the system in order to ensure the task is complete.  This break function is very simple because I was trying to get the logic down before continuing and making it more complex.  That is my next step right now. 

I wasn't trying to be a dick as I'm nowhere near perfect but I know when I was learning, that was a big fault of mine.

Share this post


Link to post
Share on other sites
Just now, HeyImJamie said:

I wasn't trying to be a dick as I'm nowhere near perfect but I know when I was learning, that was a big fault of mine.

No worries man, I understand.  For me i find it is helpful to fully understand the logic before I implement my checks to ensure it runs correctly every time. 

Share this post


Link to post
Share on other sites
Just now, IDontActuallyLift said:

No worries man, I understand.  For me i find it is helpful to fully understand the logic before I implement my checks to ensure it runs correctly every time. 

Pseudo code's better for this. Write the logic, then write the code. It'll stop you leaving clusterfucks in your code that you'll then have to fix later

Share this post


Link to post
Share on other sites
Posted (edited)

@HeyImJamie is right

 

@IDontActuallyLift

Before taking a break, make sure that your tasks beforehand have executed succesfully.

Here is an actual code example to get you started

 

private long breakStartTime;
private int breakCounter;


@Override
public void onStart() {
    this.breakStartTime = generateNextBreak();
}

@Override
public void run() {
    while (this.operate()) 
        this.sleep(10);
}

/**
 * @return the next time we want to take a break from "now" */
public long generateNextBreak() {
    return (long) (Timing.currentTimeMillis() + General.randomDouble(1.00, 1.5) * 60.0 * 60.0 * 1000.0);
}

/**
 * @return true if the current time is greater than our setbreak time */
public boolean shouldBreak() {
    return Timing.currentTimeMillis() > this.breakStartTime;
}

/** Operate your bot
 * @return false to stop the bot completely, otherwise true */
public boolean operate() {
    /** This is where your break is handled */
    if (this.shouldBreak()) {
        onBreak();
        return true;
    }
    /** ...whatever else you're doing, return true */
    
    
    return this.shouldExit(); /** This will stop your bot if it returns false */
}

/** 
 * Do your actions here when a break should activate, once they've been confirmed... * Then take your break */
public void onBreak() {
    /** Assuming we logged out because our actions have ended successfully 
     * (There are better ways to confirm completion, this is just an example)
     * Then, go ahead and generate the length you wish to break for, and sleep for that long */
    if (Login.getLoginState() != STATE.INGAME) {
        println("Initiating first break");
        final long breakTime = General.randomLong(1200000, 2400000);
        this.setLoginBotState(false);
        this.sleep(breakTime); /** Take the "break" */
        this.breakStartTime = generateNextBreak(); /** MUST, resets the break start time so we do not endlessly end up in this method after the first break has been executed */
        breakCounter++;
        return;
    }
    /** 
     * Still logged in? */
    if (Banking.isInBank()) {
        Login.logout();
        return;
    }
    /**
     * Not in the bank? */
    teleToBank();
}

 

I forgot to turn the loginBotState(true) back after "breakCounter++", so dont forget that

Edited by JoeDezzy1
  • Like 2

Share this post


Link to post
Share on other sites
4 minutes ago, IDontActuallyLift said:

This is not allowing me to have the @Override statement, it throws me this error:

The method onStart() of type Airorbs must override or implement a supertype method

It's an example. onStart is an interface I believe, so you'd have to implement it

Share this post


Link to post
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
Sign in to follow this  

  • Our picks

    • This release includes:

      Fix updater bug which was causing a bunch of issues


      TRiBot will no longer require manual hook fixes every time the RS client updates - the updater has been fully patched for objects


      Hooked login fields


      Improved the login bot


      Ability to recognize the banned/locked messages again


      Ability to read the current input for username and password fields


      If the username or password is already entered correctly, it won't be erased


      If only part of the username or password is already entered correctly, it won't be erased. The login bot will fill in what's missing.


      If there are a few invalid characters after a valid substring of your username/password, only (approximately) those invalid characters will be erased. The login bot will then proceed to fill in the missing characters.





      Coming soon:

      Skull icon fix


      Improve screen rate and responsiveness of the RS client (both regular client and LG)


      Much more
        • Thanks
        • Like
      • 20 replies
    • This release includes:

      Fix shift clicking option selecting


      Fix high paint delay settings saving


      Update prayer IDs for the quick select menu


      Remove RS3 support


      Fix hooks



      RS3 Support Removed

      The RS3 client hasn't been updated since our Old-School version of TRiBot was released, as many of you may have noticed. Keeping all of the RS3 code in the client made the client as a whole harder to maintain, larger, slower, and messier. As hardly anyone still uses the RS3 client, and since the RS3 API was hardly functioning, we made the decision to completely remove it from TRiBot.

      For the average user, this means that the client will be smaller, cleaner, and faster. Future updates will also take less work meaning there will be more frequent updates.

      If you were one of the few users still using the RS3 client, we apologize for the inconvenience. No future support for RS3 is planned. There are many other botting clients which has support for RS3, so we recommend finding an alternative if you wish to continue botting on RS3.
        • Thanks
        • Like
      • 25 replies
    • Please welcome our new developers, @JoeDezzy1, @erickho123, @Encoded, and @wastedbro.

      These members will be responsible for working on, maintaining, and improving TRiBot.

      This means that bug fixes and improvements will now come at a much faster pace! We're committed to providing users with the best botting experience possible!
        • Thanks
        • Like
      • 30 replies
    • This release includes:

      More 3rd party libraries for script writers to use


      Apache Commons Codec


      Apache Commons Collections


      Apache Commons Configuration


      Apache Commons IO


      Apache Commons Lang


      Apache Commons Math


      GSON


      Guava


      JFoenix




      Hint arrow API


      Game#getHintArrowX


      Game#getHintArrowY




      Fix player hooks including Player#getSkullIcon and Prayer#getPrayerIcon
        • Thanks
        • Like
      • 49 replies
    • This update includes:

      Fix broken hooks


      Fix login bot for the message "No reply from login server. Please wait 1 minute and try again."


      Fix bug relating to which bot tab is sent human input


      General#randomLong bug fix involving negative numbers


      Fix GE API



      Please note: There are still some issues with the login bot due to a change in the game mechanisms handling the login screen. We're working on a fix and will upload it when ready.
        • Thanks
        • Like
      • 37 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×