Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Node Tutorial - NullPointerException

Featured Replies

MainClass:

import core.*;
import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import nodes.*;

import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;


@ScriptManifest(author = "sesamest", info = "Version 0.02", name = "Cow Killer/Hide Grabber", version = 0)
public class MainClass extends Script {

        private String status = "";
        private List<Node> nodes = new ArrayList<>();
	
	@Override
	public void onStart() {
            nodes.add(new Banking(this));
	}
	
	@Override 
	public int onLoop() throws InterruptedException {
            for(Node n : nodes) {
                if(n.validate()) {
                    status = n.status();
                    if(n.execute()) {
                        return random(200,400);
                    }
                }
            }
            return random(200, 310);
	}
	
	@Override
	public void onExit() {
		log("Thanks for using this wonderful script!");
	}

	@Override
	public void onPaint(Graphics g) {
            g.setColor(Color.black);
            g.drawString(status, 6, 6);
            g.setColor(Color.white);
            g.drawString(status, 5, 5);
	}
	
}

Banking Node Class:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package nodes;

import core.Constants;
import core.Node;
import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;
import org.osbot.script.rs2.model.RS2Object;

/**
 *
 * @author LivingRoom
 */
public class Banking extends Node {
    
    private static final int[] BANKOBJECT_ID = { 24101 };
    
    public Banking(Script sA) {
        super(sA);
    }
    
    @Override
    public String status() {
        return "Banking";
    }
    
    private boolean isBoothVisible() {
        return true;
       /* RS2Object booth = sA.closestObject(BANKOBJECT_ID);
        if(booth != null)
            if(booth.getPosition().distance(sA.myPosition()) <= 5)
                return true;
        return false; */
    }

    @Override
    public boolean validate() throws InterruptedException {
        return sA.client.getLocalNPCs().contains("Banker");
    }
    
    public boolean openBank() throws InterruptedException {
        RS2Object booth = sA.closestObject(BANKOBJECT_ID);
        if (booth != null) {
            if(!booth.isVisible()) {
                sA.client.moveCameraToPosition(booth.getPosition());
            }
            if (booth.interact("Bank")) {
                while (!sA.client.getBank().isOpen())
                    sA.sleep(250);
                sA.client.getBank().depositAll();
            }
	}
        return false;
    }

    @Override
    public boolean execute() throws InterruptedException {
        if(sA.client.getInventory().contains(Constants.COWHIDE)){
            if(openBank()) {

            }
        }
        
        return true;
    }
    
}

I believe myself to be relatively capable of programming in Java. It is odd that it keeps throwing a NullPointerException on Line 43 Validate() function.

 

Any advice would be helpful. I believe it is something to do with the Script object being null when parsed to the Banking class.

return sA.client.getLocalNPCs().contains("Banker");

Not sure if you meant this or not, but you're checking if a list of NPC objects contains a String.

 

As for the NPE, show us your abstract Node class.

you're checking if a List of NPCs contains a string. Use closestNPCForName

Edited by kuuhaku

  • Author
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package core;

import org.osbot.script.Script;

/**
 *
 * @author LivingRoom
 */
public abstract class Node {
    
    public Script sA;
    
    public Node(Script A) {
        this.sA = sA;
    }
    
    public String status() {
        return "";
    }
    
    public abstract boolean validate() throws InterruptedException;
    public abstract boolean execute() throws InterruptedException;
}

Node class.

 

and by goodness, you guys are incredibly prompt at helping!

 

 

 

EDIT:

 

changed the validate to return this:

return sA.closestObject(BANKOBJECT_ID) != null;

but still causes an NullPointerException

Edited by sesamest

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package core;

import org.osbot.script.Script;

/**
 *
 * @author LivingRoom
 */
public abstract class Node {
    
    public Script sA;
    
    public Node(Script A) {
        this.sA = sA;
    }
    
    public String status() {
        return "";
    }
    
    public abstract boolean validate() throws InterruptedException;
    public abstract boolean execute() throws InterruptedException;
}

Node class.

 

and by goodness, you guys are incredibly prompt at helping!

 

I have no life, nor friends, nor loved ones.

 

You misspelled sA (what you meant to type) in the Node constructor argument. Right now you're just assigning the instance variable sA a reference to itself which is, of course, null.

Edited by Swizzbeat

  • Author

That is terrible of me.

 

Thank you very much for being so in-depth in reading my lazy code.

@ OP with your node class you might want to invest some time into making a controller class and maybe having a  priority abstract integer:

 

so that if two nodes are valid it will choose the one with the higher priority

 

 

have methods as such in mine...

 

 

ab838a26a3.png

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.