Jump to content

My First Script HELP


Toxic

Recommended Posts

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);
    }
 
}

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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