Jump to content

NoxMerc

Members
  • Posts

    73
  • Joined

  • Last visited

  • Feedback

    0%

Everything posted by NoxMerc

  1. I cleaned up your code a little bit. You have some really glaring problems, the first of which is the fact that all of your if(){} statements are empty. Frankly speaking this is unacceptable. I've incorporated a pared-down version of @Explv's Sleep utility which makes your code much more readable. I think if you use this version you'll have an easier time figuring out your bugs. One other thing I did fix was the fact that you're reusing Entities. Changing the state of an entity in-game will require you to reacquire that entity again to retrieve its updated properties. In other words, if you get an Object, and then destroy that object in-game (by removing a larder), that first object's properties won't be updated. You have to reacquire it. import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.Condition; import org.osbot.rs07.utility.ConditionalSleep; import java.util.function.BooleanSupplier; @ScriptManifest(name = "LardersV2", logo = "", version = 1, author = "Imthabawse", info = "Builds Oak Larders") public class Oaklarders extends Script { private final int ID_OAK_PLANK = 8778; private final int WIDGET_LARDER_ROOT = 458; private final int WIDGET_LARDER_CHILD = 5; private final int WIDGET_LARDER_SUBCHILD = 4; private final int MIN_OAK_PLANKS = 8; @Override public int onLoop() { if (getInventory().getAmount(ID_OAK_PLANK) <= MIN_OAK_PLANKS) { // If inventory contains 8 or equal to 8 oak planks Entity larderspace = getObjects().closest("Larder space"); // Get closest Larder space if (larderspace != null && larderspace.interact("Build")) { // If Larder space exists then Build Sleep.until(() -> !getObjects().closest(f -> f.getPosition().equals(larderspace.getPosition())).exists(), 400, 500); } RS2Widget buildlarder = getWidgets().get(WIDGET_LARDER_ROOT, WIDGET_LARDER_CHILD, WIDGET_LARDER_SUBCHILD); // Oak larder widget if (buildlarder != null && buildlarder.interact("Build")) { // If exists then build larder Sleep.until(() -> myPlayer().isAnimating(), 4000, 500); } Entity larder = getObjects().closest("Larder"); // Get closest larder if (larder != null && larder.interact("Remove")) { // If exists remove it Sleep.until(() -> !getObjects().closest(f -> f.getPosition().equals(larder.getPosition())).exists(), 400, 500); } RS2Widget remove = getWidgets().getWidgetContainingText("Yes"); if (remove != null && remove.interact()) { Sleep.until(() -> myPlayer().isAnimating(), 4000, 500); } } return 1000; } protected static class Sleep extends ConditionalSleep { private final BooleanSupplier condition; public Sleep(BooleanSupplier condition, int timeout, int interval) { super(timeout, interval); this.condition = condition; } @Override public boolean condition() { return condition.getAsBoolean(); } public static boolean until(final BooleanSupplier condition, int timeout, int interval) { return new Sleep(condition, timeout, interval).sleep(); } } }
  2. RS only loads an area around you of a radius about 50 tiles or so. You can't just load all of the NPCs across the entire game and hope it finds the closest fishing spot to you.
  3. Still deleting messages. I managed to get myself banned again because I was trying to link Explv's open-source Tutorial Island script, trying to help someone. You know. The thing we want to ban people for. https://i.imgur.com/HrRsEyR.png
  4. You're setting yourself up for failure here. You have all of your code in one class, and you're trying to execute your entire script in one loop. Realistically, each 'loop' of the script should be responsible for executing one portion of the script. In your case, you have it potentially executing your entire script. Since your script is relatively simple, you should look at the State-based framework. It's a simple framework that allows you to determine the state the script is in (fish, cook, bank, etc), and execute. The bigger reason why I'm mentioning this and not addressing your direct problem is that you're going to have this problem time and time again until you address your poor architecture. If you don't mind, try implementing something along the lines here Once you've done so, you will probably be able to locate these issues yourself! It's not about avoiding helping you, it's about making you self-sufficient to be a better developer in the future.
  5. AiO main maker. Start the script from tutorial island, let it run for a week straight, come back to 1m in the bank with all 50's and 30QP.
  6. I personally hate video tutorials and actively avoid watching them. Scrolling through an organized wall of text lets me find what I need when I need it, rather than skipping through a video. Do you have transcripts or something you can attach to them, when you get around to it? Good effort though, be glad to at least skip over the finished product.
  7. Unfortunately, you're in the same boat I am. The 4670k/4770k-era CPUs are fucking amazing, to the point where the current gen 9700k isn't all that much worth it. That's your call, but me personally, I'm not upgrading off of my 4670k for awhile. Maybe Zen2 will change that for me. https://cpu.userbenchmark.com/Compare/Intel-Core-i7-4770K-vs-Intel-Core-i7-9700K/1537vs4030 You have to look at your use-case from your computer. If you want to do heavy gaming, here's what I'd do if I were you * Ensure your CPU is OC'd as high as you can get it * Switch off of the 780 SLI into a single 1080 TI or Vega 56 (budget depending) * Get a higher-capacity SSD (think 850 Evo 1TB) (this is optional, but I currently have 3x 128Gb SSDs (thanks, dad) and I'd much rather have a single one) You kind of don't want to touch your ram, because there's no point in buying high-quality RAM for your current mobo (assuming the next mobo you buy won't support ram you upgrade) that will only last a short time until your next processor upgrade. Unfortunately, I can't tell you when is the right time to upgrade your processor.
  8. I was receiving the error earlier as well on my own private script, except it was NPCS.filter, not GroundItems. It seems to have been fixed with a fresh client download? I'm also receiving frequent WebWalking errors on this build, stating "Cycle Threshold reached!" on various locations (mostly common banks).
  9. Do you create new Threads inside of onLoop? If so you'll need probably want to interrupt them by overring the script's onStop method. Alternatively, what you can do is use the script's async event system. I haven't used it personally, but if it's handholdy enough it'll track your Thread references for you and terminate them when the script ends.
  10. Once I actually have something worth showing, I will. I'm a few months away from anything too juicy, but my end-game is to have a twitch channel where people can issue commands for the bot to follow, e.g. !woodcut willow, !combat "Al-kharid warrior", etc, as well as letting it do its own things autonomously. @Explv have you ever worked with GSON on the SDN at all? Or are we pretty much stuck with json-simple?
  11. What type of accounts, what scripts?
  12. I suppose I don't much see the purpose of even having a cache if it's randomly going to render itself unusable at some point. Especially when some point is directly after initializing the cache. Anyway I did some experimenting. To reduce memory footprint I changed RSBuddyExchangePrice from containing an internal Map<String, Object> to having distinct fields. This caused no difference in performance, however it should reduce the amount of memory each RSBEP uses by at least (110 * 2 + 32*10),, or just about 2Mb for all 4,000 (where 110 is the length of the json string and there are 10 string references). The second thing I did is that remove the Pattern.compile() call from the parse(String jsonstr) method to its calling method. I think it only needs to be called once, but the implementation was compiling it for each new item. This cut the time in half it takes to parse all 4000 or so odd items (which, mind you, is going from on average 16ms to 8ms...so..not a huge deal). Lastly, I changed the return values from longs to ints. This might be questionable, but I don't see any of the fields possibly breaking the int maxvalue. This tool saved me from having to map IDs manually (I prefer to do everything by name), so thanks so much for posting it when you did. I'm not trying to be a jerk or anything with these suggestions, just in the pursuit of making awesome things more awesome when I can. RSBuddyExchangeOracle.java RSBuddyExchangePrice.java
  13. Best of luck with your scripts. If you need help, hop on the discord. I'm there almost 24/7, and nobody asks about scriptwriting anymore :c
  14. Correct. https://i.imgur.com/atkvEgw.png
  15. Is it because I have less RAM (16Gb, but I'm always using most of it) available and the JVM collects the WeakReferences from the WeakHashMap sooner because it's trying to free up memory, whereas with your machine the JVM isn't collecting? *Edit Further testing confirms this. Tested on my laptop with 32Gb RAM. public class RSBuddyExchangeOracleTester { private static final String[] NAMES_TO_TEST = new String[] { "Clay", "Adamant pickaxe", "Rune axe", "Mithril platebody" }; private static final int[] IDS_TO_TEST = new int[] { 434, 532 }; // clay, big bones public static void main(String[] args) throws IOException { System.out.println("Testing RSBuddy Exchange Oracle"); long start = System.currentTimeMillis(); RSBuddyExchangeOracle.retrievePriceGuide(); System.out.println("Took " + (System.currentTimeMillis() - start) + "ms to load prices"); System.gc(); // <-------------- IMPORTANT for(int i : IDS_TO_TEST) { System.out.println("Testing " + i); RSBuddyExchangePrice price = RSBuddyExchangeOracle.getItemByID(i); System.out.println(price); } for(String s: NAMES_TO_TEST) { System.out.println("Testing " + s); RSBuddyExchangePrice price = RSBuddyExchangeOracle.getItemByName(s); System.out.println(price); } System.out.println("Total time taken: " + (System.currentTimeMillis() - start) + "ms"); } } Without System.gc(), things run as normal. Running System.gc() will cause the WeakHashMap to collect its Integer values. I'm not immediately sure why the String values aren't collected.
  16. Still an issue. The filter will delete the phrase
  17. I personally try and make functions as independent as possible so that I can create mini utilities in my script to test out individual methods, like this Short of that, the logger is your friend, and you should use it frequently to pick apart the brain of your script. I use the actual debugger as a last resort. You can connect it by starting the client with -debug 5005 arguments, and attaching your IDE to the remote process. I use it as a last resort because it tends to error out on me after a few reloads of the script, and I have to restart the client again. I export JARs straight to my OSBot scripts directory. My IDE complains about overwriting files, but it works anyways.
  18. https://osbot.org/api/org/osbot/rs07/api/Bank.html#withdraw-java.lang.String-int- This is how you withdraw a certain amount of an item. https://osbot.org/api/org/osbot/rs07/api/Inventory.html#isEmptyExcept-int...- public long lastAnnounceTime = 0L; public void announceIfNecessary() { if ((System.currentTimeMillis() - lastAnnounceTime) > 3_000) { typeStringInstance(""); lastAnnounceTime = System.currentTimeMillis(); } }
  19. You could do something like int verificationAttempts = 5; long goldAmt = 0; for (int i = 0; i < verificationAttempts; i++) { goldAmt = getInventory().getAmount("Coins"); if (goldAmt > 0) break; } if (goldAmt == 0) { // We tried 5 times to find gold } Granted this isn't perfect, but if your assumption is true that it's somehow returning 0 at times... I'm still convinced there's a flaw in the script's logic somewhere, and this is pretty hackish.
  20. Can you replicate the issue? Run a test script that looks like @Override public int onLoop() throws InterruptedException { log(getInventory().getAmount("Coins")); return 500; } While this is running, go through the same process manually that your bot does, and see if you notice it occasionally logging 0.
  21. For breaking early based on distance, you'll want to use a WalkingEvent (or WebWalkingEvent) and set a break condition for the event. It could be something as simple as Supplier<NPC> npcFinder = () -> getNpcs().closest(f -> f.getName().equals("NpcToFind") && f.getPosition() != null && f.getPosition().distance(myPosition()) <= 7 && getMap().canReach(f)); Condition breakCondition = new Condition() { @Override public boolean evaluate() { return npcFinder.get() != null; } }; new WalkingEvent(myPos).setBreakCondition(breakCondition).execute(); NPC targetNpc = npcFinder.get(); if (targetNpc != null) if (targetNpc.interact()) //Do stuff This will break out of your walking event as soon as the NPC is able to be reached, and interact with it. You'll use a similar concept for hovering the next monster to attack. In the execution of your combat-block, determine if the NPC you're fighting is about to die, and if so, find the next target and hover over it. You'll need to constantly validate that it's a valid target and isn't in combat with another player.
×
×
  • Create New...