Jump to content

My node class! everything looks clean but not start -_-


TheGreatests

Recommended Posts

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;

}




Data constants class (alot of stuff in data im not using)

package data;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.script.MethodProvider;

public class Data {
    public Area b = new Area(1674, 3564, 1676, 3559);
    public Area west = new Area(1665, 3549, 1673, 3543);
    public Area ClayAreaN = new Area(1683, 3533, 1691, 3527);
    public Area ClayAreaS = new Area(1705, 3550, 1713, 3543);
    public Area seast = new Area(1713, 3522, 1720, 3516);
    public Area swest = new Area(1685, 3516, 1691, 3510);
    private int currentWorld = 0;
    
    public int clay = 435;
    
    private String status = "Initializing...";
    public static int[] Worlds = {2, 3, 4, 5, 6, 9, 10, 11,
        12, 14, 18, 19, 20, 22, 27, 28, 29, 30, 33, 34, 36, 38, 41,
        42, 43, 44, 46, 50, 51, 52, 54, 58, 59, 60, 62, 67, 68, 69, 70,
        74, 76, 77, 78, 86};
    public static int worldCounter;
    public int counter;
    
    public void setCurrentWorld(int c) {
        currentWorld = c;
    }
    
    public int getCurrentWorld() {
        return currentWorld;
    }
    
    public int MinningOres = 952, SALT = 13421,
            STAM = 12631, STAM3 = 12627, STAM2=  12629, STAM4 = 12625,
            VIAL = 229;
    
    private boolean staminaUsage;
    private boolean worldHopUsage;
        
    
    /*public Constants(boolean staminaUsage, boolean worldHopUsage) {
        this.staminaUsage = staminaUsage;
        this.worldHopUsage = worldHopUsage;
    }    */
    
    public boolean getStaminaUsage() {
        return staminaUsage;
    }
    
    public boolean getWorldHopUsage() {
        return worldHopUsage;
    }
    public void sleep(int min, int max) throws InterruptedException {
        sleep(MethodProvider.random(min, max), max);
    }
    public void RandomSleep() throws InterruptedException {

        switch(MethodProvider.random(0, 5)) {
        case 0:
            sleep(650, 1250);
            break;

        case 1:  
            sleep(1450, 2050);
            break;

        case 2:
            sleep(2250, 2850);
            break;

        case 3:
            sleep(3050, 3850);
            break;
        }
    }
    
    public void setStatus(String s) {
        if (!s.equals(this.status)) {
            this.status = s;
        }
    }
    
    public String getStatus() {
        return this.status;
    }
    
}

Trading node class

package nodes;

import org.osbot.rs07.api.Inventory;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.script.Script;

import Scripts.Node;
import data.Data;

public class Trading extends Node{
    Data c = new Data();
    private Script s;
    @SuppressWarnings("unused")
    private Player me;
    @SuppressWarnings("unused")
    private Inventory inv;
    @SuppressWarnings("unused")
    private Data data;

    public Trading(Script sA) {
        super(sA);
        // TODO Auto-generated constructor stub
    }
    public String status(){
        return "Our mule is trading with us";
    }
    public boolean validate() throws InterruptedException{
        //int count = 0;
        Player player = s.players.closest("L3gendsNight");
        return player.isInteracting(s.myPlayer());
    }

    public boolean execute() throws InterruptedException{
        status();
        Player player = s.players.closest("L3gendsNight");
        player.hover(); MethodProvider.random(400, 850);
        player.interact("Trade with");
        return false;
    }

}


Intrade node class

package nodes;

import org.osbot.rs07.api.Inventory;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.script.Script;

import Scripts.Node;
import data.Data;
public class InTrade extends Node {
    private boolean isTrading() {
        return s.trade.isCurrentlyTrading();
    }
    public String status;
    Data c = new Data();
    private Script s;
    @SuppressWarnings("unused")
    private Player me;
    @SuppressWarnings("unused")
    private Inventory inv;
    @SuppressWarnings("unused")
    private Data data;


