Jump to content

Having issues with my damn fisher, I dont know wtf is wrong@!


TheGreatests

Recommended Posts

Hello All, figure I would share my fisher to the public. Some strange reason I am lagging out, and the nodes dont seem to execute at all. I had it picking salmon but after full inventory it laggs out.

 

Loot Node:

package GreatestFisher;

import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.script.Script;

import Scripts.Node;
import data.Data;

public class Loot extends Node {
	public void getTypeAndLog(GroundItem items){
		caller.log = ("[Debug] ground type: " + items.getName() + ("picking up..."));
	}
	Data d = new Data();
	FishNLoot caller = new FishNLoot();
	GroundItem item = sA.groundItems.closest(331);
	GroundItem item2 = sA.groundItems.closest(335);
	public Loot(Script sA) {
		super(sA);
		// TODO Auto-generated constructor stub
	}
	public boolean validate() throws InterruptedException{
		//item.interact("Take");
		return item !=null && !sA.inventory.isFull() && d.FishingSpot.contains(sA.players.myPosition()) ;
	}
	public boolean execute() throws InterruptedException {
		caller.log = "Looting!";
		if(item !=null && item.isOnScreen()){
			caller.log = "We are picking up " +item.getName();
			item.interact("Take");
		}
		else{
			sA.camera.toEntity(item);
		}
		if(item2 !=null && item2.isOnScreen()){
			caller.log = "We are picking up " +item.getName();
			item2.interact("Take");
			getTypeAndLog(item);
		}
		else{
			sA.camera.toEntity(item2);
		}
		return false;

	}
}

FishNLoot main :

package GreatestFisher;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.lang.Thread.State;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.osbot.rs07.api.Inventory;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import Scripts.Node;
import data.Data;

@ScriptManifest(author = "Elvitos Fisher", info = "Fishes+Loots", name = "Fishing and Loot", version = .1, logo = "Loots while fishing")
public class FishNLoot extends Script{


		public static Data data;
		//private SettingsGUI gui;
		public long OresTransfeered;
		public long startTime;
		public String status;
		public String log;
		private Inventory inv;
		private long elapsed;
		private boolean isRunning = false;
		private List<Node> nodes = new ArrayList<Node>();


		public void onStart() {
			//createGUI();
			isRunning = true;
			Collections.addAll(nodes,    
					new Loot(this),
					new Fish(this),
					new Banking(this),
					new Bank(this)); //new ClayMine(this)  If you want to add the mining clay
			//various checks to see  if show the gui yet
			Thread runTimeThread = new Thread() {

				@[member=Override]
				public void run() {
					try {
						RunTime();
					}
					catch (Exception e) {
						log(e.getMessage());
					}
				}
			};

			runTimeThread.start();
		}
		public int onLoop() throws InterruptedException{
			for (Node n : nodes){
				if(n.validate()){
					status = n.status();
					if(n.execute())	{
						return random(200,400);
					}
				}
			}
			return  random(250,400);
		}

		@SuppressWarnings("unused")
		private void createGUI() {
			// TODO Auto-generated method stub
			//code for the GUI
		}

		@SuppressWarnings("unused")
		private State getState() {
			return null;
		}

		@[member=Override]
		public void onExit() {
			isRunning = false;
			log("Thanks for running the script!");
		}
		public final String formatTime(final long ms){
			long s = ms / 1000, m = s / 60, h = m / 60;
			s %= 60; m %= 60; h %= 24;
			return String.format("%02d:%02d:%02d", h, m, s);
		}
		private void RunTime() throws InterruptedException {

			long startTime = System.currentTimeMillis();

			while(isRunning) {
				elapsed = (System.currentTimeMillis() - startTime);
				sleep(1000);
			}
		}
		private String GetRunTime() {

			long hours = (elapsed / (1000 * 60 * 60)) % 24;
			long minutes = (elapsed / (1000 * 60)) % 60;
			long seconds = (elapsed / 1000) % 60;

			return String.format("%02d:%02d:%02d", hours, minutes, seconds);
		}

		@[member=Override]
		public void onPaint(Graphics2D g) {
			int x = getMouse().getPosition().x;
			int y = getMouse().getPosition().y;

			g.drawLine(0, y, 765, y);
			g.drawLine(x, 0, x, 503);

			DrawUpdate(g);
		}
		private void DrawUpdate(Graphics2D g) {

			g.setColor(new Color(0, 0, 0, 80));
			g.fillRect(4, 280, 512, 58);

			g.setColor(Color.white);
			g.setFont(new Font("Consolas", Font.PLAIN, 12));
			//g.drawString("Mule trader script by Elvito!", 10, 40);
			g.drawString("Status  " + status, 10, 55);
			g.drawString("log  " + log, 20, 371);
			@SuppressWarnings("unused")
			final long runTime = System.currentTimeMillis() - startTime;
			g.setColor(Color.GREEN);
			g.drawString("RunTime: " + GetRunTime(), 16, 325);
			OresTransfeered =+ inv.getAmount(435);
			g.drawString("Ores traded " + OresTransfeered, 561, 449);
		}

	}




