- 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.awt.event.KeyEvent;
- import java.util.Map;
- import org.rsbot.bot.Bot;
- import org.rsbot.event.events.ServerMessageEvent;
- import org.rsbot.event.listeners.PaintListener;
- import org.rsbot.event.listeners.ServerMessageListener;
- import org.rsbot.script.Script;
- import org.rsbot.script.ScriptManifest;
- import org.rsbot.script.wrappers.RSNPC;
- import org.rsbot.script.wrappers.RSPlayer;
- import org.rsbot.script.wrappers.RSTile;
- @ScriptManifest( authors = {"TwistedMind"}, category = "Combat", version = 1.1, name = "TnT Combat", description = "Too lazy to make a proper description, will do this later!")
- public class TnTCombat extends Script implements PaintListener, ServerMessageListener{
- public Thread t;
- public MultiThreadAntibanTnTCombat antiban;
- public long startTime;
- public RSTile beastTile = new RSTile(3248,3242);
- public RSNPC beast;
- public int dieCount = 0;
- public int levelCount = 0;
- public int combatLevelsGained = 0;
- public boolean firstRun = true, clickContinue;
- public int startXp;
- public String[] beastNames = {"Goblin", "Giant spider"};
- public enum State {
- Wait,
- Antiban,
- Walk,
- Attack,
- Walk_to_beast
- }
- public State getStatus(){
- if(getMyPlayer().getInteracting() != null){
- return State.Antiban;
- }
- if(distanceTo(beastTile)>= random(20,25)){
- return State.Walk;
- }else{
- beast = getNearestFreeNPCToAttackByName(beastNames);
- if(beast == null){
- return State.Antiban;
- }else{
- if(tileOnScreen(beast.getLocation())){
- return State.Attack;
- }else{
- return State.Walk_to_beast;
- }
- }
- }
- }
- @Override
- protected int getMouseSpeed(){
- return random(7,11);
- }
- public void runCheck(){
- if(getEnergy() > random(70,80)){
- setRun(true);
- wait(random(1000,1200));
- }
- }
- @Override
- public int loop() {
- try{
- if(!t.isAlive()){
- t.start();
- log("Multi-threaded Antiban initialized, have a safe botting experience :) ~ TwistedMind");
- }
- if(firstRun){
- startXp = skills.getCurrentSkillExp(STAT_ATTACK) + skills.getCurrentSkillExp(STAT_STRENGTH) + skills.getCurrentSkillExp(STAT_DEFENSE)+skills.getCurrentSkillExp(STAT_HITPOINTS);
- setCameraAltitude(true);
- firstRun = false;
- }
- runCheck();
- getMouseSpeed();
- if(clickContinue){
- clickContinue();//Ensure the 'Advisor' message, beginners get is gone
- clickContinue = false;
- }
- switch(getStatus()){
- case Attack:
- atNPC(beast, "Attack");
- return random(1000,1500);
- case Antiban:
- if(random(1,10) == 1){
- setCameraRotation(random(1,359));
- }
- //Move mouse:
- final int gamble = random(0, 10);
- if (gamble < 2) {
- moveMouse(random(7, 12), random(50, 500), random(100,
- 500), 30);
- }
- //Right click other players
- final int chance2 = random(1,10);
- Point mousePosition;
- if(getMyPlayer().isInCombat() && chance2 == 1){
- mousePosition = getMouseLocation();
- RSPlayer player = getNearestPlayerByLevel(3, 126);
- if (player != null && distanceTo(player) != 0) {
- moveMouse(player.getScreenLocation(), 5, 5);
- wait(random(300, 700));
- clickMouse(false);
- wait(random(750, 1000));
- moveMouse(mousePosition, 15, 15);
- }
- }
- return random(1000,1500);
- case Walk_to_beast:
- if(distanceTo(beast.getLocation())>= random(12,5)){
- walkPathMM(randomizePath(generateProperPath(beast.getLocation()),2,2));
- }else{
- walkTileOnScreen(beast.getLocation());
- }
- return random(1000,1500);
- case Walk:
- walkPathMM(randomizePath(generateProperPath(beastTile),2,2));
- return random(1000,1500);
- case Wait:
- break;
- }
- return 1;
- }catch(java.lang.Throwable t){
- return 1;
- }
- }
- public boolean onStart(Map <String, String> args){
- startTime = System.currentTimeMillis();
- antiban = new MultiThreadAntibanTnTCombat();
- t = new Thread(antiban);
- return true;
- }
- @Override
- public void onRepaint(Graphics g) {
- try{
- if(isLoggedIn()){
- //---------Timer--------------------
- 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;
- //Ensure a high quality and Smooth paint :)
- ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
- ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
- g.setColor(new Color(0,0,255,50));
- g.fillRect(320,7,190,110);
- g.setColor(Color.WHITE);
- g.drawLine(365, 45, 510, 45);
- g.drawRect(320,7,190,110);
- g.setFont(new Font("Century Gothic", Font.BOLD, 16));
- g.drawString("TnT Combat",365,30);
- g.setFont(new Font("Microsoft Sans Serif", Font.PLAIN, 10));
- g.drawString("Timer: " + hours + ":" + minutes + ":" + seconds, 330, 60);
- g.drawString("Died " + dieCount + " times!", 330, 70);
- g.drawString("Levels gained: " + levelCount, 330, 80);
- g.drawString("Combat lvl's gained: "+ combatLevelsGained, 330,90);
- g.drawString("Experience gained: " + ((skills.getCurrentSkillExp(STAT_ATTACK)+skills.getCurrentSkillExp(STAT_STRENGTH)+skills.getCurrentSkillExp(STAT_DEFENSE)+skills.getCurrentSkillExp(STAT_HITPOINTS)) - startXp),330,100);
- final long totalSeconds = ((System.currentTimeMillis() - startTime) / 1000)+1;
- final int expPerHour = (int) (((skills.getCurrentSkillExp(STAT_ATTACK)+skills.getCurrentSkillExp(STAT_STRENGTH)+skills.getCurrentSkillExp(STAT_DEFENSE)+skills.getCurrentSkillExp(STAT_HITPOINTS)) - startXp) * 3600 / totalSeconds);
- g.drawString("Exp / Hour: " + expPerHour ,330, 110);
- g.setColor(Color.WHITE);
- g.drawLine(320, 45, 510, 45);
- g.setColor(Color.GRAY);
- g.drawLine(321,44,509,44);
- g.drawRect(321, 46, 188, 70);
- }
- }catch(java.lang.Throwable t){
- t.printStackTrace();
- log.severe("Paint error!");
- }
- }
- @Override
- public void onFinish(){
- antiban.stopThread = true;
- }
- private class MultiThreadAntibanTnTCombat implements Runnable{
- public boolean stopThread;
- @Override
- public void run() {
- while(!stopThread){
- try {
- if (random(0, 10) == 0) {
- final char[] LR = new char[] { KeyEvent.VK_LEFT,
- KeyEvent.VK_RIGHT };
- final char[] UD = new char[] { KeyEvent.VK_DOWN,
- KeyEvent.VK_UP };
- final char[] LRUD = new char[] { KeyEvent.VK_LEFT,
- KeyEvent.VK_RIGHT, KeyEvent.VK_UP,
- KeyEvent.VK_UP };
- final int random1 = random(0, 2);
- final int random2 = random(0, 2);
- final int random4 = random(0, 4);
- if (random(0, 3) == 0) {
- Bot.getInputManager().pressKey(LR[random1]);
- Thread.sleep(random(100, 400));
- Bot.getInputManager().pressKey(UD[random2]);
- Thread.sleep(random(300, 600));
- Bot.getInputManager().releaseKey(UD[random2]);
- Thread.sleep(random(100, 400));
- Bot.getInputManager().releaseKey(LR[random1]);
- } else {
- Bot.getInputManager().pressKey(LRUD[random4]);
- if (random4 > 1) {
- Thread.sleep(random(300, 600));
- } else {
- Thread.sleep(random(500, 900));
- }
- Bot.getInputManager().releaseKey(LRUD[random4]);
- }
- } else {
- Thread.sleep(random(200, 2000));
- }
- } catch (final Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
- @Override
- public void serverMessageRecieved(ServerMessageEvent e) {
- String message = e.getMessage();
- if(message.contains("Oh dear")){
- dieCount++;
- }else if(message.contains("You've just advanced a")){
- levelCount++;
- clickContinue = true;
- }else if(message.contains("Congratulations!")){
- combatLevelsGained++;
- }
- }
- }