Jump to content

Botre

Members
  • Posts

    5883
  • Joined

  • Last visited

  • Days Won

    18
  • Feedback

    100%

Everything posted by Botre

  1. You check for consequences of that action (experience increase, item mutation, player flags, etc...).
  2. SAPI Hello world. Here's a sneak peak of a little library I'm working on, its goal is to simplify high-level interaction between bot/script and game, useful when you need a superficial game variable but don't have the time or knowledge to fetch it via code or a clunky GUI. Currently, the following types are selectable (with more to come): Entities Widgets Positions Bank slots Inventory slots Prayer buttons Magic spells Currently, the following brushes are available (with more to come): Point Shapes: Arc2D, Ellipse2D, Rectangle2D, RoundRectangle2D The library will be free & available for everyone. No ETA but shouldn't be too long. Code example @ScriptManifest(author = "Botre", info = "", logo = "", name = "Example Script", version = 0) public class Example extends Script { private Sapi sapi; @Override public void onStart() throws InterruptedException { super.onStart(); // Initialize API. sapi = new Sapi(this); // Add a filter to the inventory module: only empty slots are made selectable. sapi.getInventorySlotModule().getFilters().add(slot -> slot.isEmpty()); // Change the painter. sapi.getInventorySlotModule().setPainter(new DefaultItemContainerSlotPainter(this) { @Override public void paint(Graphics2D g2d, ItemContainerSlot object) { g2d.setColor(Color.BLUE); g2d.drawString(object.getItem().getName(), 0, 0); super.paint(g2d, object); } }); // Activate the module / enable selection. sapi.getInventorySlotModule().setActive(true); // Start the API. sapi.start(); } @Override public void onExit() throws InterruptedException { super.onExit(); // Stop API. sapi.stop(); } @Override public int onLoop() throws InterruptedException { // Iterate over selected items. for (ItemContainerSlot slot : sapi.getInventorySlotModule().getSelected()) { log(slot.getItem().getName()); } return 500; } @Override public void onPaint(Graphics2D g2d) { super.onPaint(g2d); sapi.getInventorySlotModule().paintBrush(g2d); sapi.getInventorySlotModule().paintSelected(g2d); } } Screenshots
  3. Use your feet to spread your cheeks apart.
  4. Play around with these: int i = 0; String a = Integer.toString(i); String b = "" + i; String c = String.valueOf(i); String d = new Integer(i).toString();
  5. Botre

    onPaint caveats

    You're asking me if: calculation_cost + constant_scheduling_overhead_cost < calculation_cost * 15 Well, that depends entirely on the cost of the calculations per call and how much the scheduling overhead actually is. Once the total cost of all calculations starts exceeding (constant_scheduling_overhead_cost / 14) it becomes worth using an additional thread from a performance POV.
  6. Botre

    onPaint caveats

    Thread A changes String X twice per second. Thread B reads String X 30 times per second. The reason I'm putting String X in a variable is so it's available to both thread A & thread B, not for caching purposes (since Strings are pretty much automatically cached internally (like you just pointed out :p)).
  7. Read more here: https://github.com/Botre/OSBot-Tutorials/wiki/The-difference-between-dynamic-and-static-skill-levels
  8. Read more here: https://github.com/Botre/OSBot-Tutorials/wiki/How-to-log-the-stack-trace-of-an-exception-thrown-by-onStart()
  9. onStart usually gets called AFTER the first onPaint called. So if you use onStart to initialize variables used inside onPaint you could run into trouble. You could use a static block to make sure the image gets initialize on time or you could null check the image variable in your onPaint. Or maybe it's something entirely different that's causing the issue :p Getting any errors? Try providing a gif if you can.
  10. You might be right since onPaint gets called before onStart. @OP try this public class Script { public static BufferedImage PAINT_BACKGROUND; static { try { PAINT_BACKGROUND = ImageIO.read(new URL("http://i.imgur.com/hxNYgK6.jpg")); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } // onstart ... // onloop ... }
  11. Why? If it was initialized correctly there's no need to check if it's null 30 times per second. @OP empty try-catch blocks are a big no-no.
  12. Try this one. http://johann.loefflmann.net/en/software/jarfix/index.html
  13. Honey Boo Boo

  14. onPaint caveats Description of onPaint: "called when the script should paint it's debug". We are generously going to assume the onPaint(Graph) method gets called 30 times per seconds. @Override public void onPaint(Graphics2D g2d) { super.onPaint(g2d); // Insert custom behavior here. } 1. The method's thread of execution should never be ceased or paused This will lead to inaccurate or lagged rendering, stuttering and an overall unpleasant experience for your end-user. @Deprecated @Override public void onPaint(Graphics2D g2d) { super.onPaint(g2d); /* * BAD CODE! */ try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } try { sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } } If your IDE notifies you about an unhandled InterruptedException in your onPaint method, you're probably doing something wrong. 2. Calculate values at efficient intervals Always keep in mind that this method gets called 30 times per seconds however: - Accurate calculation of elapsed seconds requires only one or two calculations per second. - Other calculations (experience, profit, etc...) require even less than that. 3. ... and cache them where possible Avoid recalculation of values (such as elapsed time) used in other calculations, store and re-use where possible! Demonstration of caveats 2 and 3: @ScriptManifest(author = "Traum", info = "Tutorial", logo = "", name = "Tutorial - Paint", version = 0) public class TutorialPaint extends Script { // The String component that will be rendered. private String paintcomponentTime = "Time:"; // We store the starting system's clock time in milliseconds. private long startMilliseconds = System.currentTimeMillis(); // We store the elapsed amount of milliseconds (so we can reuse it instead of having to recalculate it when necessary. private long elapsedMilliseconds = 0; // We use this single thread executor to automatically recalculate / update the paint-required values (every 500 milliseconds). private ScheduledExecutorService paintValueExecutor = Executors.newSingleThreadScheduledExecutor(); // The runnable that will be executed by the executor. private Runnable paintValueRunnable = () -> { // We calculate the elapsed amount of milliseconds. elapsedMilliseconds = System.currentTimeMillis() - startMilliseconds; // We also build the string value of the component that our onPaint method is going to draw, doing this here will save the cost of rapid repeated concatenation. paintcomponentTime = "Time: " + elapsedMilliseconds; }; @Override public void onStart() throws InterruptedException { super.onStart(); paintValueExecutor.scheduleAtFixedRate(paintValueRunnable, 0, 500, TimeUnit.MILLISECONDS); } @Override public int onLoop() throws InterruptedException { // ... return 200; } @Override public void onPaint(Graphics2D g2d) { super.onPaint(g2d); // No object or value is being calculated or created here! (except for the mandatory pixel arrays and stuff like that of course). g2d.drawString(paintcomponentTime, 50, 50); } @Override public void onExit() throws InterruptedException { super.onExit(); paintValueExecutor.shutdown(); } } 4. Avoid transparency Avoid using transparency in your colors and images, your CPU and those of your end-users will thank me later. Only use transparency cleverly where it improves usability, don't use it just for the looks of it. More to come soon, feel free to suggest your best onPaint() tip(s)!
  15. Steve jobs is turning over in his grave. What a joke.
  16. The fact that you are even remotely caring about the status of your RS account when you're potentially facing prison makes me think there's something wrong in your head.
×
×
  • Create New...