import com.swath.*; import com.swath.cmd.*; import com.swath.event.*; /** * "The Sector Guard"
* Shows how to wait for events and perform actions. * * @author Stein * @since SWATH 1.3 */ public class ExampleScript4 extends UserDefinedScript { public String getName() { return "Example Script #4"; } public String getDescription() { return "The Sector Guard

"+ "Shows how to wait for events and perform actions."; } public boolean initScript() throws Exception { // Check that we are at the correct prompt if (!atPrompt(Swath.COMMAND_PROMPT)) return false; return true; } public boolean runScript() throws Exception { SetTextMode.exec(SetTextMode.COLOR_WHITE, SetTextMode.COLOR_RED, SetTextMode.MODE_HIGHLIGHT); PrintText.exec("\n\n<<< Sector guard activated >>>\n\n"); SetTextMode.exec(); // Loop forever while (true) { // Wait for someone to warp in... ShipEnteredSector eventSES = (ShipEnteredSector)WaitForEvent.exec(ShipEnteredSector.class); SetTextMode.exec(SetTextMode.COLOR_RED, SetTextMode.COLOR_BLACK, SetTextMode.MODE_HIGHLIGHT); PrintText.exec("\n\n### Red alert: " + eventSES.getTrader().name() + " entered the sector.\n\n"); SetTextMode.exec(); // Power up weapons systems! AttackTrader.exec(eventSES.getTrader(), 0); // Wait for trader to leave... ShipLeftSector eventSLS = (ShipLeftSector)WaitForEvent.exec(ShipLeftSector.class); SetTextMode.exec(SetTextMode.COLOR_GREEN, SetTextMode.COLOR_BLACK, SetTextMode.MODE_HIGHLIGHT); PrintText.exec("\n\n### Sector secured: " + eventSLS.getTrader().name() + " left the sector.\n\n"); SetTextMode.exec(); } } public void endScript(boolean finished) throws Exception { // Nothing to do } }