Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by duckysd ( 16 years ago )
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.util.List;
import java.util.Map;

import org.rsbot.event.events.ServerMessageEvent;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.event.listeners.ServerMessageListener;
import org.rsbot.script.Calculations;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.wrappers.RSCharacter;
import org.rsbot.script.wrappers.RSInterface;
import org.rsbot.script.wrappers.RSItemTile;
import org.rsbot.script.wrappers.RSNPC;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSTile;

@ScriptManifest(authors = { "duckysd" }, category = "Combat", name = "CrawlSafer", version = 2.0, description = "Start in the place that has crawlers.")
public class SpiderSTRNGHold extends Script implements PaintListener,
  ServerMessageListener {

 final ScriptManifest properties = getClass().getAnnotation(
   ScriptManifest.class);

 private long startTime, startCook, startFish, startCombat;
 private int cookLevelsGained, combatLevelsGained, fishLevelsGained;
 String status = "Starting up...";
 long currRange;
 RSTile myLoc = getMyPlayer().getLocation();
 int Health = 0, cooking, rangeID, fishSpotID[] = {}, fishing,
   crawlerID[] = {}, fishRodID, flyFishRodID, baitID, featherID,
   rockID;
 int foodID[];
 // REMEMBER UP THEN DOWN in stairs array.
 int levelOneStairs[] = {};
 int levelTwoStairs[] = {};
 int levelThreeStairs[] = {};
 int portalID[] = {};
 RSTile fishToFire[] = { new RSTile(1000, 1000) };

 private RSObject getPortal(int num) {
  RSObject portal = null;
  int portalID = num - 1;
  if (getNearestObjectByID(portalID) != null) {
   portal = getNearestObjectByID(portalID);
  }
  return portal;
 }

 private RSObject getStairs(int choice, String upDown) {
  RSObject stair = null;
  int chosenStairs[] = null;
  String ud = upDown.toLowerCase();

  if (choice == 1) {
   chosenStairs = levelOneStairs;
  } else if (choice == 2) {
   chosenStairs = levelTwoStairs;
  } else if (choice == 3) {
   chosenStairs = levelThreeStairs;
  }

  if (ud == "down") {
   stair = getNearestObjectByID(chosenStairs[1]);
  } else if (ud == "up") {
   stair = getNearestObjectByID(chosenStairs[0]);
  }
  return stair;
 }

 @Override
 public boolean onStart(Map<String, String> args) {
  startTime = System.currentTimeMillis();
  startCook = skills.getCurrentSkillExp(STAT_COOKING);
  startFish = skills.getCurrentSkillExp(STAT_FISHING);
  startCombat = skills.getCurrentSkillExp(STAT_ATTACK)
    + skills.getCurrentSkillExp(STAT_DEFENSE)
    + skills.getCurrentSkillExp(STAT_STRENGTH)
    + skills.getCurrentSkillExp(STAT_HITPOINTS);
  log("Script started. It hasn't been tested yet!");
  currRange = skills.getCurrentSkillExp(STAT_RANGE);
  return true;
 }

 private int Health() {
  if (isLoggedIn()) {
   if (RSInterface.getInterface(748).getChild(8).isValid()) {
    if (RSInterface.getInterface(748).getChild(8).getText() != null) {
     Health = Integer.parseInt(RSInterface.getInterface(748)
       .getChild(8).getText());
    } else {
     log.severe("Getting lifepoints Error");
    }
   } else {
    log.warning("HP Interface is not valid");
   }
  }

  return Health;
 }

 private boolean pickUp(int[] id, String itemName) {
  boolean back = false;
  try {
   RSItemTile loots = getGroundItemByID(17, id);
   Point toscreen = Calculations.tileToScreen(loots);
   if (loots != null && !getMyPlayer().isMoving()) {
    back = true;
    if (pointOnScreen(toscreen)) {
     moveMouse(toscreen, 3, 3);
     wait(random(100, 200));
     if (getMenuItems().size() > 1) {
      if (listContainsString(getMenuItems(), itemName)) {
       if (getMenuItems().get(0).contains(itemName)) {
        clickMouse(true);
        wait(random(750, 1000));
       } else {
        clickMouse(false);
        wait(random(500, 750));
        atMenu(itemName);
        wait(random(750, 1000));
       }
      }
     }
    }
   }
  } catch (Exception e) {
  }
  return back;
 }

 private boolean listContainsString(List<String> list, String string) {
  try {
   int a;
   for (a = list.size() - 1; a-- >= 0;) {
    if (list.get(a).contains(string))
     return true;
   }
  } catch (Exception e) {
  }
  return false;
 }

 @Override
 protected int getMouseSpeed() {
  return random(5, 10);
 }

 @Override
 public void onFinish() {

 }

 private enum state {
  walkToFish, wait, logout, generatePathToFish, fish, walkToCook, cook, walkToEntrance, goDownToLevelOne, enterPortalOne, goDownToLevelTwo, enterPortalTwo, goDownToLevelThree, goToSpiders, fight, eat, goToLevelOne, goToLevelTwo, goToLevelThree, goUpToLevelTwo, goUpToLevelOne, goToSurface, goUpToSurface
 }

 private state getState() {
  while (isFishing() || isCooking()) {
   return state.wait;
  }

  if (finishedFishing()) {
   if (atFish()) {
    return state.walkToCook;
   } else {
    if (atSpiders()) {
     return state.goToLevelThree;
    } else {
     if (atLevelThree()) {
      return state.goUpToLevelTwo;
     } else {
      if (atLevelTwo()) {
       return state.goUpToLevelOne;
      } else {
       if (atLevelOne()) {
        return state.goUpToSurface;
       } else {
        if (atSurface()) {
         return state.walkToCook;
        } else {
         log.warning("We are lost. Logging out");
         return state.logout;
        }
       }
      }
     }
    }
   }
  }

  if (!inventoryContains(foodID)) {
   if (!atFish()) {
    if (atSpiders()) {
     return state.goToLevelThree;
    } else {
     if (atLevelThree()) {
      return state.goUpToLevelTwo;
     } else {
      if (atLevelTwo()) {
       return state.goUpToLevelOne;
      } else {
       if (atLevelOne()) {
        return state.goUpToSurface;
       } else {
        if (atCook()) {
         return state.walkToFish;
        } else {
         return state.generatePathToFish;
        }
       }
      }
     }
    }
   } else {
    return state.fish;
   }
  } else {
   if (!atSpiders()) {
    if (atCook()) {
     return state.goToSurface;
    } else {
     if (atSurface()) {
      return state.goDownToLevelOne;
     } else {
      if (atLevelOne()) {
       return state.enterPortalOne;
      } else {
       if (atLadderAreaOne()) {
        return state.goDownToLevelTwo;
       } else {
        if (atLevelTwo()) {
         return state.enterPortalTwo;
        } else {
         if (atLevelThree()) {
          return state.goToSpiders;
         } else {
          log
            .warning("We are lost!:( logging out");
         }
        }
       }
      }
     }
    }
   } else {
    return state.fight;
   }
  }
  return null;
 }

 private boolean finishedFishing() {
  return !isFishing() && isInventoryFull();
 }

 private boolean isCooking() {
  RSObject range = getNearestObjectByID(rangeID);
  return animationIs(cooking) && !animationIs(-1)
    && distanceTo(range.getLocation()) < 2 && range != null;
 }

 private boolean isFishing() {
  RSNPC fishSpot = getNearestNPCByID(fishSpotID);
  return animationIs(fishing) && !animationIs(-1)
    && distanceTo(fishSpot.getLocation()) < 2 && fishSpot != null;
 }

 private boolean atLadderAreaOne() {
  // TODO get the ID of the gift of peace box thinggy
  return false;
 }

 private boolean atSurface() {
  // TODO get ID of the coal rocks and that girl
  return false;
 }

 private boolean atCook() {
  RSObject range = getNearestObjectByID(rangeID);
  return range != null && tileOnScreen(range.getLocation());
 }

 private boolean atLevelOne() {
  // TODO get ID of portal, the skeleton and the first ladder, maybe door
  // too.
  return false;
 }

 private boolean atLevelTwo() {
  // TODO find object in that place, and check if they are not null.
  return false;
 }

 private boolean atLevelThree() {
  // TODO same as atLevelOne()
  return false;
 }

 private boolean atSpiders() {
  // TODO if those dinosaurs are not null and if there are spiders around.
  return false;
 }

 private boolean atFish() {
  RSNPC fishSpot = getNearestNPCByID(fishSpotID);
  return distanceTo(fishSpot.getLocation()) < 2 && fishSpot != null;
 }

 @Override
 public void serverMessageRecieved(final ServerMessageEvent m) {
  final String message = m.getMessage();
  if (message.contains("I'm already under attack.")) {
   status = "Re-attacking crawler";
   if (getMyPlayer().getInteracting() != null) {
    RSCharacter npc = getMyPlayer().getInteracting();
    if (npc != null) {
     moveMouse(Calculations.tileToScreen(npc.getLocation()));
     wait(100);
     if (getMenuActions().contains("Attack")) {
      if (getMenuIndex("Attack") == 0) {
       clickMouse(true);
       wait(300);
       return;
      } else {
       clickMouse(false);
       wait(500);
       atMenu("Attack");
      }
     }
    }
    return;
   }
  }
 }

 public void serverMessageRecieved2(ServerMessageEvent arg0) {
  if (arg0.getMessage().contains("advanced a Fishing level!")) {
   log("Fishing leveled up!");
   fishLevelsGained++;
   if (canContinue()) {
    clickContinue();
    return;
   }
  } else if (arg0.getMessage().contains("10 seconds")) {
   wait(random(6000, 11000));
  }

  if (arg0.getMessage().contains("advanced a Cooking level!")) {
   log("Cooking leveled up!");
   cookLevelsGained++;
   if (canContinue()) {
    clickContinue();
    return;
   }
  }
  if (arg0.getMessage().contains("advanced a Defence level!")
    || arg0.getMessage().contains("advanced a Strength level!")
    || arg0.getMessage().contains("advanced a Hitpoints level!")
    || arg0.getMessage().contains("advanced a Defence level!")) {
   log("Combat skill leveled up!");
   combatLevelsGained++;
   if (canContinue()) {
    clickContinue();
    return;
   }
  }
 }

 @SuppressWarnings("unused")
 private boolean atGroundItem(RSTile itemLocation, String actionToPerform) { // Item
  // pick-up
  return canClick(itemLocation) && atTile(itemLocation, actionToPerform);
 }

 private boolean canClick(RSTile refLocation) { // Check if we can click the
  // tile
  return refLocation != null && tileOnScreen(refLocation)
    && pointOnScreen(refLocation.getScreenLocation());
 }

 // CREDIT TO RAWR FOR ANTIBAN
 void antiBan() {
  int randomNum = random(1, 30);
  int r = random(1, 35);
  if (randomNum == 6) {
   if (r == 1) {
    setCameraRotation(random(100, 360));
    wait(random(200, 400));
   }
   if (r == 2) {
    setCameraRotation(random(100, 360));
    wait(random(200, 400));
   }
   if (r == 3) {
    setCameraRotation(random(100, 360));
    wait(random(200, 400));
   }
   if (r == 4) {
    setCameraRotation(random(100, 360));
    wait(random(200, 400));
   }

  }
 }

 // Credit to whom ever made this. Most effective method ever used =D
 private boolean fightNPC(final RSNPC npc, final String action) {
  final RSTile tile = npc.getLocation();
  tile.randomizeTile(1, 1);
  try {
   final int hoverRand = random(8, 13);
   for (int i = 0; i < hoverRand; i++) {
    final Point screenLoc = npc.getScreenLocation();
    if (!pointOnScreen(screenLoc)) {
     status = "Searching...";
     setCameraRotation(getCameraAngle() + random(-35, 150));
     return true;
    }

    moveMouse(screenLoc, 15, 15);

    final List<String> menuItems = getMenuItems();
    if (menuItems.isEmpty() || menuItems.size() <= 1) {
     continue;
    }
    if (menuItems.get(0).toLowerCase().contains(
      npc.getName().toLowerCase())
      && getMyPlayer().getInteracting() == null) {
     clickMouse(true);
     return true;
    } else {
     for (int a = 1; a < menuItems.size(); a++) {
      if (menuItems.get(a).toLowerCase().contains(
        npc.getName().toLowerCase())
        && getMyPlayer().getInteracting() == null) {
       clickMouse(false);
       return atMenu(action);
      }
     }
    }
   }

  } catch (final Exception e) {
   log.warning("fightNPC(RSNPC, String) error: " + e);
   return false;
  }
  return false;
 }

 // Loop
 @Override
 public int loop() {
  setCameraAltitude(true);
  antiBan();
  if (getEnergy() > random(50, 70)) {
   setRun(true);
   wait(random(500, 750));
  }
  
  if(!waitToMove(random(9000,14000))){
   log.warning("Haven't moved for 10 seconds, loging out.");
   logout();
  }

  switch (getState()) {
  case fight:
   fightNPC(getNearestFreeNPCByID(crawlerID), "Attack");
   break;
  case eat:
   for (int a : foodID) {
    if (inventoryContains(a)) {
     atInventoryItem(a, "Eat");
    } else {
     log.warning("!!NO FOOD!!");
    }
   }
  case enterPortalOne:
   if (getPortal(1) != null) {
    if (tileOnScreen(getPortal(1).getLocation())) {
     if (isIdle()) {
      atObject(getPortal(1), "Enter");
     }
    } else {
     if (tileOnMap(getPortal(1).getLocation())) {
      walkTileMM(getPortal(1).getLocation());
     }
    }
   } else {
    log.warning("Couldn't find portal 1");
   }
   break;
  case enterPortalTwo:
   if (getPortal(2) != null) {
    if (tileOnScreen(getPortal(2).getLocation())) {
     if (isIdle()) {
      atObject(getPortal(2), "Enter");
     }
    } else {
     if (tileOnMap(getPortal(2).getLocation())) {
      walkTileMM(getPortal(2).getLocation());
     }
    }
   } else {
    log.warning("Couldn't find portal 2");
   }
   break;
  case fish:
   if (atFish()) {
    RSNPC fish = getNearestNPCByID(fishSpotID);
    if (fish != null) {
     if (tileOnScreen(fish.getLocation())) {
      atNPC(fish, fishStyle());
     }
    }
   }
   break;
  case generatePathToFish:
   if (isIdle()) {
    Walk(generateFixedPath(fishToFire[0]));
   }
   break;
  case wait:
   wait(random(70, 350));
   break;
  case goDownToLevelOne:
   RSObject rock = getNearestObjectByID(rockID);

   if (rock != null) {
    if (tileOnScreen(rock.getLocation())) {
     if (isIdle()) {
      atObject(rock, "Down");
     }
    } else {
     if (tileOnMap(rock.getLocation())) {
      walkTileMM(rock.getLocation());
     }
    }
   } else {
    log.warning("Couldn't find portal rock entrance");
   }
   break;
  case goDownToLevelTwo:
   RSObject down1 = getStairs(1, "down");
   if (down1 != null) {
    if (tileOnScreen(down1.getLocation())) {
     if (isIdle()) {
      atObject(down1, "Down");
     }
    } else {
     if (tileOnMap(down1.getLocation())) {
      walkTileMM(down1.getLocation());
     }
    }
   } else {
    log.warning("Couldn't find level 1 stairs going down");
   }
   break;
  case goDownToLevelThree:
   RSObject down2 = getStairs(2, "down");
   
   if (down2 != null) {
    if (tileOnScreen(down2.getLocation())) {
     if (isIdle()) {
      atObject(down2, "down");
     }
    } else {
     if (tileOnMap(down2.getLocation())) {
      walkTileMM(down2.getLocation());
     }
    }
   } else {
    log.warning("Couldn't find level 2 stairs going down");
   }
   break;
  case goToSurface:
   RSObject up1 = getStairs(1, "up");
   
   if (up1 != null) {
    if (tileOnScreen(up1.getLocation())) {
     if (isIdle()) {
      atObject(up1, "up");
     }
    } else {
     if (tileOnMap(up1.getLocation())) {
      walkTileMM(up1.getLocation());
     }
    }
   } else {
    log.warning("Couldn't find level 1 stairs going up");
   }
   break;
  case goUpToLevelOne:
   RSObject up2 = getStairs(2, "up");
   
   if (up2 != null) {
    if (tileOnScreen(up2.getLocation())) {
     if (isIdle()) {
      atObject(up2, "up");
     }
    } else {
     if (tileOnMap(up2.getLocation())) {
      walkTileMM(up2.getLocation());
     }
    }
   } else {
    log.warning("Couldn't find level 2 stairs going up");
   }
   break;
  case goUpToLevelTwo:
   RSObject up3 = getStairs(3, "Up");
   
   if (up3 != null) {
    if (tileOnScreen(up3.getLocation())) {
     if (isIdle()) {
      atObject(up3, "up");
     }
    } else {
     if (tileOnMap(up3.getLocation())) {
      walkTileMM(up3.getLocation());
     }
    }
   } else {
    log.warning("Couldn't find level 1 stairs going up");
   }
   break;
  case walkToCook:
   if(isIdle()){
    try{
     if(atFish()){
     Walk(fishToFire);
     }
    }catch(Exception e){
     log.warning("Failed going to cook, generating another path");
     Walk(generateFixedPath(fishToFire[fishToFire.length -1]));
    }
   }
   break;
  case walkToEntrance:
   RSObject rock1 = getNearestObjectByID(rockID);
   
   if(isIdle()){
    Walk(generateFixedPath(rock1.getLocation()));
   }
   break;
  case walkToFish:
   RSNPC fishies = getNearestNPCByID(fishSpotID);
   
   if(isIdle()){
    Walk(generateFixedPath(fishies.getLocation()));
   }
   break;
  case logout:
   logout();
   break;
  }
  return random(200, 350);
 }

 private String fishStyle() {
  String style = "";
  if (inventoryContains(fishRodID)) {
   if (inventoryContains(baitID)) {
    style = "Bait";
   } else {
    log.warning("!!NO BAIT!!");
   }
  } else {
   if (inventoryContains(flyFishRodID)) {
    if (inventoryContains(featherID)) {
     style = "Fly";
    } else {
     log.warning("!!NO FEATHERS!!");
    }
   }
  }
  return style;

 }

 private final RenderingHints rh = new RenderingHints(
   RenderingHints.KEY_TEXT_ANTIALIASING,
   RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

 public void onRepaint(Graphics g) {
  if (isLoggedIn()) {

   long fishGained = skills.getCurrentSkillExp(STAT_FISHING)
     - startFish;
   long combatGained = skills.getCurrentSkillExp(STAT_ATTACK)
     + skills.getCurrentSkillExp(STAT_DEFENSE)
     + skills.getCurrentSkillExp(STAT_STRENGTH)
     + skills.getCurrentSkillExp(STAT_HITPOINTS) - startCombat;
   long cookGained = skills.getCurrentSkillExp(STAT_COOKING)
     - startCook;
   log("Script started. It hasn't been tested yet!");

   long millis = System.currentTimeMillis() - startTime;
   long hours = millis / (1000 * 60 * 60);
   millis -= hours * (1000 * 60 * 60);
   long minutes = millis / (1000 * 60);
   millis -= minutes * (1000 * 60);
   long seconds = millis / 1000;

   long totalSeconds = ((System.currentTimeMillis() - startTime) / 1000);
   // This paint was made using Enfilade's Paint Maker
   ((Graphics2D) g).setRenderingHints(rh);
   g.setColor(new Color(204, 204, 255, 147));
   g.fillRoundRect(547, 205, 187, 260, 10, 10);
   g.setFont(new Font("Chiller", 0, 50));
   g.setColor(new Color(0, 0, 0, 100));
   g.drawString("SpiderSTRNGHold", 575, 248);
   g.setColor(new Color(255, 0, 102, 143));
   g.drawString("SpiderSTRNGHold", 572, 251);
   g.setFont(new Font("Corbel", 0, 14));
   g.setColor(new Color(0, 0, 0, 114));
   g.drawString("Idea by: happyguy3216", 594, 459);
   g.setFont(new Font("Disney Print", 0, 18));
   g.setColor(new Color(255, 153, 153, 139));
   g.drawString("Run time:", 554, 283);
   g.setFont(new Font("Disney Print", 0, 18));
   g.setColor(new Color(204, 255, 204, 167));
   g.drawString(".:Experience Gained:.", 576, 300);
   g.setFont(new Font("Disney Print", 0, 18));
   g.setColor(new Color(255, 204, 204, 145));
   g.drawString("Combat:", 554, 322);
   g.setFont(new Font("Disney Print", 0, 18));
   g.setColor(new Color(255, 204, 204, 145));
   g.drawString("Fishing:", 554, 342);
   g.setFont(new Font("Disney Print", 0, 18));
   g.setColor(new Color(255, 204, 204, 145));
   g.drawString("Cooking:", 554, 361);
   g.setFont(new Font("Disney Print", 0, 18));
   g.setColor(new Color(204, 255, 204, 177));
   g.drawString(".:Levels Gained:.", 593, 380);
   g.setFont(new Font("Disney Print", 0, 18));
   g.setColor(new Color(255, 204, 204, 147));
   g.drawString("Combat:", 553, 402);
   g.setFont(new Font("Disney Print", 0, 18));
   g.setColor(new Color(255, 204, 204, 147));
   g.drawString("Fishing:", 638, 403);
   g.setFont(new Font("Disney Print", 0, 18));
   g.setColor(new Color(255, 204, 204, 147));
   g.drawString("Cooking:", 553, 420);
   g.setFont(new Font("FFVortex", 0, 25));
   g.setColor(new Color(255, 153, 51, 189));
   g.drawString(status, 553, 444);
   g.setFont(new Font("Kristen ITC", 0, 16));
   g.setColor(new Color(0, 0, 0, 117));
   g.drawString(hours + ":" + minutes + ":" + seconds, 616, 283);
   g.setFont(new Font("Kristen ITC", 0, 16));
   g.setColor(new Color(0, 0, 0, 117));
   g.drawString(Long.toString(combatGained), 606, 323);
   g.setFont(new Font("Kristen ITC", 0, 16));
   g.setColor(new Color(0, 0, 0, 117));
   g.drawString(Long.toString(fishGained), 607, 344);
   g.setFont(new Font("Kristen ITC", 0, 16));
   g.setColor(new Color(0, 0, 0, 117));
   g.drawString(Long.toString(cookGained), 607, 362);
   g.setFont(new Font("Kristen ITC", 0, 16));
   g.setColor(new Color(0, 0, 0, 117));
   g.drawString(Integer.toString(combatLevelsGained), 605, 402);
   g.setFont(new Font("Kristen ITC", 0, 16));
   g.setColor(new Color(0, 0, 0, 117));
   g.drawString(Integer.toString(fishLevelsGained), 689, 404);
   g.setFont(new Font("Kristen ITC", 0, 16));
   g.setColor(new Color(0, 0, 0, 117));
   g.drawString(Integer.toString(cookLevelsGained), 607, 421);
   g.setColor(new Color(255, 0, 51));
   g.drawRoundRect(547, 204, 186, 261, 10, 10);

  }
 }

 private boolean isWithinBounds(Point p, int x, int y, int w, int h) {
  if (p.x > x && p.x < x + w && p.y > y && p.y < y + h)
   return true;
  else
   return false;
 }
}

 

Revise this Paste

Your Name: Code Language: