Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 10.59 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Point;
  6. import java.awt.RenderingHints;
  7. import java.awt.event.KeyEvent;
  8. import java.util.Map;
  9.  
  10. import org.rsbot.bot.Bot;
  11. import org.rsbot.event.events.ServerMessageEvent;
  12. import org.rsbot.event.listeners.PaintListener;
  13. import org.rsbot.event.listeners.ServerMessageListener;
  14. import org.rsbot.script.Script;
  15. import org.rsbot.script.ScriptManifest;
  16. import org.rsbot.script.wrappers.RSNPC;
  17. import org.rsbot.script.wrappers.RSPlayer;
  18. import org.rsbot.script.wrappers.RSTile;
  19.  
  20. @ScriptManifest( authors = {"TwistedMind"}, category = "Combat", version = 1.1, name = "TnT Combat", description = "Too lazy to make a proper description, will do this later!")
  21. public class TnTCombat extends Script implements PaintListener, ServerMessageListener{
  22.     public Thread t;
  23.     public MultiThreadAntibanTnTCombat antiban;
  24.     public long startTime;
  25.     public RSTile beastTile = new RSTile(3248,3242);
  26.     public RSNPC beast;
  27.     public int dieCount = 0;
  28.     public int levelCount = 0;
  29.     public int combatLevelsGained = 0;
  30.     public boolean firstRun = true, clickContinue;
  31.     public int startXp;
  32.     public String[] beastNames = {"Goblin", "Giant spider"};
  33.    
  34.     public enum State {
  35.         Wait,
  36.         Antiban,
  37.         Walk,
  38.         Attack,
  39.         Walk_to_beast
  40.     }
  41.    
  42.     public State getStatus(){
  43.         if(getMyPlayer().getInteracting() != null){
  44.         return State.Antiban;
  45.         }
  46.         if(distanceTo(beastTile)>= random(20,25)){
  47.             return State.Walk;
  48.         }else{
  49.             beast = getNearestFreeNPCToAttackByName(beastNames);
  50.             if(beast == null){
  51.                 return State.Antiban;
  52.             }else{
  53.                 if(tileOnScreen(beast.getLocation())){
  54.                     return State.Attack;
  55.                 }else{
  56.                     return State.Walk_to_beast;
  57.                 }
  58.             }
  59.         }
  60.     }
  61.    
  62.     @Override
  63.     protected int getMouseSpeed(){
  64.         return random(7,11);
  65.     }
  66.    
  67.     public void runCheck(){
  68.         if(getEnergy() > random(70,80)){
  69.             setRun(true);
  70.             wait(random(1000,1200));
  71.         }
  72.     }
  73.  
  74.     @Override
  75.     public int loop() {
  76.         try{
  77.             if(!t.isAlive()){
  78.                 t.start();
  79.                 log("Multi-threaded Antiban initialized, have a safe botting experience :) ~ TwistedMind");
  80.             }
  81.             if(firstRun){
  82.                 startXp = skills.getCurrentSkillExp(STAT_ATTACK) + skills.getCurrentSkillExp(STAT_STRENGTH) + skills.getCurrentSkillExp(STAT_DEFENSE)+skills.getCurrentSkillExp(STAT_HITPOINTS);
  83.                 setCameraAltitude(true);
  84.                 firstRun = false;
  85.             }
  86.             runCheck();
  87.             getMouseSpeed();
  88.            
  89.             if(clickContinue){
  90.                 clickContinue();//Ensure the 'Advisor' message, beginners get is gone
  91.                 clickContinue = false;
  92.             }
  93.    
  94.             switch(getStatus()){
  95.             case Attack:
  96.                 atNPC(beast, "Attack");
  97.                 return random(1000,1500);
  98.             case Antiban:
  99.                 if(random(1,10) == 1){
  100.                     setCameraRotation(random(1,359));
  101.                 }
  102.                 //Move mouse:
  103.                 final int gamble = random(0, 10);
  104.                 if (gamble < 2) {
  105.                 moveMouse(random(7, 12), random(50, 500), random(100,
  106.                         500), 30);
  107.                 }
  108.                 //Right click other players
  109.                 final int chance2 = random(1,10);
  110.                 Point mousePosition;
  111.                 if(getMyPlayer().isInCombat() && chance2 == 1){
  112.                     mousePosition = getMouseLocation();
  113.                     RSPlayer player = getNearestPlayerByLevel(3, 126);
  114.                     if (player != null && distanceTo(player) != 0) {
  115.                         moveMouse(player.getScreenLocation(), 5, 5);
  116.                         wait(random(300, 700));
  117.                         clickMouse(false);
  118.                         wait(random(750, 1000));
  119.                         moveMouse(mousePosition, 15, 15);
  120.                     }
  121.                 }
  122.                 return random(1000,1500);
  123.             case Walk_to_beast:
  124.                 if(distanceTo(beast.getLocation())>= random(12,5)){
  125.                     walkPathMM(randomizePath(generateProperPath(beast.getLocation()),2,2));
  126.                 }else{
  127.                     walkTileOnScreen(beast.getLocation());
  128.                 }
  129.                 return random(1000,1500);
  130.             case Walk:
  131.                 walkPathMM(randomizePath(generateProperPath(beastTile),2,2));
  132.                 return random(1000,1500);
  133.             case Wait:
  134.                 break;
  135.             }
  136.             return 1;
  137.         }catch(java.lang.Throwable t){
  138.             return 1;
  139.         }
  140.     }
  141.    
  142.     public boolean onStart(Map <String, String> args){
  143.         startTime = System.currentTimeMillis();
  144.         antiban = new MultiThreadAntibanTnTCombat();
  145.         t = new Thread(antiban);
  146.         return true;
  147.     }
  148.  
  149.     @Override
  150.     public void onRepaint(Graphics g) {
  151.         try{
  152.             if(isLoggedIn()){
  153.             //---------Timer--------------------
  154.             long millis = System.currentTimeMillis() - startTime;
  155.             long hours = millis / (1000 * 60 * 60);
  156.             millis -= hours * 1000 * 60 * 60;
  157.             long minutes = millis / (1000 * 60);
  158.             millis -= minutes * 1000 * 60;
  159.             long seconds = millis / 1000;
  160.             //Ensure a high quality and Smooth paint :)
  161.             ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  162.             ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
  163.             ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
  164.             g.setColor(new Color(0,0,255,50));
  165.             g.fillRect(320,7,190,110);
  166.             g.setColor(Color.WHITE);
  167.             g.drawLine(365, 45, 510, 45);
  168.             g.drawRect(320,7,190,110);
  169.             g.setFont(new Font("Century Gothic", Font.BOLD, 16));
  170.             g.drawString("TnT Combat",365,30);
  171.             g.setFont(new Font("Microsoft Sans Serif", Font.PLAIN, 10));
  172.             g.drawString("Timer: " + hours + ":" + minutes + ":" + seconds, 330, 60);
  173.             g.drawString("Died " + dieCount + " times!", 330, 70);
  174.             g.drawString("Levels gained: " + levelCount, 330, 80);
  175.             g.drawString("Combat lvl's gained: "+ combatLevelsGained, 330,90);
  176.             g.drawString("Experience gained: " + ((skills.getCurrentSkillExp(STAT_ATTACK)+skills.getCurrentSkillExp(STAT_STRENGTH)+skills.getCurrentSkillExp(STAT_DEFENSE)+skills.getCurrentSkillExp(STAT_HITPOINTS)) - startXp),330,100);
  177.             final long totalSeconds = ((System.currentTimeMillis() - startTime) / 1000)+1;
  178.             final int expPerHour = (int) (((skills.getCurrentSkillExp(STAT_ATTACK)+skills.getCurrentSkillExp(STAT_STRENGTH)+skills.getCurrentSkillExp(STAT_DEFENSE)+skills.getCurrentSkillExp(STAT_HITPOINTS)) - startXp) * 3600 / totalSeconds);
  179.             g.drawString("Exp / Hour: " + expPerHour ,330, 110);
  180.            
  181.             g.setColor(Color.WHITE);
  182.             g.drawLine(320, 45, 510, 45);
  183.             g.setColor(Color.GRAY);
  184.             g.drawLine(321,44,509,44);
  185.             g.drawRect(321, 46, 188, 70);
  186.         }
  187.         }catch(java.lang.Throwable t){
  188.             t.printStackTrace();
  189.             log.severe("Paint error!");
  190.         }
  191.     }
  192.    
  193.     @Override
  194.     public void onFinish(){
  195.         antiban.stopThread = true;
  196.     }
  197.    
  198.     private class MultiThreadAntibanTnTCombat implements Runnable{
  199.             public boolean stopThread;
  200.            
  201.             @Override
  202.             public void run() {
  203.                 while(!stopThread){
  204.                     try {
  205.                         if (random(0, 10) == 0) {
  206.                                 final char[] LR = new char[] { KeyEvent.VK_LEFT,
  207.                                                 KeyEvent.VK_RIGHT };
  208.                                 final char[] UD = new char[] { KeyEvent.VK_DOWN,
  209.                                                 KeyEvent.VK_UP };
  210.                                 final char[] LRUD = new char[] { KeyEvent.VK_LEFT,
  211.                                                 KeyEvent.VK_RIGHT, KeyEvent.VK_UP,
  212.                                                 KeyEvent.VK_UP };
  213.                                 final int random1 = random(0, 2);
  214.                                 final int random2 = random(0, 2);
  215.                                 final int random4 = random(0, 4);
  216.  
  217.                                 if (random(0, 3) == 0) {
  218.                                         Bot.getInputManager().pressKey(LR[random1]);
  219.                                         Thread.sleep(random(100, 400));
  220.                                         Bot.getInputManager().pressKey(UD[random2]);
  221.                                         Thread.sleep(random(300, 600));
  222.                                         Bot.getInputManager().releaseKey(UD[random2]);
  223.                                         Thread.sleep(random(100, 400));
  224.                                         Bot.getInputManager().releaseKey(LR[random1]);
  225.                                 } else {
  226.                                         Bot.getInputManager().pressKey(LRUD[random4]);
  227.                                         if (random4 > 1) {
  228.                                                 Thread.sleep(random(300, 600));
  229.                                         } else {
  230.                                                 Thread.sleep(random(500, 900));
  231.                                         }
  232.                                         Bot.getInputManager().releaseKey(LRUD[random4]);
  233.                                 }
  234.                         } else {
  235.                                 Thread.sleep(random(200, 2000));
  236.                         }
  237.                 } catch (final Exception e) {
  238.                         e.printStackTrace();
  239.                 }
  240.                 }
  241.             }
  242.     }
  243.  
  244.     @Override
  245.     public void serverMessageRecieved(ServerMessageEvent e) {    
  246.         String message = e.getMessage();
  247.         if(message.contains("Oh dear")){
  248.             dieCount++;
  249.         }else if(message.contains("You've just advanced a")){
  250.             levelCount++;
  251.             clickContinue = true;
  252.         }else if(message.contains("Congratulations!")){
  253.             combatLevelsGained++;
  254.         }
  255.     }
  256. }