abdulr 0 Share Posted December 18, 2018 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 Link to comment Share on other sites More sharing options...
kingsolo 15 Share Posted December 18, 2018 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 Link to comment Share on other sites More sharing options...
abdulr 0 Author Share Posted December 18, 2018 okay i will try this, thank you very much :))))))), exactly what i'm looking for Link to comment Share on other sites More sharing options...
abdulr 0 Author Share Posted December 18, 2018 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 More sharing options...
abdulr 0 Author Share Posted December 18, 2018 because while i'm chopping i want to activate this random anti-bans events Link to comment Share on other sites More sharing options...
kingsolo 15 Share Posted December 18, 2018 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 More sharing options...
abdulr 0 Author Share Posted December 18, 2018 I assume you code with one main class using switch cases for different tasks? Link to comment Share on other sites More sharing options...
Nuclear Nezz 2055 Share Posted December 18, 2018 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. Link to comment Share on other sites More sharing options...
abdulr 0 Author Share Posted December 18, 2018 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 More sharing options...
Nuclear Nezz 2055 Share Posted December 18, 2018 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.