package DamageDetection import OnUnitEnterLeave /** Use `addOnDamageFunc` to add a listener to any damage event that happens on the map. Example: init addOnDamageFunc() -> print("Damage Event with dmg: " + GetEventDamage().toString()) */ @configurable constant SWAP_TIMEOUT = 600. boolexpr array func int funcNext = 0 trigger current = null trigger toDestroy = null constant filter = Filter(() -> addUnit(GetFilterUnit())) function addUnit(unit u) current.registerUnitEvent(u, EVENT_UNIT_DAMAGED) /** Add a Action to the damage Event. */ public function addOnDamageFunc(code c) let cf = Condition(c) current.addCondition(cf) func[funcNext] = cf funcNext++ /** Add a Condition(Action) to the damage Event. */ public function addOnDamageFunc(boolexpr cf) current.addCondition(cf) func[funcNext] = cf funcNext++ /** Disables the damage events */ public function disableDamageDetect() DisableTrigger(current) /** Enables the damage events */ public function enableDamageDetect() EnableTrigger(current) /** Periodic Cleanup-Function */ function swap() let isEnabled = IsTriggerEnabled(current) current.disable() if toDestroy != null toDestroy.destr() toDestroy = current current = CreateTrigger() if not isEnabled current.disable() ENUM_GROUP.enumUnitsAll(filter) for i = 0 to funcNext - 1 current.addCondition(func[i]) init current = CreateTrigger() for i = 0 to funcNext - 1 current.addCondition(func[i]) onEnter(() -> addUnit(getEnterLeaveUnit())) CreateTimer().startPeriodic(SWAP_TIMEOUT, function swap)