sesamest Posted May 30, 2014 Share Posted May 30, 2014 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. Link to comment Share on other sites More sharing options...
Swizzbeat Posted May 30, 2014 Share Posted May 30, 2014 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. Link to comment Share on other sites More sharing options...
Dog_ Posted May 30, 2014 Share Posted May 30, 2014 (edited) you're checking if a List of NPCs contains a string. Use closestNPCForName Edited May 30, 2014 by kuuhaku Link to comment Share on other sites More sharing options...
sesamest Posted May 30, 2014 Author Share Posted May 30, 2014 (edited) /* * 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 May 30, 2014 by sesamest Link to comment Share on other sites More sharing options...
Swizzbeat Posted May 30, 2014 Share Posted May 30, 2014 (edited) /* * 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 May 30, 2014 by Swizzbeat Link to comment Share on other sites More sharing options...
sesamest Posted May 30, 2014 Author Share Posted May 30, 2014 That is terrible of me. Thank you very much for being so in-depth in reading my lazy code. Link to comment Share on other sites More sharing options...
TheScrub Posted May 30, 2014 Share Posted May 30, 2014 @ 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... Link to comment Share on other sites More sharing options...