scope SnD initializer Init
//Requires NewGen.
globals
private constant group AIGroup = CreateGroup()
//No touchie the group.
private constant player AIPlayer = Player(12)
//Whatever player this should run for.
//(In JASS, Player 0 is red. So, blue is Player 1, and so on,
//Player 12 is Neutral Hostile.)
private constant rect AIRect = bj_mapInitialPlayableArea
//The region they will search inside. It is currently Playable Map Area.
private constant integer Helpers = 3
//The amount of reinforcements a unit call when attacked.
private constant real HelpRange = 1000
//The distance from which reinforcements can be called.
private boolexpr True
//No touchie the boolexpr.
private constant real MinX = GetRectMinX(AIRect)
//No touchie.
private constant real MaxX = GetRectMaxX(AIRect)
//No touchie.
private constant real MinY = GetRectMinY(AIRect)
//No touchie.
private constant real MaxY = GetRectMaxY(AIRect)
//No touchie.
private unit array EnumUnits
//NO TOUCHIE.
endglobals
private constant function TrueFunc takes nothing returns boolean
return true
endfunction
private function AIAct takes nothing returns nothing
local unit EnumUnit
local unit TrigUnit = GetTriggerUnit()
local integer i = 0
local integer loopint = 0
local real X = GetUnitX(TrigUnit)
local real Y = GetUnitY(TrigUnit)
call GroupEnumUnitsInRange(AIGroup, X, Y, HelpRange, True)
loop
set EnumUnit = FirstOfGroup(AIGroup)
exitwhen EnumUnit == null
set EnumUnits<i> = EnumUnit
set i = i + 1
call GroupRemoveUnit(AIGroup, EnumUnit)
endloop
loop
exitwhen loopint > Helpers
call IssuePointOrder(EnumUnits[GetRandomInt(0, i)], "attack", X, Y)
set loopint = loopint + 1
endloop
set EnumUnit = null
set TrigUnit = null
endfunction
private function RunAI takes nothing returns nothing
local unit EnumUnit
call GroupEnumUnitsOfPlayer(AIGroup, AIPlayer, True)
loop
set EnumUnit = FirstOfGroup(AIGroup)
exitwhen EnumUnit == null
if OrderId2String(GetUnitCurrentOrder(EnumUnit)) == "none" then
call IssuePointOrder(EnumUnit, "attack", GetRandomReal(MinX, MaxX), GetRandomReal(MinY, MaxY))
endif
call GroupRemoveUnit(AIGroup, EnumUnit)
endloop
set EnumUnit = null
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local timer tr = CreateTimer()
local integer i = 0
set True = Filter(function TrueFunc)
call TimerStart(tr, 0.01, true, function RunAI)
call TriggerRegisterPlayerUnitEvent(t, AIPlayer, EVENT_PLAYER_UNIT_ATTACKED, True)
call TriggerAddAction(t, function AIAct)
endfunction
endscope</i>