    public InTrade(Script sA) {
        super(sA);
        // TODO Auto-generated constructor stub
    }
    public String status(){
        return "In trade";

    }

    @[member=Override]
    public boolean validate() throws InterruptedException {
        // TODO Auto-generated method stub
        return s.trade.isFirstInterfaceOpen() || s.trade.isSecondInterfaceOpen();
    }

    @[member=Override]
    public boolean execute() throws InterruptedException {
        // TODO Auto-generated method stub
        s.trade.acceptTrade();
        status =("Accepted first trade interface");
        while(isTrading() && !s.trade.didOtherAcceptTrade()){
            MethodProvider.random(250,800);
            return false;
        }
        return true;
    }
}


Wait node class:

package nodes;

import org.osbot.rs07.api.Inventory;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.script.Script;

import Scripts.Node;
import data.Data;

public class Wait extends Node {

    public Wait(Script sA) {
        super(sA);
        // TODO Auto-generated constructor stub
    }
    public String status;
    Data c = new Data();
    private Script s;
    @SuppressWarnings("unused")
    private Player me;
    @SuppressWarnings("unused")
    private Inventory inv;
    private Data data;
    Player player = s.players.closest("L3gendsNight");
    @[member=Override]
    public boolean validate() throws InterruptedException {
        // TODO Auto-generated method stub
        return !player.isInteracting(s.myPlayer()) && !s.trade.isFirstInterfaceOpen() || !s.trade.isSecondInterfaceOpen();
    }

    @[member=Override]
    public boolean execute() throws InterruptedException {
        // TODO Auto-generated method stub
        status = "We are sleeping";
        data.RandomSleep();
        return true;
    }


}


Main class -

package Scripts;
import nodes.ClayMine;
import nodes.InTrade;
import nodes.Trading;
import nodes.Wait;

import org.osbot.s;
import org.osbot.rs07.api.Inventory;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import data.Data;

import java.awt.*;
import java.lang.Thread.State;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

@SuppressWarnings("unused")
@ScriptManifest(author = "Elvito", info = "Trades with mule", name = "MuleTrader V2", version = 1.0, logo = "Trades with mule")
public class MuleTrader extends Script {
	public static Data data;
	//private SettingsGUI gui;
	private long lobsterCaught;
	private int fishExpGained;
	private long startTime;
	public String status;
	private Inventory inv;
	private List<Node> nodes = new ArrayList<Node>();


	public void onStart() {
		//createGUI();
		Collections.addAll(nodes,  
				new Wait(this), 
				new Trading(this), 
				new InTrade(this)); //new ClayMine(this)  If you want to add the mining clay
		//various checks to see  if show the gui yet
	}
	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);
	}

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

	private State getState() {
		return null;
	}

	@[member='Override']
	public void onExit() {
		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);
	}

	@[member='Override']
	public void onPaint(Graphics2D g) {

		g.setColor(Color.MAGENTA);
		g.drawString("dontbuzz Karamja Lobster", 10, 40);

		fishExpGained = getExperienceTracker().getGainedXP(Skill.FISHING);
		g.setColor(Color.black);
		g.drawString("Status  " + status, 10, 55);

		lobsterCaught = inv.getAmount(435);
		g.drawString("Ores traded " + lobsterCaught, 10, 70);

		final long runTime = System.currentTimeMillis() - startTime;
		g.drawString("Time Running " + formatTime(runTime), 10, 85);
	}

}

Have no clue why it is not starting, no logs are shown...

Edited by TheGreatests
Link to comment
Share on other sites

What exactly does Override do at this instances? Would it allow the loop to continue forth if a eruption has been made?

Override is needed because those methods are abstract methods in the Script class. The runnable scripts inherit Script class, without override when onStart/onLoop/etc. is called from the super class it is not able to be called in the inherited class because the abstract method wasn't overriden.

Edited by Trees
Link to comment
Share on other sites

Override is needed because those methods are abstract methods in the Script class. The runnable scripts inherit Script class, without override when onStart/onLoop/etc. is called from the super class it is not able to be called in the inherited class because the abstract method wasn't overriden.

 

