Jump to content


Scripter II
  • Posts

  • Joined

  • Last visited

  • Days Won

  • Feedback


Everything posted by Explv

  1. It's not the true source code, it's just decompiled. You can see it in IntelliJ by right clicking something and selecting "go to > implementations"
  2. 1. You're creating a new instance of the Bank class, this is an OSBot API class which extends MethodProvider. Any class which extends MethodProvider needs to have some context provided, so that it has access to all the other OSBot API class instances (e.g. inventory, equipment, etc.). In your case, you have not provided this context, and so all of these API references are null. You don't *need* to create an instance of the Bank class anyway, because OSBot provides you one that is correctly setup, which you access via getBank(). 2. It is the `open` function throwing a null pointer exception. This means that something the open function is trying to access is null (again because you have not exchanged context, so the internal fields in the Bank class are null) You can see the open function here: On the 4th line of the function you can see `this.inventory.isItemSelected()` `this.inventory` will be null, as you have not exchanged context. Therefore this function call will throw a NullPointerException. This would probably work: Bank bank = new Bank(); bank.exchangeContext(getBot()); exchangeContext sets all the internal context fields in the API class instance using the provided Bot reference. You can see the implementation here: However there is no need for it, because you can access the already setup instance using `getBank()`.
  3. Published a new version to GitHub. Please let me know if you still have any of these issues https://github.com/Explv/Explvs-AIO/releases/latest SDN update will follow
  4. 1. Define your custom method provider, this extends OSBot's MethodProvider class, and then adds on / overrides functionality. In this example, I am overriding getInventory() with my own class which adds a "use" function. The CustomMethodProvider class defined below also supplies a custom "execute" function, which runs an Executable (a different class I have defined later) class CustomMethodProvider extends MethodProvider { private ExtendedInventory extendedInventory; private boolean hasContext; public void init(final Bot bot) { super.exchangeContext(bot); this.extendedInventory = new ExtendedInventory(); extendedInventory.exchangeContext(bot); hasContext = true; } public boolean hasContext() { return hasContext; } // Deprecated as exchangeContext(Bot bot, CustomMethodProvider methodProvider) should be used instead. @Deprecated public MethodProvider exchangeContext(final Bot bot) { return super.exchangeContext(bot); } public CustomMethodProvider exchangeContext(final Bot bot, final CustomMethodProvider methodProvider) { this.extendedInventory = methodProvider.extendedInventory; super.exchangeContext(bot); hasContext = true; return this; } @Override public ExtendedInventory getInventory() { return extendedInventory; } /** * Helper function which exchanges context with an Executable * (if not already exchanged), and then calls Executable::run * @param executable The Executable to execute * @throws InterruptedException */ public void execute(final Executable executable) throws InterruptedException { if (!executable.hasContext()) { executable.exchangeContext(getBot(), this); } executable.run(); } } Here is my "ExtendedInventory" class: class ExtendedInventory extends Inventory { public boolean isUsing(final String itemName) { return itemName.equals(getSelectedItemName()); } public boolean use(final String itemName) { if (isUsing(itemName)) { return true; } if (getInventory().interact("Use", itemName)) { Sleep.sleepUntil(() -> itemName.equals(getSelectedItemName()), 1000); return true; } return false; } } 2. Define the Executable class, this is what we will use for other classes in our script that have a common "onStart" / "onLoop" / "onEnd" pattern: abstract class Executable extends CustomMethodProvider { public void onStart() throws InterruptedException {} public abstract void run() throws InterruptedException; public void onEnd() throws InterruptedException {} } Note how this class extends our CustomMethodProvider, which means anything we define in the CustomMethodProvider class will be available to subclasses of "Executable" 3. In the main script class, set everything up (create an instance of CustomMethodProvider, and exchange context) @ScriptManifest(author = "Explv", name = "Example", info="", logo = "", version = 0.1) public class Example extends Script { private final CustomMethodProvider customMethodProvider = new CustomMethodProvider(); @Override public void onStart() { customMethodProvider.init(getBot()); } @Override public int onLoop() throws InterruptedException { return 0; } } 4. Finally, whenever you want some other class with an onStart / onLoop / onEnd, just extend the Executable class, and then run it using "execute". Here is a very contrived example: class ExampleExecutable extends Executable { private static final String TINDERBOX = "Tinderbox"; private final Executable someOtherExecutable = new SomeOtherExecutable(); @Override public void run() throws InterruptedException { if (!getInventory().isUsing(TINDERBOX)) { getInventory().use(TINDERBOX); } else { execute(someOtherExecutable); } } } class SomeOtherExecutable extends Executable { @Override public void run() throws InterruptedException { getWalking().webWalk(new Area(1, 2, 3, 4)); } } @ScriptManifest(author = "Explv", name = "Example", info="", logo = "", version = 0.1) public class Example extends Script { private final CustomMethodProvider customMethodProvider = new CustomMethodProvider(); private final Executable exampleExecutable = new ExampleExecutable(); @Override public void onStart() { customMethodProvider.init(getBot()); } @Override public int onLoop() throws InterruptedException { customMethodProvider.execute(exampleExecutable); return 600; } } 5. If you want an "Executable" that blocks until completion, then you can either use OSBot's Event class, or define your own "BlockingExecutable" which utlises OSBot's Event, for example: public abstract class BlockingExecutable extends Executable { private boolean finished; private ExecutionFailedException executionFailedException; @Override public final void run() throws InterruptedException { finished = false; executionFailedException = null; onStart(); execute(new Event() { @Override public int execute() throws InterruptedException { if (finished) { setFinished(); } else { try { blockingRun(); } catch (ExecutionFailedException executionFailedException) { BlockingExecutable.this.executionFailedException = executionFailedException; setFailed(); } } return 0; } }); onEnd(); if (executionFailedException != null) { throw executionFailedException; } } protected abstract void blockingRun() throws InterruptedException; protected void setFinished() { finished = true; } } public class ExecutionFailedException extends RuntimeException { public ExecutionFailedException(String message) { super(message); } }
  5. This is cool, although I would recommend using your own class instead of the Script class. Using your own class would let you extend the MethodProvider and supply additional functionality to all your subclasses, which can be useful in a big script. Can provide example if helpful
  6. I'd recommend following some Java tutorials, in your first example you didn't even construct an instance of your Fishing class. You also made your Fishing class abstract, which means it cannot be instantiated directly. Only your main script class should extend Script. If you want other classes to be able to access the API, either pass MethodProvider as a constructor arg, or make your other class extend MethodProvider and exchange context. See section 5 of https://osbot.org/forum/topic/115124-explvs-scripting-101/
  7. You're including the OSBot.jar in your script, instead of the compiled output. In the bottom right of your screen shot, where it says "Available Elements", you should be including "FirstBot2 compile output" (it should show up on the left side under the "Woodcutting_Script.jar". The "OSBot 2.6.20" should be on the right hand side (excluded from the compiled script)
  8. If I recall correctly, you do not need to disable randoms. You can override the break manager in isolation: getBot().getRandomExecutor().overrideOSBotRandom(customBreakManager) (Docs - https://osbot.org/api/org/osbot/rs07/event/RandomExecutor.html#overrideOSBotRandom-org.osbot.rs07.script.RandomSolver- ) Where your custom break manager might look something like: https://github.com/Explv/Explvs-AIO/blob/master/src/main/java/tasks/break_task/CustomBreakManager.java There is no way to get passwords through the API, as it would be a security risk. You have to consider local scripts as well as SDN scripts.
  9. Read section 13 of this tutorial to learn about configs Funnily enough, it actually covers attack style as the example. Screenshots are a bit out of date and the OSBot UI has changed, but there is still a config debug view in the settings. TLDR: Config 43.
  10. Fixed in latest version (v3.2.7). Available on GitHub now, or on SDN whenever a refresh happens.
  11. Just pushed an update to the SDN & GitHub SDN will be available whenever it's refreshed GitHub working now Will look at other reported issues and fix now too.
  12. I would say it's more likely to be a scam than not. There's barely any information about it online, aside from their website (which makes some ridiculous claims)
  13. You're either missing the onLoop function which is required, or it has the wrong signature. See section 2 of the following: https://osbot.org/forum/topic/115124-explvs-scripting-101/
  14. Your Test class is importing a log function from a package that is blocked by OSBot's permissions. That's not the log function you want anyway, you want the one from the OSBot API. Remove that import and either pass an instance of MethodProvider to the constructor of your class, or have your class extend MethodProvider and call exchangeContext. See section 5 in this tutorial:
  15. "the problem is that I use: IF IF IF, ELSE ELSE ELSE but need to use if else, else if." At the risk of sounding rude, that's pretty nonsensical. I would highly recommend following some Java tutorials until you have a basic understanding of programming and logical constructs. You'll find that it's much faster to learn that way rather than waiting for replies on here. The best way to learn programming in my opinion, is to follow some tutorials, make things, Google when you get stuck, fix things yourself. Perhaps try writing out some pseudocode, so you can get a clearer idea how this should be structured. For example: If my inventory is full: If I am not in the bank: Then walk to the bank Else if the bank is not open Then open the bank Else if.... Etc. Else if I am not at the stalls: Then walk to the stalls Etc.
  16. getInventory().contains(item1, item2) Returns true if either item1 or item2 is in the inventory. getInventory().interact("Eat", item1, item2) Uses the interaction "Eat" on either item1 or item2 depending on which item it finds in the inventory first. If you want to eat a Swordfish followed by a Pizza, you need to be explicit in your logic, i.e If not eaten swordfish Then eat swordfish Else Eat pizza To track whether you have eaten a swordfish, just store a boolean value in a variable, e.g. hasEatenSwordfish, and set it to true when the "Eat" interaction on the swordfish is successful. Set it back to false when you eat the pizza
  17. The OSBot app is a swing app, so you have to embed your JavaFX content within swing. You can do so using a JFrame + JFXPanel. For example: https://docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm Or: https://stackoverflow.com/questions/40110175/how-to-run-javafx-stage-scene-in-swing-application
  18. Hello old bean Are you trying to just walk to said tile? If so you can do it with a WalkingEvent: WalkingEvent walkingEvent = new WalkingEvent(new Position(3299, 3273, 0)); walkingEvent.setMinDistanceThreshold(0); execute(walkingEvent); Could you please also elaborate on what you mean by "neither of these methods work"? Does it not hover the tile? Does it hover but not click?
  19. Remove this: final Bank bank = new Bank() You don't instantiate `Bank`, it's already instantiated for you and provided via the MethodProvider. If you are in your main Script class, you can access it using getBank() Have a read through my tutorial if you haven't already, it might help you out a bit: https://osbot.org/forum/topic/115124-explvs-scripting-101/
  20. It's a free open source piece of software. You're more than welcome to modify it to work how you want to. It closes the client when the script exits, this is to support script chaining. If you want to change it, there's nothing stopping you.
  21. You can just set a boolean flag when you enter the house. For example: public class YourScript extends Script { private boolean hasEnteredHouse; @Override public int onLoop() throws InterruptedException { if (!inHouse()) { // If we're not in the house, enter it enterHouse(); } else { // We are inside the house, so we can set hasEnteredHosue to true // so that next time we enter the house, we can use the last visit functionality hasEnteredHouse = true; } return 600; } public boolean enterHouse() { if (hasEnteredHouse) { // We have entered the house before, use the last visit functionality } else { // We have not entered the house before, use the search } } } Or alternatively, set a different flag when you see the "You haven't visited anyone this session." message. For example: public class YourScript extends Script { private boolean visitedPlayerHouse = true; @Override public int onLoop() throws InterruptedException { if (!inHouse()) { // If we're not in the house, enter it enterHouse(); } else { // We have entered the house, so we set visitedPlayerHouse to true // so that next time we go to enter a house, we know that we can use the // last visit functionality visitedPlayerHouse = true; } return 600; } public boolean enterHouse() { if (visitedPlayerHouse) { // We have entered the house before, use the last visit functionality } else { // We have not entered the house before, use the search } } @Override public void onMessage(Message message) { if (message.getType() != MessageType.GAME) { return; } // When we see this GAME message if (message.getMessage().contains("You haven't visited anyone this session.")) { // We set visitedPlayerHouse to false // So that we know to use the search functionality to enter the house next time visitedPlayerHouse = false; } } } Note I have not tested any of the above code, but it should give you an idea how to do it.
  22. Note that this is not related to switching OSBot scripts, so is not quite the same thing as what OP wants.
  23. Nice idea. You can kind of already do this yourself using a custom bash script, however it would involve restarting the whole client to load the next script.
  • Create New...