dartz Posted January 15, 2019 Share Posted January 15, 2019 (edited) Hello, I'm dartz and this is my first OsBot script. I've written a tab making bot on another client and recently came to osBot to write bots, improve my java skill, and not have to pay $8 a month. I know python fairly well, but I'm a noob at java. The script is very simple, but gets the job done. Fixed: When checking the bank for grapes/jugs of water, it will not detect the items if they are at the corner of the screen. Pros Works Has a Paint Cons Few comments simple if statements, no functions only works at the G.E. No GUI package osBots; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.util.concurrent.TimeUnit; import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(name = "CookMate", version = 1.0, info = "", author = "Dartz", logo = "") public class CookMate extends Script{ // reaction times changed prior to posting.. public int min = 1000; public int low = 2000; public int med = 3000; public int high = 5000; // item ids public int grapes = 1987; public int water = 1937; // Paint // public int batches; public int estWine; public int fontSize; public long timeBegan; public long timeRan; // Crucial to paint time working // public void onStart() { timeBegan = System.currentTimeMillis(); } @Override public int onLoop() throws InterruptedException { if (!myPlayer().isAnimating()) { log("Standing still"); if (!inventory.contains(grapes) & !inventory.contains(water)) { log("Inventory lacking grapes"); objects.closest("Grand Exchange booth").interact(); log("Clicked bank"); sleep(1000); // smart depositing + paint implementation if (!inventory.isEmpty()) { if (inventory.contains(1995) | inventory.contains(1993)) { batches = batches + 1; estWine = estWine + 14; log("batches: " + batches); } log("depositing all"); bank.depositAll(); } if (!bank.contains(grapes) | !bank.contains(water)) { stop(); } sleep(random(min,low)); bank.withdraw(grapes, 14); sleep(random(min,low)); bank.withdraw(water, 14); sleep(random(min,low)); bank.close(); log("Bank Closed"); sleep(1000); } if (inventory.contains(grapes) & inventory.contains(water)) { inventory.getItem("Grapes").interact("Use"); sleep(1000); inventory.getItem("Jug of water").interact("Use"); sleep(1000); RS2Widget makeInterface = getWidgets().get(270,14,38); if (makeInterface != null) { if (makeInterface.isVisible()); log("Make interface is visible!"); makeInterface.interact(); /* * Wine making = 2 ticks * 14 Wines = 16.8 secs */ sleep(random(13000,18000)); } } } log("Gone through onLoop()"); sleep(1000); return 500; } // BELOW: ONLY EFFECTS PAINT // public void onPaint(Graphics2D g) { Graphics2D gr = g; timeRan = System.currentTimeMillis() - this.timeBegan; fontSize = 16; Font crossHair = new Font("SANS_SERIF", Font.BOLD, fontSize); g.setColor(Color.BLACK); g.setFont(crossHair); // 17 pixels in between each other g.drawString("Estimated xp: " + (estWine*200), 555, 424); g.drawString("Run time: " + ft(timeRan), 555, 441); g.drawString("Batches made: " + batches + " (wines: "+estWine+")", 555, 458); } private String ft(long duration) { String res = ""; long days = TimeUnit.MILLISECONDS.toDays(duration); long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration)); long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(duration)); long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)); if (days == 0) { res = (hours + ":" + minutes + ":" + seconds); } else { res = (days + ":" + hours + ":" + minutes + ":" + seconds); } return res; } } I used several tutorials on here and greatly appreciate this community. I want to become a better programmer and community member. If you have any resources that proved helpful, I'd greatly appreciate those as well. I also started working on a shrimp fisher to get familiar with walking to and from the bank. Edited January 15, 2019 by dartz Quote Link to comment Share on other sites More sharing options...
TheWind Posted January 15, 2019 Share Posted January 15, 2019 Looks like you are using the wrong operators in your if statements https://www.quora.com/What-is-difference-between-and-in-Java 1 Quote Link to comment Share on other sites More sharing options...
dreameo Posted January 15, 2019 Share Posted January 15, 2019 35 minutes ago, TheWind said: Looks like you are using the wrong operators in your if statements https://www.quora.com/What-is-difference-between-and-in-Java RIP. The example is wrong. The "bitwise and" is not appropriate in the way that it's used but it still works here. Quote Link to comment Share on other sites More sharing options...
IDontEB Posted January 15, 2019 Share Posted January 15, 2019 12 minutes ago, dreameo said: RIP. The example is wrong. The "bitwise and" is not appropriate in the way that it's used but it still works here. The examples not wrong. boolean expressions are expressed as 0s or 1s and in the example they had int x =55; if (x<50 & x>0) so it'd be if (0 & 1) which (0 & 1) evaluate to 0 which is false. you're right about it not being appropriate though. Quote Link to comment Share on other sites More sharing options...
dreameo Posted January 15, 2019 Share Posted January 15, 2019 2 minutes ago, IDontEB said: The examples not wrong. boolean expressions are expressed as 0s or 1s and in the example they had int x =55; if (x<50 & x>0) so it'd be if (0 & 1) which (0 & 1) evaluate to 0 which is false. you're right about it not being appropriate though. zz read it as the author saying the first expression is false and second is true. Quote Link to comment Share on other sites More sharing options...
dartz Posted January 15, 2019 Author Share Posted January 15, 2019 47 minutes ago, IDontEB said: The examples not wrong. boolean expressions are expressed as 0s or 1s and in the example they had int x =55; if (x<50 & x>0) so it'd be if (0 & 1) which (0 & 1) evaluate to 0 which is false. you're right about it not being appropriate though. Thanks for the clarification. Quote Link to comment Share on other sites More sharing options...
dartz Posted January 15, 2019 Author Share Posted January 15, 2019 1 hour ago, TheWind said: Looks like you are using the wrong operators in your if statements https://www.quora.com/What-is-difference-between-and-in-Java Thanks, this fixed the bank bug I was having! Quote Link to comment Share on other sites More sharing options...