Guest User

First script

a guest
Feb 22nd, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.60 KB | None | 0 0
  1. package choptree;
  2.  
  3.  
  4. import org.osbot.rs07.api.map.Area;
  5. import org.osbot.rs07.api.model.Entity;
  6. import org.osbot.rs07.script.Script;
  7. import org.osbot.rs07.script.ScriptManifest;
  8.  
  9. import java.util.concurrent.TimeUnit;
  10.  
  11. import javax.imageio.ImageIO;
  12.  
  13. import java.awt.Graphics2D;
  14. import java.awt.Image;
  15. import java.awt.Point;
  16. import java.awt.Rectangle;
  17. import java.awt.event.MouseEvent;
  18. import java.io.IOException;
  19. import java.net.URL;
  20.  
  21.  
  22.  
  23.  
  24. @ScriptManifest(author = "Slasher", info = "My first script", name = "Tree chopper", version = 0, logo = "")
  25. public class main extends Script {
  26.  
  27. Area GEtrees = new Area(3145, 3492, 3141, 3500);
  28. Area WVoak = new Area(3159, 3420, 3169, 3412);
  29. Area GEbank = new Area(3162, 3489, 3162, 3490);
  30. Area WVbank = new Area(3183, 3441, 3182, 3440);
  31.  
  32. private long timeBegan;
  33. private long timeRan;
  34.  
  35. private boolean hide = false;
  36. private boolean dropit = false; //This boolean determines if the script will drop the logs or naw.
  37. private boolean GEtreecutter = false;
  38. private boolean WVoakcutter = false;
  39. private boolean Banktime = false;
  40. private boolean optionb = false;
  41. private boolean walkback = false;
  42. private boolean determine = true;
  43.  
  44. private final Image bg = getImage("http://i.imgur.com/xLlbzks.png");
  45.  
  46.  
  47. @Override
  48. public void onStart() { //runs once
  49.  
  50.  
  51. timeBegan = System.currentTimeMillis();
  52.  
  53. this.bot.addMouseListener(new java.awt.event.MouseListener() {
  54.  
  55.  
  56.  
  57.  
  58. @Override
  59. public void mouseReleased(MouseEvent e) {
  60. // TODO Auto-generated method stub
  61.  
  62.  
  63. }
  64.  
  65.  
  66. @Override
  67. public void mousePressed(MouseEvent e) {
  68. Point clicked = e.getPoint();;
  69. Rectangle paintButton = new Rectangle(405, 459, 108, 15);
  70. Rectangle optionbutton = new Rectangle(488, 346, 19, 18);
  71. Rectangle gelogs = new Rectangle(80, 370, 40, 13);
  72. Rectangle wvoaks = new Rectangle(160, 370, 55, 13);
  73. Rectangle BankDrop = new Rectangle(320, 390, 55, 13);
  74. if (paintButton.contains(clicked)){
  75. if(hide == false){
  76. hide = true;
  77. } else {
  78. hide = false;
  79. }
  80. }
  81. if(hide == false){
  82. if (optionbutton.contains(clicked)){
  83. if(optionb == false){
  84. optionb = true;
  85. } else {
  86. optionb = false;
  87. }
  88. }
  89. if(optionb == true && gelogs.contains(clicked)){
  90. GEtreecutter = true;
  91. WVoakcutter = false;
  92. determine = true;
  93. log("Gelogs have been clicked");
  94.  
  95. }
  96. }
  97. if(optionb == true && wvoaks.contains(clicked)){
  98. WVoakcutter = true;
  99. GEtreecutter = false;
  100. determine = true;
  101. log("WVoakcutter has been clicked");
  102. }
  103.  
  104. if(optionb == true && BankDrop.contains(clicked)){
  105. if(dropit == false){
  106. dropit = true;
  107. } else {
  108. dropit = false;
  109. }
  110. }
  111.  
  112.  
  113. }
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. @Override
  122. public void mouseExited(MouseEvent e) {
  123. // TODO Auto-generated method stub
  124.  
  125.  
  126. }
  127.  
  128.  
  129. @Override
  130. public void mouseEntered(MouseEvent e) {
  131. // TODO Auto-generated method stub
  132. }
  133.  
  134.  
  135. @Override
  136. public void mouseClicked(MouseEvent e) {
  137. // TODO Auto-generated method stub
  138.  
  139.  
  140. /*
  141. *
  142. * GUI ON/OFF
  143. *
  144. */
  145.  
  146.  
  147.  
  148.  
  149. }
  150.  
  151.  
  152. });
  153. if(GEtreecutter == true){
  154. if(!GEtrees.contains(myPlayer())){
  155. getWalking().webWalk(GEtrees);
  156. }
  157. }
  158. if(WVoakcutter == true){
  159. getWalking().webWalk(WVoak);
  160. }
  161.  
  162.  
  163. }
  164.  
  165. private enum State { //What state is the bot in
  166. CHOPPING_GETREES, CHOPPING_WVOAKS, DROPPING, WAIT, BANKING, WALKING_FRA_BANK, DETERMINELOCATION
  167. };
  168.  
  169. private State getState() { //Determine what state the bot should be in
  170.  
  171. Entity tree = objects.closest( "Tree" ); //The closest tree
  172. Entity oak = objects.closest("Oak");
  173.  
  174. if(inventory.isFull() && dropit == true) //If the inv is full and dropit is on, it will go to state DROPPING
  175. return State.DROPPING;
  176.  
  177. if(inventory.isFull() && dropit == false || Banktime == true)//If the inv is full and dropit is off and its in the bank area, bank
  178. return State.BANKING;
  179.  
  180. if(inventory.isEmptyExcept("Silver axe", "Bronze axe", "Black axe", "Iron axe", "Rune axe", "Steel", "Mithril axe", "Dragon axe") && walkback == true) //todo isEmptyExcept(axes) .... Tells script to walk back from bank
  181. return State.WALKING_FRA_BANK;
  182.  
  183. if(tree != null && GEtreecutter == true && determine == false) //if there are trees around and none of the other states are active, cut them trees.
  184. return State.CHOPPING_GETREES;
  185.  
  186. if(oak != null && WVoakcutter == true && determine == false)
  187. return State.CHOPPING_WVOAKS;
  188.  
  189. if(determine == true)
  190. return State.DETERMINELOCATION;
  191.  
  192.  
  193. return State.WAIT; //default
  194. }
  195.  
  196. @Override
  197. public int onLoop() throws InterruptedException { //Below is where the script actually does stuff
  198. switch (getState()) {
  199. case CHOPPING_GETREES:
  200. log("State.CHOPPING_GETREES");
  201. Entity tree = objects.closest(GEtrees, "Tree");
  202. if(tree != null && !myPlayer().isAnimating() ){
  203. tree.interact("Chop Down");
  204. sleep(random(1000,1200));
  205. }
  206.  
  207. if(!GEtrees.contains(myPlayer()) && Banktime == false){
  208. determine = true;
  209. }
  210. break;
  211. case CHOPPING_WVOAKS:
  212. Entity oak = objects.closest(WVoak, "Oak");
  213. if(oak != null && !myPlayer().isAnimating()){
  214. oak.interact("Chop Down");
  215. sleep(random(1000,1200));
  216. }
  217.  
  218. break;
  219.  
  220. case DROPPING:
  221. if(dropit == true){
  222. inventory.dropAllExcept("Silver axe", "Bronze axe", "Black axe", "Iron axe", "Rune axe", "Steel", "Mithril axe", "Dragon axe"); //put the axe id's where the 0 is
  223. }
  224. break;
  225. case BANKING:
  226. log("Banking");
  227. if(GEtreecutter == true){
  228. getWalking().webWalk(GEbank);
  229. Entity banker = objects.closest("Grand Exchange Booth");
  230. if(banker != null){
  231. banker.interact("Bank");
  232. sleep(random(1000,1100));
  233. } else {
  234. log("No banker found");
  235.  
  236. }
  237. }
  238. if(WVoakcutter == true){
  239. getWalking().webWalk(WVbank);
  240. Entity banker = objects.closest("Bank booth");
  241. if(banker != null){
  242. banker.interact("Bank");
  243. sleep(random(1000,1100));
  244. } else {
  245. log("No banker found");
  246. }
  247. }
  248. sleep(random(600,700));
  249. getBank().depositAllExcept("Silver axe", "Bronze axe", "Black axe", "Iron axe", "Rune axe", "Steel", "Mithril axe", "Dragon axe");
  250. log("walkback = true");
  251. determine = true;
  252. Banktime = false;
  253. break;
  254. case WALKING_FRA_BANK:
  255. log("Walk back from bank");
  256. if(GEtreecutter == true){
  257. getWalking().webWalk(GEtrees);
  258. walkback = false;
  259. }
  260. if(WVoakcutter == true){
  261. log("Walk back from oaks");
  262. getWalking().webWalk(WVoak);
  263. walkback = false;
  264. }
  265. break;
  266. case DETERMINELOCATION:
  267. log("State.DETERMINELOCATION");
  268. if(GEtreecutter == true){
  269. log("Determinelocation walking to getrees");
  270. getWalking().webWalk(GEtrees);
  271. log("Determine = false");
  272. determine = false;
  273. }
  274. if(WVoakcutter == true){
  275. log("WVoakcutter webwalk");
  276. getWalking().webWalk(WVoak);
  277. determine = false;
  278. }
  279. break;
  280. case WAIT:
  281. break;
  282. } //above is where the script actually does stuff
  283. if(random(1,7) == 4){
  284. getMouse().moveRandomly();
  285. } else if(random(7,20) == 9){
  286. getMouse().moveOutsideScreen();
  287. }
  288.  
  289. if(random(1,9) == 4){
  290. getCamera().moveYaw(random(10,140));
  291. }
  292. //antiban above
  293. return random(700, 900);
  294. }
  295.  
  296.  
  297.  
  298. @Override
  299. public void onExit() { //what to do when the script stops
  300. }
  301.  
  302. @Override
  303. public void onPaint(Graphics2D g) { //Beautiful banters and such
  304. timeRan = System.currentTimeMillis() - this.timeBegan;
  305.  
  306. if(hide == false){
  307. if(optionb == false){
  308. g.drawImage(bg, 2, 340, null);
  309. g.drawString(ft(timeRan), 100, 470);
  310. g.drawString("Bot Time:", 20, 470);
  311.  
  312. if(dropit == false){
  313. g.drawString("Banking", 97, 400);
  314. } else {
  315. g.drawString("Dropping", 97, 400);
  316. }
  317. }
  318. }
  319.  
  320. if(hide == true){
  321. g.drawRect(405, 459, 108, 15);
  322. }
  323.  
  324.  
  325. //////////////////////////////////////////////////////
  326. if(optionb == true){
  327. g.drawRect(488, 346, 19, 18);
  328. g.drawRect(80, 370, 45, 13);
  329. g.drawString("Choose Location And Log", 180, 359);
  330. g.drawString("GE logs", 80, 380);
  331. g.drawString("WV oaks", 160, 380);
  332. g.drawString("Toggle Bank", 320, 402);
  333. g.drawRect(160, 370, 55, 13);
  334. g.drawRect(320, 390, 75, 15); //Banking dropping rect
  335.  
  336. }
  337.  
  338.  
  339. }
  340.  
  341. private String ft(long duration)
  342. {
  343. String res = "";
  344. long days = TimeUnit.MILLISECONDS.toDays(duration);
  345. long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
  346. long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(duration));
  347. long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration));
  348. if (days == 0)
  349. {
  350. res = (hours + ":" + minutes + ":" + seconds);
  351. }
  352. else
  353. {
  354. res = (days + ":" + hours + ":" + minutes + ":" + seconds);
  355. }
  356. return res;
  357. }
  358.  
  359. private Image getImage(String url)
  360. {
  361. try
  362. {
  363. return ImageIO.read(new URL(url));
  364. }
  365. catch (IOException e) {}
  366. return null;
  367. }
  368.  
  369. }
Advertisement
Add Comment
Please, Sign In to add comment