fish node:

package GreatestFisher;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.lang.Thread.State;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.osbot.rs07.api.Inventory;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import Scripts.Node;
import data.Data;

@ScriptManifest(author = "Elvitos Fisher", info = "Fishes+Loots", name = "Fishing and Loot", version = .1, logo = "Loots while fishing")
public class FishNLoot extends Script{


		public static Data data;
		//private SettingsGUI gui;
		public long OresTransfeered;
		public long startTime;
		public String status;
		public String log;
		private Inventory inv;
		private long elapsed;
		private boolean isRunning = false;
		private List<Node> nodes = new ArrayList<Node>();


		public void onStart() {
			//createGUI();
			isRunning = true;
			Collections.addAll(nodes,    
					new Loot(this),
					new Fish(this),
					new Banking(this),
					new Bank(this)); //new ClayMine(this)  If you want to add the mining clay
			//various checks to see  if show the gui yet
			Thread runTimeThread = new Thread() {

				@[member=Override]
				public void run() {
					try {
						RunTime();
					}
					catch (Exception e) {
						log(e.getMessage());
					}
				}
			};

			runTimeThread.start();
		}
		public int onLoop() throws InterruptedException{
			for (Node n : nodes){
				if(n.validate()){
					status = n.status();
					if(n.execute())	{
						return random(200,400);
					}
				}
			}
			return  random(250,400);
		}

		@SuppressWarnings("unused")
		private void createGUI() {
			// TODO Auto-generated method stub
			//code for the GUI
		}

		@SuppressWarnings("unused")
		private State getState() {
			return null;
		}

		@[member=Override]
		public void onExit() {
			isRunning = false;
			log("Thanks for running the script!");
		}
		public final String formatTime(final long ms){
			long s = ms / 1000, m = s / 60, h = m / 60;
			s %= 60; m %= 60; h %= 24;
			return String.format("%02d:%02d:%02d", h, m, s);
		}
		private void RunTime() throws InterruptedException {

			long startTime = System.currentTimeMillis();

			while(isRunning) {
				elapsed = (System.currentTimeMillis() - startTime);
				sleep(1000);
			}
		}
		private String GetRunTime() {

			long hours = (elapsed / (1000 * 60 * 60)) % 24;
			long minutes = (elapsed / (1000 * 60)) % 60;
			long seconds = (elapsed / 1000) % 60;

			return String.format("%02d:%02d:%02d", hours, minutes, seconds);
		}

		@[member=Override]
		public void onPaint(Graphics2D g) {
			int x = getMouse().getPosition().x;
			int y = getMouse().getPosition().y;

			g.drawLine(0, y, 765, y);
			g.drawLine(x, 0, x, 503);

			DrawUpdate(g);
		}
		private void DrawUpdate(Graphics2D g) {

			g.setColor(new Color(0, 0, 0, 80));
			g.fillRect(4, 280, 512, 58);

			g.setColor(Color.white);
			g.setFont(new Font("Consolas", Font.PLAIN, 12));
			//g.drawString("Mule trader script by Elvito!", 10, 40);
			g.drawString("Status  " + status, 10, 55);
			g.drawString("log  " + log, 20, 371);
			@SuppressWarnings("unused")
			final long runTime = System.currentTimeMillis() - startTime;
			g.setColor(Color.GREEN);
			g.drawString("RunTime: " + GetRunTime(), 16, 325);
			OresTransfeered =+ inv.getAmount(435);
			g.drawString("Ores traded " + OresTransfeered, 561, 449);
		}

	}




Banking Node:

package GreatestFisher;

import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;

import Scripts.Node;
import data.Data;

public class Banking extends Node {
	FishNLoot caller = new FishNLoot();
	NPC banker = sA.npcs.closest(395);
	Data supply = new Data();
	public Banking(Script sA) {
		super(sA);
		// TODO Auto-generated constructor stub
	}
	public boolean validate() throws InterruptedException{
		return banker!=null && banker.isOnScreen();
		
	}
	public boolean execute() throws InterruptedException{
		if(sA.bank.isOpen()){
			sA.bank.depositAllExcept(supply.F_equipment);
		}
		else{
		}
		sA.bank.open();
		
		caller.log ="Banking";
		return false;
		
	}

}

Bank node:

package GreatestFisher;

import org.osbot.rs07.api.Players;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.event.WebWalkEvent;
import org.osbot.rs07.script.Script;

import Scripts.Node;
import data.Data;
import nodes.Wait;

@SuppressWarnings("unused")
public class Bank extends Node {
	private Data data;

	NPC banker = sA.npcs.closest(395);
	public Bank(Script sA) {
		super(sA);
		// TODO Auto-generated constructor stub
	}
	public boolean validate() throws InterruptedException{

			//// Checking if inventory is full, and if so, is our player in the bank or not
		return 
				sA.inventory.isFull() && !data.EBank.contains(sA.players.myPosition())
				&& !banker.isOnScreen();
	}
	public boolean execute() throws InterruptedException {
		sA.settings.setRunning(true);
		WebWalkEvent webEvent = new WebWalkEvent(Banks.EDGEVILLE);
		webEvent.execute();
		return false;
	}
}





