Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Author: Kevin Spaeth
- * Script updated: Version 1.1 ~ 2/3/2014
- * Usage: Copyright protected, informational use only
- * Info: Completes the agility course in the Gnome Stronghold
- */
- package scripts;
- import java.net.URL;
- import java.awt.Font;
- import java.awt.Color;
- import java.awt.Image;
- import java.awt.Graphics;
- import java.io.IOException;
- import java.util.Random;
- import javax.imageio.ImageIO;
- import org.tribot.api.Timing;
- import org.tribot.api.General;
- import org.tribot.script.Script;
- import org.tribot.script.ScriptManifest;
- import org.tribot.api2007.Camera;
- import org.tribot.api2007.Player;
- import org.tribot.api2007.Skills;
- import org.tribot.api2007.Objects;
- import org.tribot.api2007.Walking;
- import org.tribot.api2007.types.RSTile;
- import org.tribot.api2007.Skills.SKILLS;
- import org.tribot.api2007.types.RSObject;
- import org.tribot.script.interfaces.Painting;
- @ScriptManifest(authors = { "Sp333th" }, category = "Agility", name = "Sp333th Gnome Agility V1.1", description =
- "<html>" +
- "<head>" +
- "<title>HTML Editor Sample Page</title>" +
- "</head>" +
- "<body>" +
- "<p style=\"text-align: center;\">" +
- "<span style=\"color:#ff0000;\"><span style=\"font-family:comic sans ms,cursive;\"><span style=\"font-size:30px;\">Sp333th Gnome Agility</span></span></span></p>" +
- "<p style=\"text-align: center;\">" +
- "<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's it!</span></span></span></p>" +
- "<p style=\"text-align: center;\">" +
- "<img alt=\"\" src=\"http://s27.postimg.org/cvpwmrcr7/image.png\" style=\"width: 417px; height: 457px;\" /></p>" +
- "</body>" +
- "</html>")
- public class Sp333thGnomeAgility extends Script implements Painting {
- //System variables
- private Random rand;
- private boolean running;
- //GUI Variables
- private long timeBegan;
- private int beginningXP;
- private int beginningLVL;
- //More GUI Variables
- private Font textFont;
- private Image paintImg;
- private String version;
- private Color textColor;
- //RSTiles
- private RSTile endLoc;
- private RSTile net1Loc;
- private RSTile net2Loc;
- private RSTile pipeLoc;
- private RSTile ropeLoc;
- private RSTile net2Loc2;
- private RSTile ropeLoc2;
- private RSTile startLoc;
- private RSTile branch1Loc;
- private RSTile branch2Loc;
- //Object IDs
- private int logID;
- private int netID;
- private int netID2;
- private int ropeID;
- private int pipeID;
- private int pipeID2;
- private int branchID;
- private int branchID2;
- private int branchID3;
- //Time to complete obstacle
- private int logTime;
- private int netTime;
- private int ropeTime;
- private int pipeTime;
- private int branchTime;
- //Up-Texts
- private String crossLog;
- private String climbNet;
- private String crossRope;
- private String climbDown;
- private String goThruPipe;
- private String climbBranch;
- @Override
- public void run() {
- //Start the script
- if(onStart()) {
- //Loop while running
- while(running) {
- //Execute loop
- sleep(loop());
- }
- }
- }
- //This happens every time the program iterates
- private int loop() {
- //Used to choose a random obstacle
- int randPipeID;
- int randBranchID;
- //Used to generate some randomness
- int randPipe = rand.nextInt(2);
- int randBranch = rand.nextInt(2);
- int random = rand.nextInt(1000);
- //Determine which pipe to use
- if(randPipe == 1) {
- randPipeID = pipeID;
- }else{
- randPipeID = pipeID2;
- }
- //Determine which branch to use
- if(randBranch == 1) {
- randBranchID = branchID2;
- }else{
- randBranchID = branchID3;
- }
- //Program Loop:
- //Cross the log
- if(at(startLoc, 4)) {
- if(nav(logID, logTime, crossLog)) {}
- //Climb the net
- }else if(at(net1Loc, 2)) {
- if(nav(netID, netTime, climbNet)) {}
- //Climb the branch
- }else if(at(branch1Loc, 3)) {
- if(nav(branchID, branchTime, climbBranch)) {}
- //Walk to and cross the rope
- }else if(at(ropeLoc, 2)) {
- if(walkTo(ropeLoc2)) {
- if(nav(ropeID, ropeTime, crossRope)) {}
- }
- //Cross the rope
- }else if(at(ropeLoc2, 2)) {
- if(nav(ropeID, ropeTime, crossRope)) {}
- //Climb down the branch
- }else if(at(branch2Loc, 2)) {
- if(nav(randBranchID, branchTime, climbDown)) {}
- //Walk to and climb the net
- }else if(at(net2Loc, 2)) {
- if(walkTo(net2Loc2)) {
- if(nav(netID2, netTime, climbNet)) {}
- }
- //Climb the net
- }else if(at(net2Loc2, 2)) {
- if(nav(netID2, netTime, climbNet)) {}
- //Go through the pipe
- }else if(at(pipeLoc, 3)) {
- if(nav(randPipeID, pipeTime, goThruPipe)) {}
- //Walk to the start location
- }else if(at(endLoc, 3)) {
- if(walkTo(startLoc)) {}
- //Nothing
- }else{}
- //Sleep for a random duration
- return random;
- }
- //Waits until the player is idle
- private void waitToIdle(int sleep) {
- //Initial sleep
- sleep(sleep, sleep+250);
- while(true) {
- //The player is idle if they're not moving and they have the default animation of -1
- if(!Player.isMoving() && Player.getAnimation()==-1){
- break;
- }
- //Wait and check again
- sleep(sleep+250, sleep+500);
- }
- }
- //This is called before the script starts running
- private boolean onStart() {
- rand = new Random();
- boolean started = false;
- //Moves the camera
- Camera.setCameraAngle(General.random(65, 75));
- Camera.setCameraRotation(General.random(210, 230));
- //Makes the player use run energy
- Walking.setControlClick(true);
- //Sets the color/font/image for the GUI
- textColor = new Color(201, 33, 0);
- textFont = new Font("Comic Sans MS", 7, 20);
- paintImg = getImage("http://s4.postimg.org/g1inf5jbh/image.png");
- //Sets the strings/data for the GUI
- version = "V1.1";
- timeBegan = System.currentTimeMillis();
- beginningXP = Skills.getXP(SKILLS.AGILITY);
- beginningLVL = Skills.getCurrentLevel(SKILLS.AGILITY);
- //These are the up-texts
- climbBranch = "Climb";
- crossRope = "Walk-on";
- climbNet = "Climb-over";
- climbDown = "Climb-down";
- crossLog = "Walk-across";
- goThruPipe = "Squeeze-through";
- //This is how long it takes to complete an obstacle in milliseconds
- logTime = 5000;
- netTime = 2500;
- ropeTime = 5000;
- pipeTime = 8500;
- branchTime = 2500;
- //These are the object IDs
- logID = 14971;
- netID = 14960;
- netID2 = 14961;
- ropeID = 15620;
- pipeID = 14964;
- pipeID2 = 14965;
- branchID = 15622;
- branchID2 = 15623;
- branchID3 = 15624;
- //These are the RSTiles
- endLoc = new RSTile(2485, 3437, 0);
- net1Loc = new RSTile(2474, 3429, 0);
- net2Loc = new RSTile(2487, 3420, 0);
- pipeLoc = new RSTile(2485, 3428, 0);
- ropeLoc = new RSTile(2473, 3420, 2);
- ropeLoc2 = new RSTile(2477, 3420, 2);
- startLoc = new RSTile(2474, 3437, 0);
- net2Loc2 = new RSTile(2485, 3425, 0);
- branch1Loc = new RSTile(2473, 3423, 1);
- branch2Loc = new RSTile(2483, 3420, 2);
- running = true;
- started = true;
- return started;
- }
- //Walks to the passed RSTile
- private boolean walkTo(RSTile tile) {
- boolean walked = false;
- //Try to click the RSTile
- while(walked == false) {
- if(Walking.clickTileMM(tile, 1)) {
- //Wait until the player is idle
- waitToIdle(100);
- walked = true;
- }else{
- //Wait and try again
- waitToIdle(100);
- }
- }
- return walked;
- }
- //Returns true if the player is within the specified distance of the RSTile
- private boolean at(RSTile tile, int distance) {
- return ((Player.getPosition().distanceTo(tile) <= distance) && (Player.getPosition().getPlane() == tile.getPlane()));
- }
- //Navigates an agility obstacle giving the following arguments
- private boolean nav(int navID, int sleep, String upText) {
- boolean navd = false;
- //Find nearest obstacle...
- RSObject[] obj = Objects.findNearest(5, navID);
- //If something was found, try to click it
- if(obj!=null && obj.length>0) {
- while(navd == false) {
- //Click the object
- if(obj[0].click(upText)) {
- //Sleep until the object is navigated
- sleep(sleep);
- //Wait until the player is idle
- waitToIdle(100);
- navd = true;
- }else{
- //Wait and try to click the object again
- waitToIdle(100);
- }
- }
- }
- return navd;
- }
- //Gets an image from a URL to be used with a GUI
- private Image getImage(String url){
- //Try to get the image at the specified URL.
- try{
- return ImageIO.read(new URL(url));
- //The following executes if the try block throws an exception.
- }catch(IOException e){
- //Although... nothing is done.
- return null;
- }
- }
- @Override
- public void onPaint(Graphics arg0) {
- //Calculate variables to draw.
- long timeRan = System.currentTimeMillis() - timeBegan;
- int currentLVL = Skills.getCurrentLevel(SKILLS.AGILITY);
- int gainedLVL = currentLVL - beginningLVL;
- int xpGained = (Skills.getXP(SKILLS.AGILITY) - beginningXP);
- //Set font and text.
- arg0.setFont(textFont);
- arg0.setColor(textColor);
- //Draw paint.
- arg0.drawImage(paintImg, 1, 338, null);
- arg0.drawString(version, 400, 430);
- arg0.drawString(""+xpGained, 215, 456);
- arg0.drawString(Timing.msToString(timeRan), 400, 457);
- arg0.drawString(beginningLVL + " (+" + gainedLVL + ")", 140, 427);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement