function Trig_Ignore_Rangers_Conditions takes nothing returns boolean
return (IsUnitType(GetTriggerUnit(), UNIT_TYPE_MELEE_ATTACKER)) and (IsUnitType(GetAttacker(), UNIT_TYPE_RANGED_ATTACKER))
endfunction
function Trig_Ignore_Rangers_Actions takes nothing returns nothing
local group g = CreateGroup()
local unit u = GetTriggerUnit()
local location target_loc = GetUnitLoc(u)
local integer target_index = 0
local unit first
local unit array target
call GroupEnumUnitsInRangeOfLoc(g,target_loc,500.00,null)
loop
set first = FirstOfGroup(g)
exitwhen (first == null)
if (IsUnitEnemy(first,GetTriggerPlayer())) and (not IsUnitType(first,UNIT_TYPE_RANGED_ATTACKER)) then
set target[target_index] = first
set target_index = target_index + 1
endif
call GroupRemoveUnit(g,first)
endloop
if (target[0]==null) then
call IssuePointOrder(u,"move",1,2)
//those are X/Y coordinates, you have to change them to those you are using
else
call IssueTargetOrder(u,"attack",target[GetRandomInt(0,target_index)])
endif
endfunction
//===========================================================================
function InitTrig_Ignore_Rangers takes nothing returns nothing
set gg_trg_Ignore_Rangers = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Ignore_Rangers, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition( gg_trg_Ignore_Rangers, Condition( function Trig_Ignore_Rangers_Conditions ) )
call TriggerAddAction( gg_trg_Ignore_Rangers, function Trig_Ignore_Rangers_Actions )
endfunction