Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to implement an action after a random amount of time has passed

Featured Replies

basically looking to world hop a random amount of time
(similar to sleep(random(300, 500)) )

just need help on being able to intitate the world hop

i.e

 

if time has been between 30 mins - 1 hour since last world hop {

do stuff

}

store the last hop time in a long.

 

Check if the current time - the last time you stored > time your want in between.

If so hop.

Edited by House

  • Author

long lastHop = System.currentTimeMillis();
if(lastHop >= (pastTime + 30*60000) { //multiply by 60000 to get mins
doSomething();
}

 

like this? is what i can find, but its after a set amount of time rather than random between two ints

long lastHop = System.currentTimeMillis();

if(lastHop >= (pastTime + 30*60000) { //multiply by 60000 to get mins

doSomething();

}

 

like this? is what i can find, but its after a set amount of time rather than random between two ints

 

so randomize it?

long lastHop = System.currentTimeMillis();

if(lastHop >= (pastTime + 30*60000) { //multiply by 60000 to get mins

doSomething();

}

 

like this? is what i can find, but its after a set amount of time rather than random between two ints

 

I'm not trying to berate you or anything but I really think it would benefit you greatly to learn the basics first, all of this trivial you should be able to come up with the solution on your own after just an hour of reading or even less.

 

I'm not trying to berate you or anything but I really think it would benefit you greatly to learn the basics first, all of this trivial you should be able to come up with the solution on your own after just an hour of reading or even less.

 

 


 

private Timer worldHoppingTimer = new Timer();

public int onLoop() {

if (worldHoppingTimer.isActive()) {

//do something here

int hour = 3600000;

int minHours = 1 * hour;

int maxHours = 3 * hour;

worldHoppingTimer.setTimeout(random(minHours, minHours)); //set the timer to go off in 1 - 3 hours (just an example)

}

return 100;

}


 

public class Timer {

private long timeout;

public Timer() {

timeout = System.currentTimeMillis();

}

public boolean isActive() {

return timeout > System.currentTimeMillis();

}

public void setTimeout(long timeout) {

this.timeout = timeout + System.currentTimeMillis();

}

public long getElapsedTime() {

return System.currentTimeMillis() - timeout;

}

public String getElapsedToString() {

return Format.msToString(getElapsedTime());

}

public long getPerHour(long value) {

return value * 3600000 / getElapsedTime();

}

}

Edited by Easy

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.