Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.mythicscape.batclient.interfaces.*;
- import java.util.regex.*;
- SCRIPT_NAME = "hb_bar";
- //
- // This is a small script that takes the dunk_dunks and displays them in a small bar (extra window)
- // If you encounter any problems or got idea on how to improve this script, please drop me(Tugmeno) a tell
- //
- // 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)
- // So if you are casting prots and the hb_bar displays a 8 or even a 9, swap to wis!
- public static BatWindow win;
- //Change the Colours here, if you don't like them R/G/B
- public static final Color cb = new Color(0,0,255); //border
- public static final Color c1 = new Color(0,255,0); //more than 2 sec untill dunk
- public static final Color c2 = new Color(255,0,0); //more than 1 sec untill dunk
- public static final Color c3 = new Color(100,100,0); // less than 1 sec untill dunk
- public static final Color c4 = new Color(255,255,255); // dunks since tick colour
- // You will need to change the line starting with Pattern p_sc here so it matchs your sc, the following example works for
- // Hp: {colorhp}/<maxhp> [{diffhp}] Sp: {colorsp}/<maxsp> [{diffsp}] Ep: {colorep}/<maxep> [{diffep}]
- 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]*)\\]");
- 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.)");
- Boolean faketick = false;
- //If you close the window by accident just type "$hb_bar" to make it visible again
- void run(){
- win.setVisible(true);
- }
- void bootup()
- {
- win = clientGUI.createBatWindow("x",800,10,110,50); //if the window should appear at a different location change the 800 & 10
- win.removeTabAt(0);
- bp = new DunkPanel();
- win.newTab("x", bp);
- new Thread(bp).start();
- win.setVisible(true);
- triggerManager.newTrigger(SCRIPT_NAME + "dunk_dunk",
- "^Dunk dunk$",
- "$" + SCRIPT_NAME + ".dunk",
- true, // replace true with false if you want to see the dunk dunks anyway
- false, false,
- null, Font.PLAIN);
- }
- public ParsedResult trigger() {
- ParsedResult result = argument;
- String raw = result.getStrippedText();
- Matcher m_sc = p_sc.matcher(raw);
- if(m_sc.find())
- {
- int hp,hpmax,hpdif;
- int sp,spmax,spdif;
- int ep,epmax,epdif;
- hp = Integer.parseInt(m_sc.group(1));
- hpmax = Integer.parseInt(m_sc.group(2));
- String temp = m_sc.group(3);
- if(temp.equals(""))
- hpdif = 0;
- else if(temp.charAt(0) == '+')
- hpdif = Integer.parseInt(temp.substring(1));
- else
- hpdif = Integer.parseInt(temp);
- sp = Integer.parseInt(m_sc.group(4));
- spmax = Integer.parseInt(m_sc.group(5));
- temp = m_sc.group(6);
- if(temp.equals(""))
- spdif = 0;
- else if(temp.charAt(0) == '+')
- spdif = Integer.parseInt(temp.substring(1));
- else
- spdif = Integer.parseInt(temp);
- ep = Integer.parseInt(m_sc.group(7));
- epmax = Integer.parseInt(m_sc.group(8));
- temp = m_sc.group(9);
- if(temp.equals(""))
- epdif = 0;
- else if(temp.charAt(0) == '+')
- epdif = Integer.parseInt(temp.substring(1));
- else
- epdif = Integer.parseInt(temp);
- //decomment to get some sc debug message to debug your regexp
- //
- //clientGUI.printText("generic","SC DEBUG: "
- // + " hp " + hp + "/" + hpmax + "/" + hpdif
- // + " sp " + sp + "/" + spmax + "/" + spdif
- // + " ep " + ep + "/" + epmax + "/" + epdif + "\n");
- //Is our sc update really a tick? This was the best I could come up with:
- if( ((hp >= hpmax && hpdif == 0)||(hp < hpmax && hpdif>0)) // If we can tick something
- && ((sp >= spmax && spdif == 0)||(sp < spmax && spdif>0)) // in a real tick we will tick
- && ((ep >= epmax && epdif == 0)||(ep < epmax && epdif>0)) // it
- && (Math.max(Math.max(hpdif,spdif),epdif) > 25 ) // treshhold against campfire & crystal and spheres
- && !faketick ) // camping or heal alls
- {
- //Another debug output message, this time it is for debugging the real tick detection
- //clientGUI.printText("generic","Real tick!\n");
- bp.tick();
- }
- faketick = false;
- } else {
- Matcher m_aw = p_aw.matcher(raw);
- if(m_aw.find())
- {
- faketick = true;
- }
- }
- return result;
- }
- void dunk()
- {
- bp.dunk();
- }
- public class DunkPanel extends BatPanel implements Runnable {
- int x = 0;// If anyone could explain me why changing this to private makes paint bug around drop me a tell
- int dunks = 0;
- public dunk()
- {
- x = 3000;
- dunks++;
- }
- public void tick()
- {
- dunks = 0;
- }
- public void run()
- {
- while(true)
- {
- Thread.sleep(70); // the lower the value here
- x -= 70; // the faster it updates the bar
- x = (x<0)?0:x;
- repaint();
- }
- }
- public DunkPanel()
- {
- super();
- }
- public void paint(Graphics g) {
- super.paint(g);
- g.setColor(cb);
- g.drawRect(0,0,100,20);
- int d = new Double(x/3000.0 * 100.0).intValue();
- if(d >= 66)
- g.setColor(c1);
- else if(d >= 33)
- g.setColor(c2);
- else
- g.setColor(c3);
- g.fillRect(0,0,d,20);
- if(dunks < 40)
- {
- g.setColor(c4);
- g.drawString("" + dunks,80,15);
- }
- }
- }
- public static DunkPanel bp;
Advertisement
Add Comment
Please, Sign In to add comment