Kelvin87
New Member
- Reaction score
- 14
This sample you juz look for the trigger part will do. The rest no need to consider. The Trigger for the register attack (acquires a target)you keep it.
if not IssueTargetOrder( GetTriggerUnit(), "attack", GetEventTargetUnit() ) then
call IssueImmediateOrder( GetTriggerUnit(), "stop" )
endif
scope TowerManager initializer InitTrig
globals
private constant integer MAX_TOWER_TYPES = 2 // Number of towers in your map that you
// included in this system.
//------------------------------------------------------------------------------------
private integer array TOWER_ID[MAX_TOWER_TYPES]
private group Towers = null
endglobals
private function setTowers takes nothing returns nothing
set TOWER_ID[0] = 039;H000039; // Set this to rawcode of the tower
set TOWER_ID[1] = 039;H001039; // and remember to increase [X] by 1 for every tower you add
endfunction
private function checkTowerId takes unit y returns boolean
local integer i = 0
local integer a = GetUnitTypeId(y)
loop
exitwhen i >= MAX_TOWER_TYPES
if (a == TOWER_ID<i> and not IsUnitInGroup(y, Towers)) then
return true
endif
set i = i + 1
endloop
return false
endfunction
private function check takes nothing returns boolean
local unit u = GetAttacker()
local unit a = GetTriggerUnit()
if (IsUnitInGroup(a, Towers)) then
call IssueTargetOrder(a, "attack", u)
endif
set a = null
set u = null
return false
endfunction
private function add takes nothing returns boolean
if checkTowerId(GetEnteringUnit()) and not IsUnitInGroup(GetEnteringUnit(), Towers) then
call GroupAddUnit(Towers, GetEnteringUnit())
return true
endif
return false
endfunction
private function bool takes nothing returns boolean
return checkTowerId(GetFilterUnit())
endfunction
private function InitTrig takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ATTACKED)
call TriggerAddCondition(t, Condition(function check))
set t = CreateTrigger()
call TriggerRegisterEnterRectSimple(t, bj_mapInitialPlayableArea)
call TriggerAddCondition(t, Condition(function add))
set Towers = CreateGroup()
call GroupEnumUnitsInRect(Towers, bj_mapInitialPlayableArea, Condition(function bool))
call setTowers()
endfunction
endscope</i>