Jump to content

My First Script HELP


Recommended Posts

Posted

Well, I really didn't want to ask for help and try to figure this out myself but...I just don't understand why my script is not running. I click start and it just stands there by the jug...:/

If anyone can help and explain too me how to fix this to make it take the Jug in lumbridge kitchen and then drop and wait....please I would love you.

Here is my Code

Spoiler

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.api.model.RS2Object; 
 
import java.awt.*;


 
@ScriptManifest(author = "Toxic", info = "My first script", name = "Lumbridge Jug Stealer", version = 0, logo = "")
public class Main extends Script {
 
    @Override
    public void onStart() {
        log("Welcome to Toxic's Jug Stealer.");
        log("This is my first sript ever, hope you enjoy!");
    }
    
    private enum State {
        TAKE, DROP, WAIT
    };
    
    private State getState() {
        RS2Object Table = getObjects().closest("Jug");
        if (!inventory.isEmpty())
            return State.DROP;
    if (Table != null)
            return State.TAKE;
        return State.WAIT;
    }
 
    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case TAKE:
            RS2Object Table = getObjects().closest("Jug");
            
            if (Table != null) {
                    Table.interact("Take");
            }
            break;
        case DROP:
                inventory.dropAll();
                break;
        case WAIT:
                sleep(random(500, 700));
                break;
        }
        return random(200, 300);
    }
 
    @Override
    public void onExit() {
        log("Thanks for running my Jug Stealer!");
    }
 
    @Override
    public void onPaint(Graphics2D g) {
        g.drawString("Hello Jugs!", 50, 50);
    }
 
}

 

 

Posted
4 minutes ago, HeyImJamie said:

It's possible the RS2Object call within your getState method is stopping it from running. Try with the script logged in. If that fixes it you could add a while loop to your onStart method that waits for the script to be logged in before your getState method is called :) 

I am already logged in while starting the script and it does nothing still.

Posted
9 hours ago, Prozen said:

You're trying to grab the nearest Object, when jugs are grounditems. use getGroundItems().closest() as I use in the example.

 

GroundItem jug = getGroundItems().closest("Jug");

if(jug != null && jug.exists() && jug.interact("Take")) {

// Interaction successful - sleep here

}

Got it, Thank you :D

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...