Node class:

package Scripts;

import org.osbot.rs07.script.Script;

public abstract class Node {
	public Script sA;
	public Node(Script sA){
		this.sA = sA;
	}
	public String status(){
		return "";
	}
	public abstract boolean validate() throws InterruptedException;
	public abstract boolean execute() throws InterruptedException;

}




Any help at all would be amazing. Im lagging out soon as inventory is full. I used Dunks Path maker for the area.

When I exported the jar, i included my Data constant class, and my Node.java class also.

Link to comment
Share on other sites

 

You say you lag out as soon as you get a full inventory. Maybe you are getting a nullpointer?

NPC banker = sA.npcs.closest(395);

Try and test if (banker != null) before trying to use banker in your validate()

&& !banker.isOnScreen();

 

Banking works very good, just having issues with the bank node.

Lines 26 which is

the return in the validation boolean.

Ahh null checker on Banker!

					catch (Exception e) {
						log(e.getMessage());
					}

Can throw a null pointer as well. Store, then null check the return of e.getMessage()

 

 

How?

Lovely now, im getting a null pointer on webWalk event..

 

You say you lag out as soon as you get a full inventory. Maybe you are getting a nullpointer?

NPC banker = sA.npcs.closest(395);

Try and test if (banker != null) before trying to use banker in your validate()

&& !banker.isOnScreen();

 

Should I store the variable with a int, and then call it

 

!(banker != null)

Link to comment
Share on other sites

Banking works very good, just having issues with the bank node.

Lines 26 which is

the return in the validation boolean.

Ahh null checker on Banker!

 

How?

Lovely now, im getting a null pointer on webWalk event..

 

Should I store the variable with a int, and then call it

 

!(banker != null)

 

Am tired

public boolean validate() throws InterruptedException{

            //// Checking if inventory is full, and if so, is our player in the bank or not
        return
                sA.inventory.isFull() && !data.EBank.contains(sA.players.myPosition()) &&
                (banker !=null && !banker.isOnScreen());
    }
Edited by Hayase
Link to comment
Share on other sites

 

Here's a dirty nasty way I would do it:

public boolean validate() throws InterruptedException{
    boolean bankerVisible = true;
    if(banker !=null) {
        if(!banker.isOnScreen())
            bankerVisible = false;
    }

			//// Checking if inventory is full, and if so, is our player in the bank or not
		return 
				sA.inventory.isFull() && !data.EBank.contains(sA.players.myPosition())
				&& !bankerVisible;
	}

 

Basically making myself a method to validate the banker being on screen. I deleted that, now the big problem

 

couldnt you also do

if(Banker !=null {

NotThere = false;

return sA....blah blah && NotThere = true;

 

Anyways, im having issues with a null pointer check on the webEvent.execute(); method... you ever use it to run to banks?

What I did instead of the event walker -

@SuppressWarnings("unused")
public class Bank extends Node {
	Data data = new Data();
	NPC banker = sA.npcs.closest(395);
	public Bank(Script sA) {
		super(sA);
		// TODO Auto-generated constructor stub
	}
	private void MoveToZone(Area zone) throws InterruptedException {

		sA.walking.webWalk(zone.getRandomPosition());
	}
	public boolean validate() throws InterruptedException{

			//// Checking if inventory is full, and if so, is our player in the bank or not
		return 
				sA.inventory.isFull() && !data.EBank.contains(sA.players.myPosition());
	}
	public boolean execute() throws InterruptedException {
		sA.settings.setRunning(true);
		MoveToZone(Banks.EDGEVILLE);

 

 

Edited by TheGreatests
Link to comment
Share on other sites

I changed my mind.

public boolean validate() throws InterruptedException{

			//// Checking if inventory is full, and if so, is our player in the bank or not
		return 
				sA.inventory.isFull() && !data.EBank.contains(sA.players.myPosition()) &&
				(banker !=null && !banker.isOnScreen());
	}

Does this work like your Bank node?

 

Link to comment
Share on other sites

I changed my mind.

public boolean validate() throws InterruptedException{

			//// Checking if inventory is full, and if so, is our player in the bank or not
		return 
				sA.inventory.isFull() && !data.EBank.contains(sA.players.myPosition()) &&
				(banker !=null && !banker.isOnScreen());
	}

Does this work like your Bank node?

 

That wont work as you're null checking the banker, and would basically only validate that boolean if the banker is there.

 

Link to comment
Share on other sites

I won't go through the whole lot, because I found some problems in the very first segment of code which need addressing.

 

t5ssn9.png

 

Also, me personally, I'd avoid using the 'node' methodology, because it's encapsulation can be very restrictive, hard to maintain, and execution structure (onLoop) looks ugly and meaningless. I prefer to 'path of least resistance' method, which is something like:

 

onLoop() {

findSomething()

doSomethingToThatSomething()

getResults()

checkHealthAndRunIfNecessary()

}

 

You could use a enum state for this, but that's a lesser form of encapsulation, so I'd probably avoid that too.

Edited by liverare
  • Like 1
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...