Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • AbstractScript - help


    abdulr
     Share

    Recommended Posts

    I basically want to create a class where I will include many functions. The purpose of these functions will be for anti-ban, so each function will do a different anti-ban measure.

    How do I implement AbstractScript without having to implement the method onLoop()

     

    This is the anti-ban class

    public class Anti_Ban extends AbstractScript {
    
        @Override
        public int onLoop() {
            return 0;
        }
    
        void addFriend() {
            getFriends().addFriend("Mod Mark");
        }
    }

     

    Im calling the class anti_ban on a different class,

    private Anti_Ban a = new Anti_Ban();

     

    (I know code is absolutely disgusting but I just wanted to see if it worked) but this code doesn't work even tho it executes

    @Override
    public int execute() {
        a.addFriend();
    
        c.getGameObjects().closest("Tree").interact("Chop down");
        return 1000;
    }

     

    Thanks to whoever helps <3 

    Link to comment
    Share on other sites

    Only extend AbstractScript in your main class, you can do it like this:

    Firstly in your Anti_Ban class:

    import org.dreambot.api.script.AbstractScript; //Import AbstractScript
    
    public class Anti_Ban {
    	//create instance of AbstractScript
    	private AbstractScript s;
    
    	//Constructor to allow our class file to access AbstractScript (This is called from Main class)
    	public Anti_Ban(AbstractScript script) {
    		this.s = script;
    	}

    Then in your Main class declare this:

    //Creates a new Antiban object called antiBan using the AntiBan constructor passing in the context	
    Anti_Ban antiBan = new Anti_Ban(this);

    Your methods in the Anti_Ban class would then look something like..

        public void addFriend() {
            s.getFriends().addFriend("Mod Mark"); //Notice we are calling the method 'getFriends' against our instance of AbstractClass 's'
        }

    You can access your Anti_ban methods from your Main class by doing:

    antiBan.addFriend();

     

    Hopefully that makes sense

    Edited by kingsolo
    Link to comment
    Share on other sites

    your code works perfect,

    this line of code works perfect in the main class

    Anti_Ban antiBan = new Anti_Ban(this);
    

    but when i try to add this in my node classes e.g. chop, i get an error

    Anti_Ban antiBan = new Anti_Ban(this);

    the 'this' becomes an error

    Link to comment
    Share on other sites

    If you're using nodes I believe you will have to do what I said not in the Main class but in your Node class, you then extend your Node class to your other nodes and they will all be able to access the AbstractScript methods.

    I'm unfamiliar with node classes i'm afraid

    Link to comment
    Share on other sites

    4 minutes ago, Nuclear Nezz said:

    You should probably try to learn a bit more about Java and how classes + OOP works. It'll help a lot, especially if you're dealing with nodes.

    yeah i will learn but atm i just want to know how to do so i can mess around with dreambot's api

    any idea how to do it?

    Link to comment
    Share on other sites

    3 minutes ago, abdulr said:

    yeah i will learn but atm i just want to know how to do so i can mess around with dreambot's api

    any idea how to do it?

    change the AbstractScript script; to MethodContext ctx;

    You'll still have all of the api methods (I assume you're using TaskNode)

    every TaskNode extends MethodContext.

    Personally, I would suggest just making your own Node class, that way you have more control over what you have access to when you need it, then use an AbstractScript for your main script class, and handle the nodes on your own in the onLoop.

    Link to comment
    Share on other sites

    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
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.