Advertisement
Guest User

Sp333th Gnome Agility V1.1

a guest
Feb 4th, 2014
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.24 KB | None | 0 0
  1. /*
  2.  * Author: Kevin Spaeth
  3.  * Script updated: Version 1.1 ~ 2/3/2014
  4.  * Usage: Copyright protected, informational use only
  5.  * Info: Completes the agility course in the Gnome Stronghold
  6.  */
  7.  
  8. package scripts;
  9.  
  10. import java.net.URL;
  11. import java.awt.Font;
  12. import java.awt.Color;
  13. import java.awt.Image;
  14. import java.awt.Graphics;
  15. import java.io.IOException;
  16. import java.util.Random;
  17.  
  18. import javax.imageio.ImageIO;
  19.  
  20. import org.tribot.api.Timing;
  21. import org.tribot.api.General;
  22. import org.tribot.script.Script;
  23. import org.tribot.script.ScriptManifest;
  24. import org.tribot.api2007.Camera;
  25. import org.tribot.api2007.Player;
  26. import org.tribot.api2007.Skills;
  27. import org.tribot.api2007.Objects;
  28. import org.tribot.api2007.Walking;
  29. import org.tribot.api2007.types.RSTile;
  30. import org.tribot.api2007.Skills.SKILLS;
  31. import org.tribot.api2007.types.RSObject;
  32. import org.tribot.script.interfaces.Painting;
  33.  
  34. @ScriptManifest(authors = { "Sp333th" }, category = "Agility", name = "Sp333th Gnome Agility V1.1", description =
  35. "<html>" +
  36.         "<head>" +
  37.         "<title>HTML Editor Sample Page</title>" +
  38.         "</head>" +
  39.         "<body>" +
  40.         "<p style=\"text-align: center;\">" +
  41.         "<span style=\"color:#ff0000;\"><span style=\"font-family:comic sans ms,cursive;\"><span style=\"font-size:30px;\">Sp333th Gnome Agility</span></span></span></p>" +
  42.         "<p style=\"text-align: center;\">" +
  43.         "<span style=\"color:#808080;\"><span style=\"font-size:14px;\"><span style=\"font-family:comic sans ms,cursive;\">Start this script at the first obstacle of the Gnome Stronghold agility course. That&#39;s it!</span></span></span></p>" +
  44.         "<p style=\"text-align: center;\">" +
  45.         "<img alt=\"\" src=\"http://s27.postimg.org/cvpwmrcr7/image.png\" style=\"width: 417px; height: 457px;\" /></p>" +
  46.         "</body>" +
  47.         "</html>")
  48. public class Sp333thGnomeAgility extends Script implements Painting {
  49.     //System variables
  50.     private Random rand;
  51.     private boolean running;
  52.  
  53.     //GUI Variables
  54.     private long timeBegan;
  55.     private int beginningXP;
  56.     private int beginningLVL;
  57.  
  58.     //More GUI Variables
  59.     private Font textFont;
  60.     private Image paintImg;
  61.     private String version;
  62.     private Color textColor;
  63.  
  64.     //RSTiles
  65.     private RSTile endLoc;
  66.     private RSTile net1Loc;
  67.     private RSTile net2Loc;
  68.     private RSTile pipeLoc;
  69.     private RSTile ropeLoc;
  70.     private RSTile net2Loc2;
  71.     private RSTile ropeLoc2;
  72.     private RSTile startLoc;
  73.     private RSTile branch1Loc;
  74.     private RSTile branch2Loc;
  75.  
  76.     //Object IDs
  77.     private int logID;
  78.     private int netID;
  79.     private int netID2;
  80.     private int ropeID;
  81.     private int pipeID;
  82.     private int pipeID2;
  83.     private int branchID;
  84.     private int branchID2;
  85.     private int branchID3;
  86.  
  87.     //Time to complete obstacle
  88.     private int logTime;
  89.     private int netTime;
  90.     private int ropeTime;
  91.     private int pipeTime;
  92.     private int branchTime;
  93.  
  94.     //Up-Texts
  95.     private String crossLog;
  96.     private String climbNet;
  97.     private String crossRope;
  98.     private String climbDown;
  99.     private String goThruPipe;
  100.     private String climbBranch;
  101.  
  102.     @Override
  103.     public void run() {
  104.         //Start the script
  105.         if(onStart()) {
  106.             //Loop while running
  107.             while(running) {
  108.                 //Execute loop
  109.                 sleep(loop());
  110.             }
  111.         }
  112.     }
  113.  
  114.     //This happens every time the program iterates
  115.     private int loop() {
  116.         //Used to choose a random obstacle
  117.         int randPipeID;
  118.         int randBranchID;
  119.  
  120.         //Used to generate some randomness
  121.         int randPipe = rand.nextInt(2);
  122.         int randBranch = rand.nextInt(2);
  123.         int random = rand.nextInt(1000);
  124.  
  125.         //Determine which pipe to use
  126.         if(randPipe == 1) {
  127.             randPipeID = pipeID;
  128.         }else{
  129.             randPipeID = pipeID2;
  130.         }
  131.  
  132.         //Determine which branch to use
  133.         if(randBranch == 1) {
  134.             randBranchID = branchID2;
  135.         }else{
  136.             randBranchID = branchID3;
  137.         }
  138.  
  139.  
  140.         //Program Loop:
  141.  
  142.         //Cross the log
  143.         if(at(startLoc, 4)) {
  144.             if(nav(logID, logTime, crossLog)) {}
  145.  
  146.             //Climb the net
  147.         }else if(at(net1Loc, 2)) {
  148.             if(nav(netID, netTime, climbNet)) {}
  149.  
  150.             //Climb the branch
  151.         }else if(at(branch1Loc, 3)) {
  152.             if(nav(branchID, branchTime, climbBranch)) {}
  153.  
  154.             //Walk to and cross the rope
  155.         }else if(at(ropeLoc, 2)) {
  156.             if(walkTo(ropeLoc2)) {
  157.                 if(nav(ropeID, ropeTime, crossRope)) {}
  158.             }
  159.  
  160.             //Cross the rope
  161.         }else if(at(ropeLoc2, 2)) {
  162.             if(nav(ropeID, ropeTime, crossRope)) {}
  163.  
  164.             //Climb down the branch
  165.         }else if(at(branch2Loc, 2)) {
  166.             if(nav(randBranchID, branchTime, climbDown)) {}
  167.  
  168.             //Walk to and climb the net
  169.         }else if(at(net2Loc, 2)) {
  170.             if(walkTo(net2Loc2)) {
  171.                 if(nav(netID2, netTime, climbNet)) {}
  172.             }
  173.  
  174.             //Climb the net
  175.         }else if(at(net2Loc2, 2)) {
  176.             if(nav(netID2, netTime, climbNet)) {}
  177.            
  178.             //Go through the pipe  
  179.         }else if(at(pipeLoc, 3)) {
  180.             if(nav(randPipeID, pipeTime, goThruPipe)) {}
  181.  
  182.             //Walk to the start location
  183.         }else if(at(endLoc, 3)) {
  184.             if(walkTo(startLoc)) {}
  185.  
  186.             //Nothing
  187.         }else{}
  188.  
  189.         //Sleep for a random duration
  190.         return random;
  191.     }
  192.  
  193.     //Waits until the player is idle
  194.     private void waitToIdle(int sleep) {
  195.         //Initial sleep
  196.         sleep(sleep, sleep+250);
  197.  
  198.         while(true) {
  199.             //The player is idle if they're not moving and they have the default animation of -1
  200.             if(!Player.isMoving() && Player.getAnimation()==-1){
  201.                 break;
  202.             }
  203.             //Wait and check again
  204.             sleep(sleep+250, sleep+500);
  205.         }
  206.     }
  207.  
  208.     //This is called before the script starts running
  209.     private boolean onStart() {
  210.         rand = new Random();
  211.         boolean started = false;
  212.  
  213.         //Moves the camera
  214.         Camera.setCameraAngle(General.random(65, 75));
  215.         Camera.setCameraRotation(General.random(210, 230));
  216.  
  217.         //Makes the player use run energy
  218.         Walking.setControlClick(true);
  219.  
  220.         //Sets the color/font/image for the GUI
  221.         textColor = new Color(201, 33, 0);
  222.         textFont = new Font("Comic Sans MS", 7, 20);
  223.         paintImg = getImage("http://s4.postimg.org/g1inf5jbh/image.png");
  224.  
  225.         //Sets the strings/data for the GUI
  226.         version = "V1.1";
  227.         timeBegan = System.currentTimeMillis();
  228.         beginningXP = Skills.getXP(SKILLS.AGILITY);
  229.         beginningLVL = Skills.getCurrentLevel(SKILLS.AGILITY);
  230.  
  231.         //These are the up-texts
  232.         climbBranch = "Climb";
  233.         crossRope = "Walk-on";
  234.         climbNet = "Climb-over";
  235.         climbDown = "Climb-down";
  236.         crossLog = "Walk-across";
  237.         goThruPipe = "Squeeze-through";
  238.  
  239.         //This is how long it takes to complete an obstacle in milliseconds
  240.         logTime = 5000;
  241.         netTime = 2500;
  242.         ropeTime = 5000;
  243.         pipeTime = 8500;
  244.         branchTime = 2500;
  245.  
  246.         //These are the object IDs
  247.         logID = 14971;
  248.         netID = 14960;
  249.         netID2 = 14961;
  250.         ropeID = 15620;
  251.         pipeID = 14964;
  252.         pipeID2 = 14965;
  253.         branchID = 15622;
  254.         branchID2 = 15623;
  255.         branchID3 = 15624;
  256.  
  257.         //These are the RSTiles
  258.         endLoc = new RSTile(2485, 3437, 0);
  259.         net1Loc = new RSTile(2474, 3429, 0);
  260.         net2Loc = new RSTile(2487, 3420, 0);
  261.         pipeLoc = new RSTile(2485, 3428, 0);
  262.         ropeLoc = new RSTile(2473, 3420, 2);
  263.         ropeLoc2 = new RSTile(2477, 3420, 2);
  264.         startLoc = new RSTile(2474, 3437, 0);
  265.         net2Loc2 = new RSTile(2485, 3425, 0);
  266.         branch1Loc = new RSTile(2473, 3423, 1);
  267.         branch2Loc = new RSTile(2483, 3420, 2);
  268.  
  269.         running = true;
  270.         started = true;
  271.         return started;
  272.     }
  273.  
  274.     //Walks to the passed RSTile
  275.     private boolean walkTo(RSTile tile) {
  276.         boolean walked = false;
  277.  
  278.         //Try to click the RSTile
  279.         while(walked == false) {
  280.             if(Walking.clickTileMM(tile, 1)) {
  281.                 //Wait until the player is idle
  282.                 waitToIdle(100);
  283.                 walked = true;
  284.             }else{
  285.                 //Wait and try again
  286.                 waitToIdle(100);
  287.             }
  288.         }
  289.         return walked;
  290.     }
  291.  
  292.     //Returns true if the player is within the specified distance of the RSTile
  293.     private boolean at(RSTile tile, int distance) {
  294.         return ((Player.getPosition().distanceTo(tile) <= distance) && (Player.getPosition().getPlane() == tile.getPlane()));
  295.     }
  296.  
  297.     //Navigates an agility obstacle giving the following arguments
  298.     private boolean nav(int navID, int sleep, String upText) {
  299.         boolean navd = false;
  300.  
  301.         //Find nearest obstacle...
  302.         RSObject[] obj = Objects.findNearest(5, navID);
  303.  
  304.         //If something was found, try to click it
  305.         if(obj!=null && obj.length>0) {
  306.             while(navd == false) {
  307.                 //Click the object
  308.                 if(obj[0].click(upText)) {
  309.                     //Sleep until the object is navigated
  310.                     sleep(sleep);
  311.                     //Wait until the player is idle
  312.                     waitToIdle(100);
  313.                     navd = true;
  314.                 }else{
  315.                     //Wait and try to click the object again
  316.                     waitToIdle(100);
  317.                 }
  318.             }
  319.         }
  320.         return navd;
  321.     }
  322.  
  323.     //Gets an image from a URL to be used with a GUI
  324.     private Image getImage(String url){
  325.         //Try to get the image at the specified URL.
  326.         try{
  327.             return ImageIO.read(new URL(url));
  328.             //The following executes if the try block throws an exception.
  329.         }catch(IOException e){
  330.             //Although... nothing is done.
  331.             return null;
  332.         }
  333.     }
  334.  
  335.     @Override
  336.     public void onPaint(Graphics arg0) {
  337.         //Calculate variables to draw.
  338.         long timeRan = System.currentTimeMillis() - timeBegan;
  339.         int currentLVL = Skills.getCurrentLevel(SKILLS.AGILITY);
  340.         int gainedLVL = currentLVL - beginningLVL;
  341.         int xpGained = (Skills.getXP(SKILLS.AGILITY) - beginningXP);
  342.  
  343.         //Set font and text.
  344.         arg0.setFont(textFont);
  345.         arg0.setColor(textColor);
  346.  
  347.         //Draw paint.
  348.         arg0.drawImage(paintImg, 1, 338, null);
  349.         arg0.drawString(version, 400, 430);
  350.         arg0.drawString(""+xpGained, 215, 456);
  351.         arg0.drawString(Timing.msToString(timeRan), 400, 457);
  352.         arg0.drawString(beginningLVL + " (+" + gainedLVL + ")", 140, 427);
  353.     }
  354. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement