Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by [ ampzZ_ ] on 6/15/09
- //
- package com.scripts;
- import com.kbot2.handlers.eventSystem.eventListeners.PaintListener;
- import com.kbot2.handlers.eventSystem.eventListeners.ServerMessageListener;
- import com.kbot2.scriptable.Script;
- import com.kbot2.scriptable.methods.wrappers.*;
- import com.kbot2.scriptable.methods.data.Skills;
- import com.kbot2.scriptable.methods.data.GameScreen;
- import java.awt.*;
- import java.text.DecimalFormat;
- import java.util.logging.Logger;
- import java.awt.event.KeyEvent;
- public class ZanarisRingAlcher extends Script implements PaintListener, ServerMessageListener {
- //-------------------
- // Variables
- //-----------------------------
- int fails = 0;
- boolean runnable = true;
- String statusMsg = "";
- int ringsAlched = 0;
- int origExp = 0;
- int origLvl = 0;
- long startTime = 0;
- long lastAlch = 0;
- long antibanTimer = System.currentTimeMillis() + random(15000, 40000);
- //-------------------
- // Starting methods
- //------------------------------
- public boolean active() { return runnable; }
- public String getName() { return "Zanaris Ring Alcher"; }
- public String getAuthor() { return "ampzZ_"; }
- public double getVersion() { return 1.0; }
- public String getDescription() { return "Please refer to\nforum post."; }
- public String[] getTags() { return new String[]{"ampzz", "Magic", "Zanaris", "Alcher"}; }
- public boolean onStart() {
- camera.setAltitude(true);
- setMouseSpeed(1.5);
- origExp = skills.getExperience(Skills.SKILL_MAGIC);
- origLvl = skills.getLevel(Skills.SKILL_MAGIC);
- startTime = System.currentTimeMillis();
- return true;
- }
- //-------------------
- // Loop
- //------------------------------
- public int loop() {
- try {
- if(!(inventory.contains(561))) {
- log("No more nature runes - Stopping;");
- runnable = false;
- return 1;
- }
- if(fails > 15) {
- runnable = false;
- return 1;
- }
- if(getMyPlayer().getAnimation() != -1 || getMyPlayer().isMoving()) // 9633 = alch anim
- return 100;
- if(antibanTimer < System.currentTimeMillis())
- antiban();
- if(inventory.contains(1641) && !interfaces.interfaceGroupExists(620)) {
- if(gameScreen.getCurrentTab() != GameScreen.TAB_MAGIC)
- gameScreen.openTab(GameScreen.TAB_MAGIC);
- statusMsg = "Casting alch...";
- if(interfaces.getInterface(192, 34).isValid() && interfaces.getInterface(192, 34) != null) {
- interfaces.getInterface(192, 34).doClick();
- sleep(300, 500);
- if(inventory.atItem("Cast", 1641)) {
- statusMsg = "Alching...";
- ringsAlched++;
- lastAlch = System.currentTimeMillis()+5000;
- }
- return random(800, 1100);
- } else {
- if(gameScreen.getCurrentTab() != GameScreen.TAB_MAGIC) {
- log("Hmm... couldnt open magic tab?");
- gameScreen.openTab(GameScreen.TAB_MAGIC);
- fails++;
- }
- }
- } else {
- if(interfaces.interfaceGroupExists(620) && inventory.contains(1641)) {
- statusMsg = "Closing trade";
- if(interfaces.getInterface(620, 7) != null) {
- interfaces.getInterface(620, 7).doClick();
- return random(500, 800);
- }
- }
- if(interfaces.getInterface(620, 21) != null && interfaces.getInterface(620, 21).getTextColor() != 16750623) {
- interfaces.getInterface(620, 21).doClick();
- return 1;
- }
- if(interfaces.interfaceGroupExists(620) && !inventory.contains(1641)) {
- if(interfaces.getInterface(620, 23) != null) {
- statusMsg = "Buying rings";
- Interface tehInterface= interfaces.getInterface(620, 23);
- Point randomPoint = tehInterface.getChild(0).getRandomPointInside();
- clickMouse(randomPoint, false);
- sleep(100);
- /*atMenu("Buy 10");
- sleep(100);
- clickMouse(randomPoint, false);
- sleep(100);
- atMenu("Buy 10");
- sleep(100);
- clickMouse(randomPoint, false);
- sleep(100);
- atMenu("Buy 10");*/
- atMenu("X");
- sleep(1000, 1500);
- sendText("" + random(26, 99), true);
- sleep(500, 800);
- }
- if(interfaces.getInterface(620, 7) != null) {
- statusMsg = "Closing trade";
- interfaces.getInterface(620, 7).doClick();
- return random(500, 800);
- }
- } else {
- statusMsg = "Finding Irksol";
- NPC irksol = npcs.getClosest(10, 566);
- if(irksol == null) {
- irksol = npcs.getClosest(10, "Irksol");
- if(irksol == null) {
- log("Cant find Irksol.");
- stopAllScripts();
- } else {
- statusMsg = "Trading Irksol";
- irksol.doAction("Trade Irksol");
- sleep(500, 800);
- }
- } else {
- statusMsg = "Trading Irksol";
- irksol.doAction("Trade Irksol");
- sleep(500, 800);
- }
- }
- }
- return random(350, 500);
- } catch (Exception e) {
- return 100;
- }
- }
- //-------------------
- // Server messages
- //------------------------------
- public void onServerMessage(String m) {
- if(m.contains("have enough coins")) {
- log("Ran out of money somehow?");
- runnable = false;
- }
- }
- //-------------------
- // Paint
- //------------------------------
- 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));
- /* This is from z.Darkness as Im too lazy to do the logic */
- float xpsec = 0;
- if ((mins > 0 || hours > 0 || secs > 0) && (skills.getExperience(Skills.SKILL_MAGIC) - origExp) > 0) {
- xpsec = ((float) (skills.getExperience(Skills.SKILL_MAGIC) - origExp)) / (float) (secs + (mins * 60) + (hours * 60 * 60));
- }
- float xpmin = xpsec * 60;
- float xphours = xpmin * 60;
- int x = 43;
- int y = 43;
- DecimalFormat d = new DecimalFormat("#,#00");
- d.setMaximumFractionDigits(0);
- g.setFont(new Font("Lucida", Font.BOLD, 12));
- g.setColor(Color.WHITE);
- g.drawString(getName() + " " + getVersion() + " | Created By: " + getAuthor(), x-18, y);
- g.setFont(new Font("Lucida", Font.PLAIN, 12));
- y += 20;
- g.drawString("Status: " + statusMsg, x, y);
- y += 13;
- g.drawString("Run time: " + d.format(hours) + ":" + d.format(mins) + ":" + d.format(secs), x, y); // Yes alo, I took this from you :)
- y += 13;
- g.drawString("Rings Alched: " + ringsAlched, x, y);
- y += 13;
- g.drawString("Current level: " + skills.getLevel(Skills.SKILL_MAGIC), x, y);
- y += 13;
- g.drawString("Next level: " + (skills.getExperienceToNextLevel(Skills.SKILL_MAGIC)) + " experience", x, y);
- y += 13;
- g.drawString("Next level: " + ((ringsAlched == 0 || skills.getExperience(Skills.SKILL_MAGIC) - origExp == 0) ? 0 : (skills.getExperienceToNextLevel(Skills.SKILL_MAGIC)/((skills.getExperience(Skills.SKILL_MAGIC) - origExp)/ringsAlched))) + " rings", x, y);
- y += 13;
- g.drawString("Experience gained: " + (skills.getExperience(Skills.SKILL_MAGIC) - origExp), x, y);
- y += 13;
- g.drawString("Levels gained: " + (skills.getLevel(Skills.SKILL_MAGIC)-origLvl), x, y);
- y += 13;
- g.drawString("Projected XP/Hour: " + (int)xphours, x, y);
- y += 13;
- g.drawString("Projected Rings/Hour: " + (ringsAlched > 1 ? (int)xphours/((skills.getExperience(Skills.SKILL_MAGIC) - origExp)/ringsAlched) : 0), x, y);
- }
- /* Contributed from mehhh */
- public void randomtab() {
- int randomtabs = random(1, 15);
- int chance = random(1, 2);
- if (randomtabs == 2) {
- if (gameScreen.getCurrentTab() != GameScreen.TAB_CLAN) {
- log("mehhh Antiban: Opening clan tab.");
- gameScreen.openTab(GameScreen.TAB_CLAN);
- } else {
- if (chance == 1) {
- randomtab();
- }
- }
- }
- if (randomtabs == 4) {
- if (gameScreen.getCurrentTab() != GameScreen.TAB_FRIENDS) {
- log("mehhh Antiban: Opening friends tab.");
- gameScreen.openTab(GameScreen.TAB_FRIENDS);
- } else {
- if (chance == 1) {
- randomtab();
- }
- }
- }
- if (randomtabs == 5) {
- if (gameScreen.getCurrentTab() != GameScreen.TAB_IGNORE) {
- log("mehhh Antiban: Opening ignore tab.");
- gameScreen.openTab(GameScreen.TAB_IGNORE);
- } else {
- if (chance == 1) {
- randomtab();
- }
- }
- }
- if (randomtabs >= 13) {
- if (gameScreen.getCurrentTab() != GameScreen.TAB_INVENTORY) {
- log("mehhh Antiban: Opening inventory tab.");
- gameScreen.openTab(GameScreen.TAB_INVENTORY);
- } else {
- if (chance == 1) {
- randomtab();
- }
- }
- }
- if (randomtabs == 7) {
- if (gameScreen.getCurrentTab() != GameScreen.TAB_MAGIC) {
- log("mehhh Antiban: Opening magic tab.");
- gameScreen.openTab(GameScreen.TAB_MAGIC);
- } else {
- if (chance == 1) {
- randomtab();
- }
- }
- }
- if (randomtabs == 12) {
- if (gameScreen.getCurrentTab() != GameScreen.TAB_STATS) {
- log("mehhh Antiban: Opening stat tab.");
- gameScreen.openTab(GameScreen.TAB_STATS);
- } else {
- if (chance == 1) {
- randomtab();
- }
- }
- }
- }
- //converted from RSBot -- start
- public void turnCamera() {
- char[] LR = new char[] { KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT };
- char[] UD = new char[] { KeyEvent.VK_DOWN, KeyEvent.VK_UP };
- char[] LRUD = new char[] { KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT, KeyEvent.VK_UP, KeyEvent.VK_UP };
- int random2 = random(0,2);
- int random1 = random(0,2);
- int random4 = random(0,4);
- if(random(0,3) == 0) {
- botEnv.keyboard.pressKey(LR[random1]);
- try { Thread.sleep(random(100, 400)); } catch (Exception e) {}
- botEnv.keyboard.pressKey(UD[random2]);
- try { Thread.sleep(random(300, 600)); } catch (Exception e) {}
- botEnv.keyboard.releaseKey(UD[random2]);
- try { Thread.sleep(random(100, 400)); } catch (Exception e) {}
- botEnv.keyboard.releaseKey(LR[random1]);
- } else {
- botEnv.keyboard.pressKey(LRUD[random4]);
- if(random4>1) {
- try { Thread.sleep(random(300, 600)); } catch (Exception e) {}
- } else {
- try { Thread.sleep(random(500, 900)); } catch (Exception e) {}
- }
- botEnv.keyboard.releaseKey(LRUD[random4]);
- }
- }
- protected final Logger log = Logger.getLogger(this.getClass().getName());
- public boolean setCameraAltitude(final double altPercent) {
- final int alt = (int) (altPercent / 100 * -1237 - 1226);
- int curAlt = botEnv.getClient().getCameraZ();
- int lastAlt = 0;
- if (curAlt == alt) {
- log.info("Good: " + curAlt);
- return true;
- } else if (curAlt > alt) {
- botEnv.keyboard.pressKey((char) KeyEvent.VK_UP);
- long start = System.currentTimeMillis();
- while (curAlt > alt && System.currentTimeMillis() - start < 30) {
- if (lastAlt != curAlt) {
- start = System.currentTimeMillis();
- }
- lastAlt = curAlt;
- sleep(1);
- curAlt = botEnv.getClient().getCameraZ();
- }
- botEnv.keyboard.releaseKey((char) KeyEvent.VK_UP);
- return true;
- } else {
- botEnv.keyboard.pressKey((char) KeyEvent.VK_DOWN);
- long start = System.currentTimeMillis();
- while (curAlt < alt && System.currentTimeMillis() - start < 30) {
- if (lastAlt != curAlt) {
- start = System.currentTimeMillis();
- }
- lastAlt = curAlt;
- sleep(1);
- curAlt = botEnv.getClient().getCameraZ();
- }
- botEnv.keyboard.releaseKey((char) KeyEvent.VK_DOWN);
- return true;
- }
- }
- //end
- public void magic() {
- if (gameScreen.getCurrentTab() != GameScreen.TAB_STATS) {
- gameScreen.openTab(GameScreen.TAB_STATS);
- magic();
- } else {
- log("Checking magic stat.");
- moveMouse(new Point(577, 395), random(-15, 15), random(-5, 10));
- sleep(random(2000, 2500));
- }
- }
- public void antiban() {
- int r = random(0, 25);
- if(r == 0){
- gameScreen.openTab(GameScreen.TAB_INVENTORY);
- sleep(800, 1500);
- }
- if(r == 1) { // Open friends tab
- gameScreen.openTab(GameScreen.TAB_FRIENDS);
- sleep(800, 1500);
- }
- if(r == 2 && random(1, 5) == 2 && !getMyPlayer().isMoving()) { // Asks what magic level is
- Interface qChat = interfaces.getInterface(137, 52);
- if(qChat != null) {
- clickMouse(qChat.getRandomPointInside(), true);
- sleep(100);
- sendText("s", false);
- sleep(100);
- sendText("m", false);
- sleep(800, 1000);
- sendText("1", false);
- }
- }
- if(r == 3) { // Move mouse random position
- mouse.moveMouse(random(5, 420), random(5, 420));
- sleep(300, 700);
- }
- if(r == 4 && random(1, 3) == 2 && !getMyPlayer().isMoving()) { // Randomly click on players near - 1% chance of this :P
- if(players.getPlayers().length == 0)
- return;
- int randPlayer = random(0, players.getPlayers().length-1);
- Point onePoint = getCalculations().tileToScreen(players.getPlayers()[randPlayer].getLocation());
- clickMouse(onePoint, 1, 1, false);
- sleep(2000);
- atMenu("Cancel");
- }
- if(r == 5 && !getMyPlayer().isMoving()) { // Randomly examine objects
- Obj[] objectsAround = objects.getObjects(10);
- if(objectsAround.length == 0) // Shouldnt be 0;
- return;
- int randObjs = random(0, objectsAround.length-1);
- objectsAround[randObjs].doAction("Examine");
- }
- if(r == 5 || r == 6) { // Move camera up and down
- char k = (random(0, 1) == 0 ? (char)KeyEvent.VK_DOWN : (char)KeyEvent.VK_UP);
- keyboard.pressKey(k);
- sleep(random(10, 400));
- keyboard.releaseKey(k);
- }
- if(r == 7 || r == 8) { // Rotate camera
- camera.setAngle(camera.getAngle() + random(-90, 90));
- gameScreen.openTab(GameScreen.TAB_MAGIC);
- antibanTimer = System.currentTimeMillis() + random(15000, 40000);
- log("Doing antiban again in: " + ((antibanTimer-System.currentTimeMillis())/1000) + " seconds");
- }
- if (r == 9 || r == 10) {
- magic();
- }
- if (r == 11 || r == 12) {
- sleep(random(1000, 2000));
- }
- if (r == 13 || r == 14) {
- int randomcompass = random(1, 4);
- if (randomcompass == 1) {
- camera.setCompass('e');
- }
- if (randomcompass == 2) {
- camera.setCompass('w');
- }
- if (randomcompass == 3) {
- camera.setCompass('n');
- }
- if (randomcompass == 4) {
- camera.setCompass('s');
- }
- }
- if (r == 15 || r == 16) {
- sleep(random(2000, 3000));
- }
- if (r == 17 || r == 18) {
- setCameraAltitude(random(1, 100));
- }
- if (r == 19 || r == 20) {
- randomtab();
- }
- if (r >= 21 && r <= 25) {
- turnCamera();
- }
- }
- }
Add Comment
Please, Sign In to add comment