SCRIPT_NAME = "balance"; SCRIPT_DESC = "Pisano's Balance Triggers"; SCRIPT_OFF = false; /** * author: pisano * last updated: 1/31/2018 * version: 0.2 */ Color green = new Color(0, 127, 0); Color red = new Color(200, 50, 50); long lastBalanceTime = 0; void help() { clientGUI.printText("general", "*************************\n"); clientGUI.printText("general", "Balance triggers Help\n"); clientGUI.printText("general", "\nMake a hotkey or command for \"$balance\", this will display the balance timer.\n"); clientGUI.printText("general", "You can balance every 25 minutes. When you balance the timer will reset.\n"); clientGUI.printText("general", "*************************\n"); } void bootup() { clientGUI.printText("general", "LOADED: " + SCRIPT_NAME + " ('$"+SCRIPT_NAME+".help' for more info.)\n"); triggerManager.newTrigger("balance_reset", "^You feel balanced.$", "$"+SCRIPT_NAME+".resetBalanceTimer"); // when you wear sleeves it starts the timer over again. triggerManager.newTrigger("balance_reset2", "^You wear a pair of pure white flowing sleeves", "$"+SCRIPT_NAME+".resetBalanceTimer"); triggerManager.newTrigger("balance", "^You feel balanced.$", "", false, true, false, new Color[] { green }, Font.PLAIN); // Balance timer not ready yet. triggerManager.newTrigger("balance_unable", "^The sleeves seem unable to grant balance at the time.$", "", false, true, false, new Color[] { red }, Font.PLAIN); // Balance available, but you are at max health/sps triggerManager.newTrigger("balance_unable2", "^The sleeves are unable to balance you further.$", "", false, true, false, new Color[] { red }, Font.PLAIN); resetBalanceTimer(); } void resetBalanceTimer() { lastBalanceTime = System.currentTimeMillis(); clientGUI.printText("general", "Reset Balance timer.\n" ); startBalanceTimer(); } void showBalanceTimer() { // clientGUI.printText("general", "[balance] showBalanceTimer()\n", "ff0000"); long now = System.currentTimeMillis(); long elapsed = now - lastBalanceTime; Date timeSinceLastBalance = new Date(elapsed); //clientGUI.doCommand("party report " + lastTime.toString()); //long seconds = (elapsed / 1000) % 60; long milliseconds = elapsed; int seconds = (int) (milliseconds / 1000) % 60 ; int minutes = (int) ((milliseconds / (1000*60)) % 60); int hours = (int) ((milliseconds / (1000*60*60)) % 24); String secondsStr = seconds < 10 ? "0" + seconds : "" + seconds; String timeStr = minutes + ":" + secondsStr; if (hours > 0) { timeStr = hours + ":" + timeStr; } clientGUI.printText("general", "*** REPORT: Last Balance was: " + timeStr + " ago. (Can balance every 25 min)\n", "CC8800"); // clientGUI.doCommand("party report Last Balance was..."); } void run() { showBalanceTimer(); // clientGUI.printText("general", "[balance] run()\n", "ff0000"); } void startBalanceTimer() { clientGUI.printText("general", "starting balance timer\n", "ff0000"); try { int seconds = 25*60; // 25 mins new CommandThread(seconds, "ignore"); } catch (Exception e) { clientGUI.printText("general", "----------Failed to run $threads script: " + e, "ff0000"); } } public class CommandThread extends Thread { int seconds; String command; public CommandThread(int seconds, String command) { this.seconds = seconds; this.command = command; start(); } public void run() { //clientGUI.printText("general", "[balance] command thread run\n", "ff0000"); // The sleep method in threads throw an exception we must catch. try { sleep(seconds * 1000); // Sleep x ms } catch (Exception e) { clientGUI.printText("general", "Eeeek, exception occured in our thread\n"); } // Now we will issue the command by sending it over the net object // to the server. The net object is one of the defined variables that // all scripts have access to. clientGUI.printText("general", "Can Balance Again\n", "22cc22"); // net.send(command); } }