Jump to content

Beginner noob problems


Recommended Posts

Posted

Heya I just wanted to ask how I could make it that my Player does stop if he interact with the Rock (mining) I could put sleeping on like 10 secs but I want to that he not waits 10 sec even he mined the rock after 2 secs.

 

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import java.awt.*;
 
@ScriptManifest(author = "Someone", info = "Testing", name = "Mining Test", logo = "", version = 0)
public class main extends Script {
 
public void onStart() {
log("Shitty test");
}
 
private enum State {
MINE, DROP, WAIT
};
            
private State getState() throws InterruptedException {
Entity stall = objects.closest("Rocks");
        inventory.dropAllExcept(1265);
        sleep(random(1000));
if (stall != null)
return State.MINE;
return State.WAIT;
}
 
public int onLoop() throws InterruptedException {
switch (getState()) {
case MINE:
Entity stall = objects.closest("Rocks");
if (stall != null) {
stall.interact("Mine");
}
break;
case DROP:
inventory.dropAll();
break;
case WAIT:
sleep(random(500, 700));
break;
}
return random(200, 300);
}
 
public void onExit() {
log("Test more");
}
 
public void onPaint(Graphics2D g) {
 
}
 
}
 
 
Thanks for any help.
~Life
Posted

Vilius answered your question really well, but as a side note, you might want to have a look into condition sleeping. It can be very useful. 

 

For instance, say you want to drop everything except for a certain ore, you could write:

if(inventory.isFull()) {
      inventory.dropAllExcept(2958);
      new ConditionalSleep(10000) {
	    @[member=Override]
						
	    public boolean condition() throws InterruptedException {
			return inventory.onlyContains(2958);
			}
	    }.sleep();
}

This would, if your inventory is full, drop everything except for item ID 2958, and sleep until your inventory only contains item ID 2958.

 

If after 10000 ms your inventory still does not only contain 2958 (if the script failed to drop something for some reason), it will repeat, trying to drop everything and sleeping until the condition of "inventory.onlyContains(2958)" is met.

 

  • Like 1
Posted

Vilius answered your question really well, but as a side note, you might want to have a look into condition sleeping. It can be very useful. 

 

For instance, say you want to drop everything except for a certain ore, you could write:

if(inventory.isFull()) {
      inventory.dropAllExcept(2958);
      new ConditionalSleep(10000) {
	    @[member='Override']
						
	    public boolean condition() throws InterruptedException {
			return inventory.onlyContains(2958);
			}
	    }.sleep();
}

This would, if your inventory is full, drop everything except for item ID 2958, and sleep until your inventory only contains item ID 2958.

 

If after 10000 ms your inventory still does not only contain 2958 (if the script failed to drop something for some reason), it will repeat, trying to drop everything and sleeping until the condition of "inventory.onlyContains(2958)" is met.

Okay cool  I understand thanks!

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...