Awesome!, I declared overrides on both of the Loop, and start. It worked however it closed once again. Ive even tried to debug it using system prints, and I cant even seem to get into my wait node.

[ERROR][bot #1][10/20 03:17:14 AM]: Error in script onStart(): MuleTrader V10

java.lang.NullPointerException

    at data.Data.<init>(Data.java:31)

    at nodes.Trading.<init>(Trading.java:12)

    at Scripts.MuleTrader.onStart(MuleTrader.java:39)

    at org.osbot.rs07.event.ScriptExecutor.IiiIiiiIiiiI(gp:279)

    at org.osbot.rs07.event.ScriptExecutor.start(gp:30)

    at org.osbot.c.run(su:200)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

    at java.lang.Thread.run(Unknown Source)

[iNFO][bot #1][10/20 03:17:14 AM]: Terminating script MuleTrader V10...

[iNFO][bot #1][10/20 03:17:14 AM]: Thanks for running the script!

[iNFO][bot #1][10/20 03:17:14 AM]: Script MuleTrader V10 has exited!

[iNFO][bot #1][10/20 03:17:14 AM]: Started script : MuleTrader V10

 

Link to comment
Share on other sites

Awesome!, I declared overrides on both of the Loop, and start. It worked however it closed once again. Ive even tried to debug it using system prints, and I cant even seem to get into my wait node.

[ERROR][bot #1][10/20 03:17:14 AM]: Error in script onStart(): MuleTrader V10

java.lang.NullPointerException

    at data.Data.<init>(Data.java:31)

    at nodes.Trading.<init>(Trading.java:12)

    at Scripts.MuleTrader.onStart(MuleTrader.java:39)

    at org.osbot.rs07.event.ScriptExecutor.IiiIiiiIiiiI(gp:279)

    at org.osbot.rs07.event.ScriptExecutor.start(gp:30)

    at org.osbot.c.run(su:200)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

    at java.lang.Thread.run(Unknown Source)

[iNFO][bot #1][10/20 03:17:14 AM]: Terminating script MuleTrader V10...

[iNFO][bot #1][10/20 03:17:14 AM]: Thanks for running the script!

[iNFO][bot #1][10/20 03:17:14 AM]: Script MuleTrader V10 has exited!

[iNFO][bot #1][10/20 03:17:14 AM]: Started script : MuleTrader V10

 

 

Not sure it's the issue, but in your Data class it seems like you have a recursive call to sleep, which would cause an infinite loop. Need to use the methodprovider sleep inside the sleep method.

Link to comment
Share on other sites

Not sure it's the issue, but in your Data class it seems like you have a recursive call to sleep, which would cause an infinite loop. Need to use the methodprovider sleep inside the sleep method.

 

    case 0:

            MethodProvider.random

            break;

 

 

??

Edited by TheGreatests
Link to comment
Share on other sites

case 0:

            MethodProvider.random

            break;

 

 

??

 

No here:

   public void sleep(int min, int max) throws InterruptedException {
        sleep(MethodProvider.random(min, max), max);
    }
There's also a problem with that switch statement because 4 and 5 (?, forget if random is inclusive or not) aren't handled.
Link to comment
Share on other sites

 

No here:

   public void sleep(int min, int max) throws InterruptedException {
        sleep(MethodProvider.random(min, max), max);
    }
There's also a problem with that switch statement because 4 and 5 (?, forget if random is inclusive or not) aren't handled.

 

 

Yup I corrected these awhile back, and used MethodProvider just like you mentioned. still messed up, here is my modified code now for my wait class. and the data class

package nodes;

import org.osbot.rs07.api.Inventory;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.script.Script;

import Scripts.Node;
import data.Data;

public class Wait extends Node {

    public Wait(Script sA) {
        super(sA);
        // TODO Auto-generated constructor stub
    }
    public boolean isTrading(){
        return s.trade.isCurrentlyTrading();
    }
    public String status(){
        return "In our waiting method";
    }
    public String status;
    Data c = new Data();
    private Script s;
    @SuppressWarnings("unused")
    private Player me;
    @SuppressWarnings("unused")
    private Inventory inv;
    private Data data;
    @[member=Override]
    public boolean validate() throws InterruptedException {
        // TODO Auto-generated method stub
        return !isTrading();
    }

    @[member=Override]
    public boolean execute() throws InterruptedException {
        // TODO Auto-generated method stub
        System.out.println("We are in the wait class");
        status = "We are sleeping";
        data.RandomSleep();
        return true;
    }


}

^^^ Wait class

package data;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.script.MethodProvider;

public class Data {
	public Area b = new Area(1674, 3564, 1676, 3559);
	public Area west = new Area(1665, 3549, 1673, 3543);
	public Area ClayAreaN = new Area(1683, 3533, 1691, 3527);
	public Area ClayAreaS = new Area(1705, 3550, 1713, 3543);
	public Area seast = new Area(1713, 3522, 1720, 3516);
	public Area swest = new Area(1685, 3516, 1691, 3510);
	private int currentWorld = 0;
	public int clay = 435;
	private String status = "Initializing...";
	public static int[] Worlds = {2, 3, 4, 5, 6, 9, 10, 11,
		12, 14, 18, 19, 20, 22, 27, 28, 29, 30, 33, 34, 36, 38, 41,
		42, 43, 44, 46, 50, 51, 52, 54, 58, 59, 60, 62, 67, 68, 69, 70,
		74, 76, 77, 78, 86};
	public static int worldCounter;
	public int counter;
	public void setCurrentWorld(int c) {
		currentWorld = c;
	}
	public int getCurrentWorld() {
		return currentWorld;
	}
	
	public int MinningOres = 952, SALT = 13421,
			STAM = 12631, STAM3 = 12627, STAM2=  12629, STAM4 = 12625,
			VIAL = 229;
	
	private boolean staminaUsage;
	private boolean worldHopUsage;
		
	
	/*public Constants(boolean staminaUsage, boolean worldHopUsage) {
		this.staminaUsage = staminaUsage;
		this.worldHopUsage = worldHopUsage;
	}	*/
	
	public boolean getStaminaUsage() {
		return staminaUsage;
	}
	
	public boolean getWorldHopUsage() {
		return worldHopUsage;
	}
	public void sleep(int min, int max) throws InterruptedException {
		sleep(MethodProvider.random(min, max), max);
	}
	public void RandomSleep() throws InterruptedException {

		switch(MethodProvider.random(0, 4)) {
		case 0:
			MethodProvider.random(650, 1250);
			break;

		case 1:  
			MethodProvider.random(1450, 2050);
			break;

		case 2: 
			MethodProvider.random(2250, 2850);
			break;

		case 3:
			MethodProvider.random(3050, 3850);
			break;
		}
	}
	
	public void setStatus(String s) {
		if (!s.equals(this.status)) { 
			this.status = s;
		}
	}
	
	public String getStatus() {
		return this.status;
	}
	
}

^^ data class...

 

Still freezes, it gives me a log saying that there is something wrong with the isTrading() validation, however ive tried nearly everything.

Edited by TheGreatests
Link to comment
Share on other sites

Still freezes, it gives me a log saying that there is something wrong with the isTrading() validation, however ive tried nearly everything.

The player is null.

return player != null && player.isInteracting(s.myPlayer());
For future reference try/catch usually helps a lot. Edited by Trees
Link to comment
Share on other sites

The player is null.

return player != null && player.isInteracting(s.myPlayer());
For future reference try/catch usually helps a lot.

 

 

Yup, I tried this way just to test it out, this is the wait class

package nodes;

import org.osbot.rs07.api.Inventory;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.script.Script;

import Scripts.Node;
import data.Data;

public class Wait extends Node {

	public Wait(Script sA) {
		super(sA);
		// TODO Auto-generated constructor stub
	}
	public boolean isTrading(){
		return s.trade.isCurrentlyTrading();
	}
	public String status(){
		return "In our waiting method";
	}
	public String status;
	Data c = new Data();
	private Script s;
	@SuppressWarnings("unused")
	private Player me;
	@SuppressWarnings("unused")
	private Inventory inv;
	private Data data;
	@[member=Override]
	public boolean validate() throws InterruptedException {
		// TODO Auto-generated method stub
		return !isTrading();
	}

	@[member=Override]
	public boolean execute() throws InterruptedException {
		// TODO Auto-generated method stub
		System.out.println("We are in the wait class");
		status = "We are sleeping";
		data.RandomSleep();
		return true;
	}

Im not sure why that class was posted, that was long ago.

The player is null.

return player != null && player.isInteracting(s.myPlayer());
For future reference try/catch usually helps a lot.

 

 

My wait class is throwing nullpointers at wait.isTrading (wait.java: 17) <-- Which is the is trading boolean

and line 33 which is the validation for isTrading... Wondering if I need to do null checks? but how would you do that?

 

s.trade.isCurrentlyTrading != null?

Link to comment
Share on other sites

Override is needed because those methods are abstract methods in the Script class. The runnable scripts inherit Script class, without override when onStart/onLoop/etc. is called from the super class it is not able to be called in the inherited class because the abstract method wasn't overriden.

You don't actually NEED the @ Override annotation, it just improves readability and helps the compiler a little bit. It would work just fine without it

Edited by Explv
  • Like 2
Link to comment
Share on other sites

Yup, it hasnt fixed the lag at all. Anyone else know a reason why its lagging out?

In your Trading, InTrade and Wait classes you are using the Script variable 's' . This variable is never initialised. What you should be using is 'sA' which is the Script variable set in your Abstract Node class:

package Scripts;

import org.osbot.rs07.script.Script;

public abstract class Node {

	protected final Script sA; // <------ You should be using this variable

	public Node(final Script sA){
            this.sA = sA;
	}

	public String status(){
	    return "";
	}

	public abstract boolean validate() throws InterruptedException;
	public abstract boolean execute() throws InterruptedException;
}

Here is an example of where you are using the wrong variable:

package nodes;

import org.osbot.rs07.api.Inventory;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.script.Script;

import Scripts.Node;
import data.Data;

public class Trading extends Node{
    Data c = new Data();
    private Script s; // <-------- You shouldn't have another Script variable here
    @SuppressWarnings("unused")
    private Player me;
    @SuppressWarnings("unused")
    private Inventory inv;
    @SuppressWarnings("unused")
    private Data data;

    public Trading(Script sA) {
        super(sA); // <--------------- You are already setting the Script variable sA here
    }

    // ... Rest of your code
}
Edited by Explv
Link to comment
Share on other sites

 

In your Trading, InTrade and Wait classes you are using the Script variable 's' . This variable is never initialised. What you should be using is 'sA' which is the Script variable set in your Abstract Node class:

package Scripts;

import org.osbot.rs07.script.Script;

public abstract class Node {

	protected final Script sA; // <------ You should be using this variable

	public Node(final Script sA){
            this.sA = sA;
	}

	public String status(){
	    return "";
	}

	public abstract boolean validate() throws InterruptedException;
	public abstract boolean execute() throws InterruptedException;
}

Here is an example of where you are using the wrong variable:

package nodes;

import org.osbot.rs07.api.Inventory;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.script.Script;

import Scripts.Node;
import data.Data;

public class Trading extends Node{
    Data c = new Data();
    private Script s; // <-------- You shouldn't have another Script variable here
    @SuppressWarnings("unused")
    private Player me;
    @SuppressWarnings("unused")
    private Inventory inv;
    @SuppressWarnings("unused")
    private Data data;

    public Trading(Script sA) {
        super(sA); // <--------------- You are already setting the Script variable sA here
    }

    // ... Rest of your code
}

 

Awesome tyvm, switched it over. It works, however now somehow my data.RandomSleep() is throwing a null. Its  using a method from the data class.. Why would it throw a null.. Do I need to make a instance of this?

 

And I did just that, and it worked.  Used sleep.RandomSleep();  and made a instance of the Data class by Data sleep = new Data();

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