Hey just wanted to get people opinions on a very basic script. Are there better ways to structure the code, better ways to go about what this script is attempting(Red chins)?
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;
import java.awt.*;
@ScriptManifest(author = "Sellout", name = "Red chin", info = "Basic red chin script", version = 0.1, logo = "")
public final class RedChin extends Script {
private long startTime;
Area top = new Area(2496, 2907, 2496, 2907);
Area left = new Area(2495, 2906, 2495, 2906);
Area right = new Area(2497, 2906, 2497, 2906);
Area bottom = new Area(2496, 2905, 2496, 2905);
Area[] trapPositions = {top, left, right, bottom};
@Override
public final int onLoop() throws InterruptedException {
resetTraps();
resetDecayed();
collectChins();
layTraps();
return random(500, 1250);
}
@Override
public final void onStart() {
log("This will be printed to the logger when the script starts");
startTime = System.currentTimeMillis();
}
@Override
public void onPaint(final Graphics2D g) {
Point mP = getMouse().getPosition();
final long runTime = System.currentTimeMillis() - startTime;
g.setColor(Color.RED);
g.drawLine(mP.x - 5, mP.y + 5, mP.x + 5, mP.y - 5);
g.drawLine(mP.x + 5, mP.y + 5, mP.x - 5, mP.y - 5);
g.drawString(formatTime(runTime), 5, 336);
}
@Override
public final void onExit() {
log("This will be printed to the logger when the script exits");
}
public final void conditionalSleep(int time){
new ConditionalSleep(time) {
@Override
public boolean condition() {
return false;
}
}.sleep();
}
public final String formatTime(final long ms){
long s = ms / 1000, m = s / 60, h = m / 60;
s %= 60; m %= 60; h %= 24;
return String.format("%02d:%02d:%02d", h, m, s);
}
public void layTraps(){
for (Area position:trapPositions) {
RS2Object trapTwo = getObjects().closest(position, "Shaking box", "Box trap");
GroundItem trap = getGroundItems().closest(position, "Box trap");
if(trapTwo == null && trap == null){
getWalking().webWalk(position);
conditionalSleep(random(1250, 1500));
getInventory().interact("Lay", "Box trap");
conditionalSleep(random(4500, 4750));
}
}
}
public void resetTraps(){
for (Area position:trapPositions) {
RS2Object trap = getObjects().closest(position, "Box trap");
if(trap != null && trap.getId() == 9385) {
trap.interact("Reset");
conditionalSleep(random(8000, 8200));
}
}
}
public void collectChins(){
for (Area position:trapPositions) {
RS2Object trap = getObjects().closest(position,"Shaking box");
if(trap != null && trap.getId() == 9383){
trap.interact("Check");
conditionalSleep(random(2250, 2500));
}
}
}
public void resetDecayed(){
for (Area position:trapPositions) {
GroundItem trap = getGroundItems().closest(position, "Box trap");
if(trap != null) {
trap.interact("Lay");
conditionalSleep(random(7750, 8000));
}
}
}
}