Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** TekksCrabs.java 1.9
- * Kills the eastern rock crabs.
- * Have fun and report bugs to me as this is my first script.
- */
- import java.awt.*;
- import java.util.*;
- import com.speljohan.rsbot.script.*;
- import com.speljohan.rsbot.bot.*;
- import com.speljohan.rsbot.script.wrappers.*;
- import com.speljohan.rsbot.event.listeners.*;
- import com.speljohan.rsbot.script.ScriptManifest;
- @ScriptManifest (authors = { "Tekk" },
- category = "Combat",
- name = "TekksCrabs",
- version = 1.9,
- description = "<i><b>TekksCrabs v1.9</b> By Tekk</i><br /><br /><b>Start at the eastern crabs. </b><br /><input type='radio' name='stat' value='att'> Attack<br /><input type='radio' name='stat' value='str'> Strength<br /><input type='radio' name='stat' value='def'> Defence<br /><input type='radio' name='stat' value='range'> Ranged<br /><br />Food ID: <input type='text' name='foodid' value=''><br /><br />HP To Eat At: <input type='text' name='eatat' value=''><br /><br />Arrow Pickup ID: <input type='text' name='pickupid' value=''><br /><br />Arrow Name: <input type='text' name='pickupname' value = ''><br /><i>Note: Capitalization counts in the 'Arrow Name' field. For example, 'bronze arrow' will not work but 'Bronze arrow' will.</i>")
- public class TekksCrabs extends Script implements PaintListener {
- RSTile[] northToSouth = new RSTile[] { new RSTile(2707, 3717), new RSTile(2708, 3708),
- new RSTile(2706, 3697), new RSTile(2705, 3690), new RSTile(2706, 3685) };
- RSTile[] southToNorth = reversePath(northToSouth);
- private int expStart;
- private int hitpointsExpStart;
- private int statBeingTrained;
- private int pickupID;
- private String pickupName;
- private int eatAtHP = random(18,23);
- private int foodID;
- private boolean eating;
- @SuppressWarnings("deprecation")
- public boolean onStart(Map<String, String> args) {
- Bot.getEventManager().addListener(PaintListener.class, this);
- if(args.get("stat").equals("range")) {
- statBeingTrained = Constants.STAT_RANGE;
- }
- if(args.get("stat").equals("att")) {
- statBeingTrained = Constants.STAT_ATTACK;
- }
- if(args.get("stat").equals("str")) {
- statBeingTrained = Constants.STAT_STRENGTH;
- }
- if(args.get("stat").equals("def")) {
- statBeingTrained = Constants.STAT_DEFENSE;
- }
- if(!args.get("foodid").equals("")) {
- eating = true;
- try {
- foodID = Integer.parseInt(args.get("foodid"));
- } catch (NumberFormatException e) {
- log("Enter food as an ID, not name!");
- stopAllScripts();
- }
- }
- if(!args.get("pickupid").equals("")) {
- try {
- pickupID = Integer.parseInt(args.get("pickupid"));
- } catch (NumberFormatException e) {
- log("Enter arrow pickup item as an ID, not name!");
- stopAllScripts();
- }
- }
- if(!args.get("pickupname").equals("")) pickupName = args.get("pickupname");
- if(!args.get("eatat").equals("")) {
- try {
- eatAtHP = Integer.parseInt(args.get("eatat"));
- } catch (NumberFormatException e) {
- log("You entered the Eat At HP wrong.");
- stopAllScripts();
- }
- }
- expStart = skills.getCurrentSkillExp(statBeingTrained);
- hitpointsExpStart = skills.getCurrentSkillExp(Constants.STAT_HITPOINTS);
- return true;
- }
- public void onFinish(){
- Bot.getEventManager().removeListener(PaintListener.class, this);
- return;
- }
- public int loop() {
- if(isFightingCrab()) {
- return random(500,700);
- }
- if(walkingToCrab()) {
- return random(500,700);
- }
- if(needToWalkSouth()) {
- walkSouth();
- return random(2000,4000);
- }
- if(needToWalkNorth()) {
- walkNorth();
- return random(2000,4000);
- }
- if(needToPickUpItems()) {
- pickUpItems();
- return random(500,700);
- }
- if(eating) {
- eatFood();
- }
- // we're not doing anything
- findAndAttackCrabs();
- return random(500,700);
- }
- private boolean needToPickUpItems() {
- RSItemTile itemToPickUp = getGroundItemByID(3, pickupID);
- if(getMyPlayer().getLocation().getY() >= 3710) {
- if(itemToPickUp != null) {
- return true;
- }
- }
- return false;
- }
- private void pickUpItems() {
- RSItemTile itemToPickUp = getGroundItemByID(3, pickupID);
- atTile(itemToPickUp, pickupName);
- wait(random(500,700));
- if(inventoryContains(pickupID)) atInventoryItem(pickupID, "Wield");
- return;
- }
- private void eatFood() {
- int currentHP = skills.getCurrentSkillLevel(STAT_HITPOINTS);
- if(currentHP <= eatAtHP) {
- if(inventoryContains(foodID)) {
- atInventoryItem(foodID, "Eat");
- wait(random(700,900));
- return;
- } else {
- log("No food and we are almost dead, stopping script.");
- walkSouth();
- stopAllScripts();
- }
- }
- return;
- }
- private void walkNorth() {
- for(int i = 0; i<southToNorth.length; i++) {
- while(distanceTo(southToNorth[i]) > 5){
- walkTileMM(southToNorth[i]);
- moveMouseSlightly();
- wait(random(300,600));
- }
- }
- return;
- }
- private boolean needToWalkNorth() {
- if(getMyPlayer().getLocation().getY() < 3710) {
- return true;
- }
- return false;
- }
- private void walkSouth() {
- for(int i = 0; i<northToSouth.length; i++) {
- while(distanceTo(northToSouth[i]) > 5){
- walkTileMM(northToSouth[i]);
- moveMouseSlightly();
- wait(random(300,600));
- }
- }
- return;
- }
- private boolean needToWalkSouth() {
- if(getNearestNPCByID(1266,1268) != null) {
- if(distanceTo(getNearestNPCByID(1266, 1268)) == 0 && !getMyPlayer().isInCombat()) {
- return true;
- }
- }
- return false;
- }
- private void findAndAttackCrabs() {
- RSNPC newCrab = getNearestFreeNPCByID(1266, 1268);
- if(newCrab != null && newCrab.getLocation().getX() > 2691 && !getMyPlayer().isInCombat() && getMyPlayer().getAnimation() == -1) {
- RSTile crabLocation = newCrab.getLocation();
- if(getEnergy() > random(20,25) && isRunning() == false) {
- setRun(true);
- }
- walkTileMM(crabLocation);
- moveMouseSlightly();
- }
- return;
- }
- private boolean walkingToCrab() {
- if(getMyPlayer().isMoving()) {
- return true;
- }
- return false;
- }
- private boolean isFightingCrab() {
- if(getMyPlayer().isInCombat()) {
- return true;
- }
- return false;
- }
- @Override
- public void onRepaint(Graphics render) {
- if(isLoggedIn()) {
- render.setColor(Color.gray);
- render.fill3DRect(12, 250, 175, 75, true);
- render.setColor(Color.white);
- render.drawString("TekksCrabs v1.9", 17, 265);
- render.drawString("XP gained: " + (skills.getCurrentSkillExp(statBeingTrained) - expStart), 17, 280);
- render.drawString("XP to level " + (skills.getCurrentSkillLevel(statBeingTrained) + 1) + " : " + skills.getXPToNextLevel(statBeingTrained), 17, 295);
- render.drawString("Hitpoints XP gained: " + (skills.getCurrentSkillExp(STAT_HITPOINTS) - hitpointsExpStart), 17, 310);
- }
- }
- }
Add Comment
Please, Sign In to add comment