Advertisement
Guest User

yews

a guest
Sep 26th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package source;
  2.  
  3. import org.osbot.script.Script;
  4. import org.osbot.script.ScriptManifest;
  5. import org.osbot.script.rs2.map.Position;
  6. import org.osbot.script.rs2.model.GroundItem;
  7. import org.osbot.script.rs2.model.RS2Object;
  8.  
  9. @ScriptManifest(author = "Zach (LifezHatred)", info = "Chops yews man", name = "XYewCutter", version = 1.0)
  10. public class Main extends Script {
  11.  
  12.     public long lastRun = 0;
  13.     public Position lastClick = null;
  14.     public int randomDistance = 0;
  15.    
  16.     public int treeId = 12611;
  17.     public int logId = 0;
  18.     public int axeId = 6739;
  19.     public int axeHeadId = 6743;
  20.     public boolean atTrees = false;
  21.     public RS2Object tree = null;
  22.    
  23.     public boolean checkGround() {
  24.         GroundItem axeHead = closestGroundItem(axeHeadId);
  25.         GroundItem nest = closestGroundItemForName("Bird nest");
  26.         if(axeHead != null && axeHead.exists()) {
  27.             try {
  28.                 axeHead.interact("Take");
  29.                 return true;
  30.             } catch (InterruptedException e) {
  31.                 // TODO Auto-generated catch block
  32.                 e.printStackTrace();
  33.             }
  34.         }
  35.         if(nest != null && nest.exists()) {
  36.             try {
  37.                 nest.interact("Take");
  38.                 return true;
  39.             } catch (InterruptedException e) {
  40.                 // TODO Auto-generated catch block
  41.                 e.printStackTrace();
  42.             }
  43.         }
  44.         return false;
  45.     }
  46.    
  47.     public int onLoop() {
  48.         if(checkGround()) {
  49.             return 3000;
  50.         }
  51.         if(myPlayer().getClient().getInventory().getEmptySlots() == 0) {
  52.             tree = null;
  53.             atTrees = false;
  54.             try {
  55.                 if(walkToLocation(new Position(2809, 3441, 0))) {
  56.                     RS2Object bankBooth = closestObjectForName("Bank booth");
  57.                     if(client.getBank().isOpen()) {
  58.                         try {
  59.                             client.getBank().depositAllExcept(axeId);
  60.                             sleep(1000);
  61.                             client.getBank().close();
  62.                             return 2000;
  63.                         } catch (InterruptedException e) {
  64.                             // TODO Auto-generated catch block
  65.                             e.printStackTrace();
  66.                         }
  67.                     } else {
  68.                         if(bankBooth.isVisible()) {
  69.                             try {
  70.                                 bankBooth.interact("Bank");
  71.                             } catch (InterruptedException e) {
  72.                                 // TODO Auto-generated catch block
  73.                                 e.printStackTrace();
  74.                             }
  75.                             return 1200 + (int) (Math.random() * 600);
  76.                         } else {
  77.                             try {
  78.                                 client.moveCameraToEntity(bankBooth);
  79.                             } catch (InterruptedException e) {
  80.                                 // TODO Auto-generated catch block
  81.                                 e.printStackTrace();
  82.                             }
  83.                         }
  84.                     }
  85.                 }
  86.             } catch (InterruptedException e) {
  87.                 // TODO Auto-generated catch block
  88.                 e.printStackTrace();
  89.             }
  90.         } else {
  91.             if(!atTrees) {
  92.                 try {
  93.                     atTrees = walkToLocation(new Position(2769, 3430, 0));
  94.                 } catch (InterruptedException e) {
  95.                     // TODO Auto-generated catch block
  96.                     e.printStackTrace();
  97.                 }
  98.             } else {
  99.                 if(tree == null || !tree.exists()) {
  100.                     tree = closestObject(treeId);
  101.                     try {
  102.                         tree.interact("Chop down");
  103.                         return 2400;
  104.                     } catch (InterruptedException e) {
  105.                         // TODO Auto-generated catch block
  106.                         e.printStackTrace();
  107.                     }
  108.                 } else if(myPlayer().getAnimation() > 0) {
  109.                     try {
  110.                         sleep(600);
  111.                     } catch (InterruptedException e) {
  112.                         // TODO Auto-generated catch block
  113.                         e.printStackTrace();
  114.                     }
  115.                 } else {
  116.                     if(tree.exists()) {
  117.                         try {
  118.                             tree.interact("Chop down");
  119.                             return 2400;
  120.                         } catch (InterruptedException e) {
  121.                             // TODO Auto-generated catch block
  122.                             e.printStackTrace();
  123.                         }
  124.                     }
  125.                 }
  126.             }
  127.         }
  128.         return 100;
  129.     }
  130.    
  131.     public boolean walkToLocation(Position p) throws InterruptedException {
  132.         int maxY;
  133.         int maxX;
  134.         boolean revY = false;
  135.         boolean revX = false;
  136.         Position playerPosition = myPlayer().getPosition();
  137.         if(playerPosition.getX() < p.getX()) {
  138.             revX = true;
  139.             int distance = p.getX()-playerPosition.getX();
  140.             if(distance > 17) {
  141.                 maxX = 17;
  142.             } else {
  143.                 maxX = distance;
  144.             }
  145.         } else {
  146.             int distance = playerPosition.getX()-p.getX();
  147.             if(distance > 17) {
  148.                 maxX = 17;
  149.             } else {
  150.                 maxX = distance;
  151.             }
  152.         }
  153.         if(playerPosition.getY() < p.getY()) {
  154.             revY = true;
  155.             int distance = p.getY()-playerPosition.getY();
  156.             if(distance > 17) {
  157.                 maxY = 17;
  158.             } else {
  159.                 maxY = distance;
  160.             }
  161.         } else {
  162.             int distance = playerPosition.getY()-p.getY();
  163.             if(distance > 17) {
  164.                 maxY = 17;
  165.             } else {
  166.                 maxY = distance;
  167.             }
  168.         }
  169.         int addX = (int) (10+(Math.random()*(maxX-10)));
  170.         int addY = (int) (10+(Math.random()*(maxY-10)));
  171.         if(maxX < 10) {
  172.             addX = maxX;
  173.         }
  174.         if(maxY < 10) {
  175.             addY = maxY;
  176.         }
  177.         if(!revX) {
  178.             addX = addX*-1;
  179.         }
  180.         if(!revY) {
  181.             addY = addY*-1;
  182.         }
  183.         if(lastClick == null) {
  184.             if(walk(new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()))) {
  185.                 lastClick = new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ());
  186.                 randomDistance = (int) (3+(Math.random() * 3));
  187.             }
  188.         } else {
  189.             if(lastClick.distance(myPlayer().getPosition()) < randomDistance) {
  190.                 if(walk(new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ()))) {
  191.                     lastClick = new Position(playerPosition.getX()+addX, playerPosition.getY()+addY, playerPosition.getZ());
  192.                     randomDistance = (int) (3+(Math.random() * 3));
  193.                 }
  194.             }
  195.         }
  196.         if(lastClick.distance(p) < 5) {
  197.             lastClick = null;
  198.             return true;
  199.         }
  200.         return false;
  201.     }
  202.    
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement