Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.scripts; //You will ALWAYS need this
- import com.kbot2.scriptable.Script;
- import com.kbot2.scriptable.methods.wrappers.*;
- import com.kbot2.scriptable.methods.input.*;
- import com.kbot2.scriptable.methods.data.*;
- import com.kbot2.scriptable.methods.data.Camera.*;
- import com.kbot2.handlers.eventSystem.eventListeners.PaintListener;
- import java.awt.*;
- public class GoblinTrainer extends Script implements PaintListener {
- public boolean active() { //if active() is true, then the script can run.
- return true;
- }
- public String getName() {
- return "GoblinTrainer";
- }
- public String getAuthor() {
- return "Wakka";
- }
- public String getDescription() {
- return "Trains your beginner character so you don't have to!" +
- "Begin at Lumbridge, at the courtyard and it'll deathwalk.";
- }
- //misx
- int state = 1;
- int fight = 1;
- long startTime;
- //walk path
- public Tile[] toGoblins = new Tile [] { new Tile(3229, 3218), new Tile(3241, 3226), new Tile(3251, 3226) };
- public static final int[] doorClosed = new int[] { 1530 };
- @Override
- public boolean onStart() {
- startTime = System.currentTimeMillis();
- return true;
- }
- public int loop() {
- if (getMyPlayer().isInCombat() || getMyPlayer().isMoving()) {
- return random(900, 1200);
- }
- switch (state) {
- case 1:
- //wieldItems();
- case 2:
- walkToGoblin();
- case 3:
- fightGoblin();
- }
- return random(500, 800);
- }
- void walkToGoblin() {
- if (distanceTo(toGoblins[0]) <18) {
- walking.setRunning(true);
- walking.walkPath(walking.randomizePath(toGoblins, 2, 2));
- }
- }
- public int fightGoblin() {
- if (!getMyPlayer().isInCombat()) {
- NPC goblin = getClosestFree(40, "Goblin");
- if (goblin == null) {
- return random(300, 600);
- }
- if (goblin != null && !goblin.isInCombat()) {
- goblin.doAction("Attack");
- sleep(200, 3000);
- }
- if(getMyPlayer().isInCombat()) {
- //antiBan();
- sleep(500, 1000);
- }
- sleep(1200, 1500);
- }
- return random(800, 1200);
- }
- void onServerMessage(String s) {
- if (s.contains("I can't reach that!")) {
- Obj door = getClosestObject(15, 1530);
- camera.setCompass('n');
- if (door != null) {
- door.doActionAtDoor('n', "Open");
- }
- }
- }
- public void onRepaint (Graphics g) {
- long runTime = System.currentTimeMillis() - startTime;
- int secs = ((int) ((runTime / 1000) % 60));
- int mins = ((int) (((runTime / 1000) / 60) % 60));
- int hours = ((int) ((((runTime / 1000) / 60) / 60) % 60));
- g.setColor(new Color(61, 61, 61, 200));
- g.setColor(Color.white);
- g.drawString("Run time: " + (hours < 10 ? "0" : "") + hours + ":"
- + (mins < 10 ? "0" : "") + mins + ":" + (secs < 10 ? "0" : "")
- + secs, 34, 61);
- }
- public NPC getClosestFree(int range, String... names) {
- Tile myLoc = players.getMyPlayer().getLocation();
- double closestDist = 256;
- NPC[] allNPCs = npcs.getNPCs();
- NPC closestNPC = null;
- try {
- mainLoop:
- for (NPC tempNPC : allNPCs) {
- for (String s : names) {
- if (tempNPC.isInCombat())
- continue;
- int tempDist = tempNPC.getLocation().distanceTo(myLoc);
- if (tempNPC.getName().equalsIgnoreCase(s) && tempDist <= range && tempDist < closestDist) {
- closestNPC = tempNPC;
- closestDist = tempDist;
- continue mainLoop;
- }
- }
- }
- } catch (Exception betterSafeThanSorry) {
- return closestNPC;
- }
- return closestNPC;
- }
- }
Add Comment
Please, Sign In to add comment