Jump to content

I'm a noob and need some help


Recommended Posts

Posted (edited)

This problem has been solved. Thank you all so much for your help!

 

I'm trying to write a very simple script to troll the Hill Giants in the Edge cave and gather Limpwerts people don't pick up. The problem is, my script just freezes the OSBot window and starts eating memory. For the life of me, I can't figure out what is going on. Here is the script: (NOTE: Bright yellow indicates edits since original post.)

 

 

import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
 
 
import java.awt.*;
 
@ScriptManifest(author = "Mustang Guy", info = "private script", name = "Limpwert root banker", version = 0.01, logo = "")
public class main extends Script
{
 
    @Override
    public void onStart() 
    {
        log("Bot to pick Limpwurt roots and bank them");
    }
    
    private enum State {PICK, BANK, WAIT};
    
    private State getState()
    {
    GroundItem lr = groundItems.closest("Limpwurt root");
    if (!inventory.isFull() && lr != null && lr.exists())
    {
          return State.PICK;
    }
    if (inventory.isFull())
    {
          return State.BANK;
    }
    return State.WAIT;
    }
 
    @Override
    public int onLoop() throws InterruptedException 
    {
    GroundItem lr = groundItems.closest("Limpwurt root");
    switch (getState()) 
    {
    case PICK:
         log("PICK");
         if (lr != null && lr.exists())
              lr.interact("Take");
         break;
    case BANK:
         log("BANK");
              //write script to run to bank
         break;
    case WAIT:
         log("WAIT");
         sleep(random(500, 700));
         break;
         }
    return random(200, 300);
    }
    
    @Override
    public void onExit() 
    {
        log("adios");
    } 
 
    @Override
    public void onPaint(Graphics2D g) 
    {}
 
}
Edited by mustang guy
Posted (edited)

    private State getState()
    {
    GroundItem lr = groundItems.closest("Limpwert root");
     if (!inventory.isFull() && lr.exists())
          return State.PICK;
    if (inventory.isFull())
          return State.BANK;
    return State.WAIT;
    }

Change to

 

    private State getState()
    {
    GroundItem lr = groundItems.closest("Limpwert root");
     if (!inventory.isFull() && lr.exists()){
          return State.PICK;
}
    if (inventory.isFull()){
          return State.BANK;
}
    return State.WAIT;
    }

Also you have nothing in your bank statement, so it'll sit there and shit itself if state = bank.

Edited by Gilgad
Posted (edited)

I put the brackets in the getState() and changed the spelling of Limpwurt, and it still freezes and gobbles memory. I edited the script above to reflect those changes, and they are indicated in bright yellow.

 

I threw a bunch of log statements in the script in the various case sections so I could figure out which section the error is occurring in. The problem is, the text window below the OSBot screen is too short to see the errors and logs() and the window is frozen so I can't scroll back up. I couldn't find a debug function for writing the log to a file.

 

Here is all I can see in the error log below the RS window in the OSBot app:

 

TTSme6i.png

Edited by mustang guy
Posted (edited)

you must always null check,

 

instead of .exists do lr != null

 

this will stop the NPE.

 

You nailed it Precise. I was null checking in the loop, but overlooked it in the getState().

 

By the way, the script works great. 

 

Perhaps instead of having the script pick up the limp, I will have it notify me there is one laying down somewhere in the room. That way I can pick it up and not be in any danger of getting nabbed for scripting. What I want is to have this little baby running while I am killing Hill giants. 

Edited by mustang guy
  • Like 1
Posted

You nailed it Precise. I was null checking in the loop, but overlooked it in the getState().

 

By the way, the script works great. 

 

Perhaps instead of having the script pick up the limp, I will have it notify me there is one laying down somewhere in the room. That way I can pick it up and not be in any danger of getting nabbed for scripting. What I want is to have this little baby running while I am killing Hill giants. 

 

If you run in injection mode you could get done for using "3rd party clients". Go big or go home lol

 

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