package OnUnitEnterLeave import MapBounds import NoWurst import Unit import Trigger import Integer import Group import Player import ClosureTimers import AbilityObjEditing import RegisterEvents constant eventTrigger = CreateTrigger() public function getEnterLeaveUnit() returns unit return tempUnit public function onEnter(code c) eventTrigger.addCondition(Condition(c)) public function onLeave(code c) eventTrigger.addAction(c) unit tempUnit = null init CreateTrigger()..registerEnterRegion(boundRegion, Filter(() -> begin tempUnit = GetFilterUnit()..addAbility(ABILITY_ID)..makeAbilityPermanent(ABILITY_ID, true) eventTrigger.evaluate() tempUnit = null end)) registerPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_ORDER, () -> begin let leavingUnit = GetTriggerUnit() if leavingUnit.getAbilityLevel(ABILITY_ID) == 0 tempUnit = leavingUnit eventTrigger.execute() tempUnit = null end) ABILITY_ID = '!e@$' for i = 0 to bj_MAX_PLAYER_SLOTS-1 players[i].setAbilityAvailable(ABILITY_ID, false) let g = CreateGroup() GroupEnumUnitsInRect(g, boundRect, null) nullTimer(() -> begin while true tempUnit = FirstOfGroup(g) if tempUnit==null break tempUnit.addAbility(ABILITY_ID) tempUnit.makeAbilityPermanent(ABILITY_ID, true) g.removeUnit(tempUnit) eventTrigger.evaluate() g.destr() end) int ABILITY_ID = '!e@$' @compiletime function generateAbility() new AbilityDefinitionDefend(ABILITY_ID) ..setName("Leave Detect")..setEditorSuffix("(OnUnitEnterLeave)") ..setArtCaster("")..setIconNormal("")..setRace(Race.Unknown)