Guest User

hb_bar.bcs

a guest
Dec 2nd, 2011
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.37 KB | None | 0 0
  1. import com.mythicscape.batclient.interfaces.*;
  2. import java.util.regex.*;
  3. SCRIPT_NAME = "hb_bar";
  4.  
  5. //
  6. // This is a small script that takes the dunk_dunks and displays them in a small bar (extra window)
  7. // If you encounter any problems or got idea on how to improve this script, please drop me(Tugmeno) a tell
  8. //
  9. // Update: Version 1.1 or so, now the hb_bar also displays how many dunks you had since your last tick (up to a max of 40)
  10. // So if you are casting prots and the hb_bar displays a 8 or even a 9, swap to wis!
  11.  
  12.  
  13.  
  14. public static BatWindow win;
  15.  
  16. //Change the Colours here, if you don't like them R/G/B
  17. public static final Color cb = new Color(0,0,255); //border
  18. public static final Color c1 = new Color(0,255,0); //more than 2 sec untill dunk
  19. public static final Color c2 = new Color(255,0,0); //more than 1 sec untill dunk
  20. public static final Color c3 = new Color(100,100,0); // less than 1 sec untill dunk
  21. public static final Color c4 = new Color(255,255,255); // dunks since tick colour
  22.  
  23. // You will need to change the line starting with Pattern p_sc here so it matchs your sc, the following example works for
  24. // Hp: {colorhp}/<maxhp> [{diffhp}] Sp: {colorsp}/<maxsp> [{diffsp}] Ep: {colorep}/<maxep> [{diffep}]
  25. Pattern p_sc = Pattern.compile("^Hp: (-?[0-9]+)/([0-9]+) \\[([-+]?[0-9]*)\\] Sp: (-?[0-9]+)/(-?[0-9]+) \\[([-+]?[0-9]*)\\] Ep: (-?[0-9]+)/(-?[0-9]+) \\[([-+]?[0-9]*)\\]");
  26. Pattern p_aw = Pattern.compile("^(You awaken from your short rest, and feel slightly better)|(You feel like [A-Z][a-z]+ healed you a bit.)");
  27.  
  28. Boolean faketick = false;
  29.  
  30. //If you close the window by accident just type "$hb_bar" to make it visible again
  31. void run(){
  32.     win.setVisible(true);  
  33. }
  34. void bootup()
  35. {
  36.     win = clientGUI.createBatWindow("x",800,10,110,50); //if the window should appear at a different location change the 800 & 10
  37.     win.removeTabAt(0);
  38.    
  39.     bp = new DunkPanel();
  40.     win.newTab("x", bp);
  41.    
  42.    new Thread(bp).start();
  43.    
  44.    win.setVisible(true);
  45.    
  46.    triggerManager.newTrigger(SCRIPT_NAME + "dunk_dunk",
  47.         "^Dunk dunk$",
  48.      "$" + SCRIPT_NAME + ".dunk",
  49.         true, // replace true with false if you want to see the dunk dunks anyway
  50.     false, false,
  51.         null, Font.PLAIN);
  52. }
  53. public ParsedResult trigger() {
  54.     ParsedResult result = argument;
  55.     String raw = result.getStrippedText();
  56.     Matcher m_sc = p_sc.matcher(raw);
  57.     if(m_sc.find())
  58.     {
  59.     int hp,hpmax,hpdif;
  60.     int sp,spmax,spdif;
  61.     int ep,epmax,epdif;
  62.     hp = Integer.parseInt(m_sc.group(1));
  63.     hpmax = Integer.parseInt(m_sc.group(2));
  64.    
  65.     String temp = m_sc.group(3);
  66.     if(temp.equals(""))
  67.     hpdif = 0;
  68.     else if(temp.charAt(0) == '+')
  69.     hpdif = Integer.parseInt(temp.substring(1));
  70.     else
  71.     hpdif = Integer.parseInt(temp);
  72.    
  73.     sp = Integer.parseInt(m_sc.group(4));
  74.     spmax = Integer.parseInt(m_sc.group(5));
  75.    
  76.     temp = m_sc.group(6);
  77.     if(temp.equals(""))
  78.     spdif = 0;
  79.     else if(temp.charAt(0) == '+')
  80.     spdif = Integer.parseInt(temp.substring(1));
  81.     else
  82.     spdif = Integer.parseInt(temp);
  83.    
  84.     ep = Integer.parseInt(m_sc.group(7));
  85.     epmax = Integer.parseInt(m_sc.group(8));
  86.    
  87.     temp = m_sc.group(9);
  88.     if(temp.equals(""))
  89.     epdif = 0;
  90.     else if(temp.charAt(0) == '+')
  91.     epdif = Integer.parseInt(temp.substring(1));
  92.     else
  93.     epdif = Integer.parseInt(temp);
  94.    
  95.     //decomment to get some sc debug message to debug your regexp
  96.    //
  97.    //clientGUI.printText("generic","SC DEBUG: "
  98.     //  + " hp " + hp + "/" + hpmax + "/" + hpdif
  99.     //  + " sp " + sp + "/" + spmax + "/" + spdif
  100.     //  + " ep " + ep + "/" + epmax + "/" + epdif + "\n");
  101.    
  102.    
  103.    //Is our sc update really a tick? This was the best I could come up with:
  104.    if( ((hp >= hpmax && hpdif == 0)||(hp < hpmax && hpdif>0)) // If we can tick something
  105.      && ((sp >= spmax && spdif == 0)||(sp < spmax && spdif>0)) //   in a real tick we will tick
  106.      && ((ep >= epmax && epdif == 0)||(ep < epmax && epdif>0)) //   it
  107.      && (Math.max(Math.max(hpdif,spdif),epdif) > 25 ) // treshhold against campfire & crystal and spheres
  108.      && !faketick ) // camping or heal alls
  109.    {
  110.     //Another debug output message, this time it is for debugging the real tick detection
  111.    //clientGUI.printText("generic","Real tick!\n");
  112.     bp.tick();
  113.     }
  114.     faketick = false;
  115.     } else {
  116.     Matcher m_aw = p_aw.matcher(raw);
  117.     if(m_aw.find())
  118.     {
  119.     faketick = true;
  120.     }
  121.    
  122.     }
  123.    
  124.     return result;
  125. }
  126.  
  127. void dunk()
  128. {
  129. bp.dunk();
  130. }
  131.  
  132.  
  133.  
  134. public class DunkPanel extends BatPanel implements Runnable {
  135.     int x = 0;// If anyone could explain me why changing this to private makes paint bug around drop me a tell 
  136.      int dunks = 0;
  137.        public dunk()
  138.        {
  139.           x = 3000;
  140.          dunks++;
  141.         }
  142.         public void tick()
  143.        {
  144.        dunks = 0;
  145.        }  
  146.        public void run()
  147.        {
  148.           while(true)
  149.           {
  150.           Thread.sleep(70); // the lower the value here
  151.           x -= 70;          // the faster it updates the bar
  152.           x = (x<0)?0:x;
  153.          repaint();
  154.           }
  155.        }  
  156.  
  157.        public DunkPanel()
  158.        {
  159.            super();
  160.       }
  161.       public void paint(Graphics g) {
  162.         super.paint(g);
  163.             g.setColor(cb);
  164.             g.drawRect(0,0,100,20);
  165.        
  166.       int d = new Double(x/3000.0 * 100.0).intValue();
  167.       if(d >= 66)
  168.          g.setColor(c1);
  169.       else if(d >= 33)
  170.          g.setColor(c2);
  171.       else
  172.          g.setColor(c3);
  173.      
  174.         g.fillRect(0,0,d,20);
  175.       if(dunks < 40)
  176.       {
  177.       g.setColor(c4);
  178.       g.drawString("" + dunks,80,15);
  179.       }
  180.       }
  181.    }
  182.  
  183. public static DunkPanel bp;
  184.  
  185.  
Advertisement
Add Comment
Please, Sign In to add comment