Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.76 KB | None | 0 0
  1.  
  2.  
  3. package scripts;import java.awt.Graphics;import org.tribot.api.General;import org.tribot.api.Timing;import org.tribot.api.input.Mouse;import org.tribot.api.rs3.Login;import org.tribot.api2007.GameTab;import org.tribot.api2007.Interfaces;import org.tribot.api2007.Inventory;import org.tribot.api2007.Skills;import org.tribot.api2007.types.RSItem;import org.tribot.script.Script;import org.tribot.script.ScriptManifest;import org.tribot.script.interfaces.Painting;@ScriptManifest(authors = { "Cloudnine" }, category = "Magic", name = "FishbowlHumidifier")// Script manifest - how the script will show up when you go to start it uppublic class FishbowlHumidifier extends Script implements Painting { /* * extends Script means that its an extension of the class "Script" and * implements Painting implements the interface "Painting" so that the * client knows what to paint onto the screen */ private long startTime = 0;// = 0 just to make the paint look pretty on // start private boolean running = true;// script will stop when this is false private int startXp;// start xp will get set after confirming that ur ingame private String status = "Getting started";// status of the script private final boolean DEBUG_MODE = false;// if true status will be painted /* * Instead of getting the below 2 variables inside of the paint, they're * defined inside of getHourly() which is ran inside of the loop. This * lowers the CPU because the variables aren't constantly being ran inside * of the paint. They're given some sleep time. You should also do this when * you're getting other variables such as an amount of items, amount of * health, etc.. */ private int xpGain = 0; private int hourly = 0; /* * For beginner java programmers: "private final int". "private" means that * it can only be accessed within this class. "final" means that the number * will never ever change. "int" means that the variable is a number. When * naming a "final" variable, the naming conventions are * CAPS_AND_UNDERSCORES_BETWEEN_WORDS rather than * firstWordLowerCaseAndOtherWordsCapitalized You should also remember that * "static" means that the variable can be accessed by other classes, you'll * be using this when you do things such as passing over variables from a * GUI. A GUI is a graphical user interface, basically a window. You can use * a GUI for selecting options when the script is started. They also server * many other purposes. */ private final int EMPTY_FISHBOWL_ID = 6667; // empty fishbowl id private final int FULL_FISHBOWL_ID = 6668; // full fishbowl id private long lastCastTime = System.currentTimeMillis();// stores the last // time the humidify // spell was casted /* * The onPaint() void uses the Graphics class, which is represented by the * letter g(Graphics g) to paint data, text, shapes, pictures, and whatever * you want onto the screen. This runs very quickly, and I don't believe it * has any sleep time. So try to avoid defining variables from the client * inside of the paint. Instead, define them at the top of the class, and * then update them inside of the loop. */ public void onPaint(Graphics g) {// Paints pics/text on screen g.drawString("Fishbowl Humidifier v1.0 by Cloudnine", 300, 285);// msg, // x, y long runTime = 0;// to make the script look pretty while waiting... if (startTime != 0) {// for the player to be logged in runTime = System.currentTimeMillis() - startTime; } // Below, Timing.msToString() converts the time to a string such as... // 00:00:00 (hours:mins:sec) g.drawString("Time Ran: " + Timing.msToString(runTime), 300, 300); g.drawString("Magic XP Gained: " + xpGain + "(" + hourly + "/hr)", 300, 315); // hourly and xp gain are set with getHourly() which is ran inside of... // the loop to keep CPU down if (DEBUG_MODE) {// if debug mode is enabled... g.drawString("Status: " + status, 300, 330);// paint the status } } public void run() {// initialized once, when the script starts while (Login.getState() != Login.STATE.IN_GAME) { // Waiting for player to be logged in // in case the script is started at login status = "Waiting for login"; sleep(100); } startTime = System.currentTimeMillis();// Now that it's logged in - it startXp = Skills.getXP(Skills.SKILLS.MAGIC);// sets these vars while (running) { // this repeats over and over while running sleep(loop());// sleeps for the # of ms returned by the int loop() } // running = false, so the script is about to stop // lets bid our user farewell & give them some info about how // the script did println("Thanks for using Cloudnine's Fishbowl Humidifier v1.0"); long runTime = System.currentTimeMillis() - startTime; println("Time Ran: " + Timing.msToString(runTime)); println("Magic XP Gained: " + xpGain + "(" + hourly + "/hr)"); // now lets beg for proggies so that more ppl buy the script println("Please post proggies! (Simply snapshot the last 4 lines of debug & post the snapshot to the main thread)"); } public int loop() {// whatever this # returns is how long, in ms, that the // script will sleep for b4 initializing loop() again if (Login.getState() != Login.STATE.IN_GAME) { status = "Not logged in"; // Give the login bot time to do its thing return 100;// wait for 100ms then start loop() again } Mouse.setSpeed(General.random(50000, 100000));// Mouse speed (min, max) // a normal speed would // be around 100 - 150 if (Inventory.find(FULL_FISHBOWL_ID, EMPTY_FISHBOWL_ID).length > 0 && Inventory.find("Astral rune", "Fire rune").length == 0) { /* * This assumes that you will always have a fishbowl to make sure * that the inventory items are actually being detected. On very * rare occasion the inventory items aren't detected even though the * inventory is there, you ARE logged in, and you are NOT in a * random. Idk why that happens, but to be on the safeside I did * this. The downside is that the script wouldn't detect loosing * your fishbowl, however you shouldn't ever loose your fishbowl. If * you did loose your fishbowl, the script would eventually stop * after for 10 of being idle. Which will keep you from getting * reported, and will stop you from wasting CPU that other bots * could be using. This is where you learn that when using a * provided API, you may be limited as to what you can do, and have * to make sacrifices & determine what choice to make. */ running = false;// stops the script println("Out of supplies. Script stopped."); return 0; } if (lastCastTime > 10 * 60 * 1000) { /* * if the last time the spell was casted is greater than 10 minutes, * then abort the script, it has stopped working */ println("Idle for more than 10 minutes. Stopping script."); running = false; return 0; } getHourly();// sets variables for xp, xp gain & hourly xp /* * An array holds multiple variables. In this case the array is not an * int, boolean, or String, instead it is a RSItem. To define an array, * simply do int[] nameOfTheArrayHere. You can also do int * nameOfTheArrayHere[], but it's conventional to do the brackets with * the variable. The only reason the brackets can be put on either side * is to help C programmers get used to Java. Below, the array(group) of * RSItems called fullBowl holds all of the items inside of your * inventory that have the same id as FULL_FISHBOWL_ID. You can also go * by name, but in some cases, such as with the fishbowl, there are * multiple names for that one item. Regardless of if the fishbowl is * empty or if the fishbowl is full, the fishbowl will always have the * name "fishbowl" but the id will always be different. Don't worry * about item ids changing, in order to do that Jagex would have to loop * through MILLIONS of accounts in their database and change the item id * everywhere, and they would have to change it in their code as well. * That will never happen. */ RSItem[] fullBowl = Inventory.find(FULL_FISHBOWL_ID); if (fullBowl.length > 0 && fullBowl[0] != null) { /* * The above if statement ensures that there is more than 0 * occurences(occurences meaning "things" inside of the array) of * FULL_FISHBOWL_ID inside of your inventory. If so, it makes sure * that the first occurence is not null. In an array, the first * occurence is represented by a 0, the second occurence is * represented by a 1, the third is represented by a 2, and so on... */ if (GameTab.getOpen() != GameTab.TABS.INVENTORY) { /* * The above if statement basically says "if the currentTab is * not INVENTORY then do the following { }" The current tab is * stored in an enum. An enum simply holds a bunch of different * possibilities. These possibilities are called states. A STATE * is exactly what it's called. It's just the STATE, phase, or * stage that something is in. Think of state of matter, MATTER * could be the name of the enum(an enum holds all of the * different states), and the different possibilities(aka * states) would be GAS, LIQUID, and, SOLID. States and enums * are both capitalized and words are separated by underlines, * JUST_LIKE_IN_A_FINAL_VARIABLE. */ status = "Opening inventory"; GameTab.open(GameTab.TABS.INVENTORY);// Clicks the inventory tab // now you've clicked the inventory tab, time to wait for it to // open with this next while loop... int count = 0; while (count < 5 && GameTab.getOpen() != GameTab.TABS.INVENTORY) { count++;// after 5 times, it will stop sleeping - to prevent // the script from hanging & to prevent wasted time sleep(100);// if it sleeps for 100ms UP TO 5 times, then it // can sleep for UP TO 500ms. (remember 1000ms = // 1 second) } return 0;// now that you've already slept until EITHER the game // tab is opened, OR it's been 500ms and it's still // not opened you will now return 0 because it's // either time to do something else or the inventory // failed to open, you've waited 500ms, and it's now // time to try again. } // so the inventory IS open, and you need to empty the fishbowl { status = "Emptying fishbowl"; if (!fullBowl[0].click("Empty")) {// fullBowl[0] pulls up the array // fullBowl and gets the very // first value (the very first // value of an array is // represented by a 0, like I // said earlier) return 100;// if the click() boolean returns false, then it // failed to click the bucket, and instead of // continuing, we'll go back, sleep for 100ms, and // then try the loop() again } // okay it's now sucessfully clicked empty fishbowl now that we're // waiting for the fishbowl to be emptied, lets go ahead and save // time by immediately opening up the spell book if (GameTab.getOpen() != GameTab.TABS.MAGIC) {// if the spell book // isnt open status = "Opening spellbook"; GameTab.open(GameTab.TABS.MAGIC);// open the spell book /* * wait for the spell book to open/load for up to 500ms */ int count = 0; while (count < 5 && GameTab.getOpen() != GameTab.TABS.MAGIC) { count++; sleep(100); } } /* * now lets wait for up to 1500 ms (1.5 seconds) for the full * fishbowl to become emptied */ int count = 0; while (count < 15 && Inventory.getCount(FULL_FISHBOWL_ID) > 0) { count++; sleep(100); } return 0;// done waiting OR it's been over 1.5ms and the fishbowl // still isn't empty } // okay so at this point we're no longer working with the full fish bowl // the below is just the same as when we were working with the full fish // bowl, except we're now working with the empty one RSItem[] emptyBowl = Inventory.find(EMPTY_FISHBOWL_ID); if (emptyBowl.length > 0 && emptyBowl[0] != null) { if (GameTab.getOpen() != GameTab.TABS.MAGIC) { status = "Opening spellbook"; GameTab.open(GameTab.TABS.MAGIC); int count = 0; while (count < 5 && GameTab.getOpen() != GameTab.TABS.MAGIC) { count++; sleep(100); } return 0; } // now the spell book is open & we have an empty bucket so it's time // to click on humidify status = "Clicking humidify"; if (Interfaces.get(430) != null && Interfaces.get(430).getChild(7) != null) { /* * If parent interface 430 exists and its child interface 7 * exists then click the option "Cast" on the child interface 7 * which is located inside of the parent interface 430. (Parent * id 430 is the spellbook, child id 7 is the spell "Humidify" */ if (Interfaces.get(430).getChild(7).click("Cast")) { /* * If we sucessfully clicked "Cast" on the spell Humidify, * lets go to the inventory and hover over the empty * fishbowl while we're waiting for it to fill up (saves * time & is humanlike) */ lastCastTime = System.currentTimeMillis(); if (GameTab.getOpen() != GameTab.TABS.INVENTORY) { status = "Opening inventory"; GameTab.open(GameTab.TABS.INVENTORY); int count = 0; while (count < 5 && GameTab.getOpen() != GameTab.TABS.INVENTORY) { count++; sleep(100); } } // okay we have now opened the inventory, lets make sure // it's open if (GameTab.getOpen() == GameTab.TABS.INVENTORY) { // okay good, it's open now lets hover over the empty // fishbowl while we wait for it to fill up emptyBowl = Inventory.find(EMPTY_FISHBOWL_ID); if (emptyBowl.length > 0 && emptyBowl[0] != null) { emptyBowl[0].hover();// hovers over the empty // fishbowl /* * now lets wait up to 3 seconds for the fishbowl to * fill up */ int count = 0; while (count < 30 && Inventory.getCount(EMPTY_FISHBOWL_ID) > 0) { count++; sleep(100); } return 0;// done waiting OR the 3 second timeout is // up, lets go back, don't sleep at all // b/c we already have slept somewhere // from 100ms to 3000ms, and then lets // do loop() again } } } else {// somehow failed to click Humidify (maybe a misclick or // something) return 100;// sleep for 100ms and try the loop() again } } } status = "Doing nothing";// you've now reached the end of the loop() // int, lets set the status to // "Doing nothing", sleep for 100ms, and run // the loop again return 100; } public void getHourly() { int xp = Skills.getXP(Skills.SKILLS.MAGIC);// Gets the current magic xp. xpGain = xp - startXp;// gets the GAINED magic xp since the script has // started long time = System.currentTimeMillis() - startTime;// gets the time // since the script // started (in // milliseconds) /* * The below formula gets the amount of XP made per hour, it's useful * for many other things as well */ hourly = (int) (((double) xpGain * 3600000D) / (double) time); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement