Explicit 213 Share Posted January 6, 2015 This is useful if you want to add your own API's that DreamBot does not include by default or even override their standard ones. The first thing to do is create a generic class which all custom API methods can extend from: import org.dreambot.api.methods.MethodContext; /** * Created with IntelliJ IDEA * User: Anthony * Date: 1/6/15 */ public abstract class API<C extends MethodContext> { protected C ctx; public API(C ctx) { this.ctx = ctx; } } Our use of generics in the class declaration will allow us to reuse this class for any custom context implementation. Next we'll actually create our first custom API class: import org.dreambot.api.wrappers.interactive.Entity; /** * Created with IntelliJ IDEA * User: Anthony * Date: 1/6/15 */ public class Methods extends API<RS07Context> { public Methods(RS07Context ctx) { super(ctx); } public boolean interact(Entity entity, String action, boolean rightClick) { // example method return false; } } Our ctx variable will be available to this class since it's stored within the super class. Now to extend MethodContext: import org.dreambot.api.methods.MethodContext; /** * Created with IntelliJ IDEA * User: Anthony * Date: 1/6/15 */ public class RS07Context extends MethodContext { private final Methods methods; public RS07Context() { this.methods = new Methods(this); } public Methods getMethods() { return methods; } } RS07Context will be able to access all of the default API methods (#getBank, #getCombat, etc.) and also our custom #getMethods method. Set it up at script start within your main class and you're good to go: import org.dreambot.api.script.impl.TaskScript; /** * Created with IntelliJ IDEA * User: Anthony * Date: 1/6/15 */ public class Main extends TaskScript { private RS07Context ctx; @Override public void onStart() { ctx = new RS07Context(); getClient().getInstance().setMethodContext(null); ctx.registerContext(getClient()); } @Override public int onLoop() { ctx.getMethods()..... return 100; } } Link to comment Share on other sites More sharing options...
Pandemic 2798 Share Posted January 7, 2015 Nice tutorial, should prove useful to many Link to comment Share on other sites More sharing options...
aa68505670 0 Share Posted March 13, 2015 nice! Link to comment Share on other sites More sharing options...
Fran 99 Share Posted July 5, 2015 Interesting, thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.