I'm not going to one for you, because I'm busy with my own, but here's how I did mine:
I had a string array that held the current AI order for each AI hero, with array number realting to owning player
Every second, I ran a series of checks for each AI hero, to check what their current status was.
The check worked like this:Create a periodic trigger that checks the unit's status, then runs a trigger just for it. That's were JASS comes in, you can run functions for single units.
- If the AI had low health, it was ordered to retreat.
- If it was idle, it would start 'roaming', or looking for heroes.
- If it was attacking, it would check if there were enemies in range, and if not, start roaming again.
- If it was attacking, it would try to use abilities.
- If it had retreated, it would check if it had enough health again, and make it roam.
- If it was attacking, it would also pick every enemy in range and calculate it's chances of winning, and push forward or fall back depending on the outcome.
Just a hint, with a thread title like that, you won't get many replies, you actually sound pretty rude. Rather say "AI help please" or "AoS AI system requested" or "Does anyone have an AoS AI system?".
scope AIEasyLevelFunctions
public function Roam takes integer int returns nothing
local unit u = udg_AI_Hero[int]
local real array tX
local real array tY
local real uX = GetUnitX(u)
local real uY = GetUnitY(u)
local real array stepdist
local real array unitdist
call BJDebugMsg("...roam function called successfully.")
if udg_AI_CurrentLane[int] == "left" then
if IsPlayerInForce(GetOwningPlayer(u), udg_Defenders_AIPlayers) == true then
set stepdist[1] = CustomFunctions_Distance(GetRectCenterX(gg_rct_HFortress), GetRectCenterY(gg_rct_HFortress), GetRectCenterX(gg_rct_TopLeft), GetRectCenterY(gg_rct_TopLeft))-10
set unitdist[1] = CustomFunctions_Distance(uX, uY, GetRectCenterX(gg_rct_TopLeft), GetRectCenterY(gg_rct_TopLeft))
set stepdist[2] = CustomFunctions_Distance(GetRectCenterX(gg_rct_TopLeft), GetRectCenterY(gg_rct_TopLeft), GetRectCenterX(gg_rct_BottomLeft), GetRectCenterY(gg_rct_BottomLeft))+10
set unitdist[2] = CustomFunctions_Distance(uX, uY, GetRectCenterX(gg_rct_BottomLeft), GetRectCenterY(gg_rct_BottomLeft))
set stepdist[3] = CustomFunctions_Distance(GetRectCenterX(gg_rct_BottomLeft), GetRectCenterY(gg_rct_BottomLeft), GetRectCenterX(gg_rct_OFortress), GetRectCenterY(gg_rct_OFortress))+10
set unitdist[3] = CustomFunctions_Distance(uX, uY, GetRectCenterX(gg_rct_OFortress), GetRectCenterY(gg_rct_OFortress))
call BJDebugMsg("distances set")
if unitdist[1] < stepdist[1] and unitdist[2] > stepdist[2] and unitdist[3] > stepdist[3] then
call IssuePointOrder(u, "attack", GetRectCenterX(gg_rct_TopLeft), GetRectCenterY(gg_rct_TopLeft))
call BJDebugMsg("unit issued order to attack to topleft")
elseif unitdist[2] < stepdist[2] and unitdist[3] > stepdist[3] then
call IssuePointOrder(u, "attack", GetRectCenterX(gg_rct_BottomLeft), GetRectCenterY(gg_rct_BottomLeft))
call BJDebugMsg("unit issued order to attack to bottomleft")
elseif unitdist[2] < stepdist[2] and unitdist[3] < stepdist[3] then
call IssuePointOrder(u, "attack", GetRectCenterX(gg_rct_OFortress), GetRectCenterY(gg_rct_OFortress))
call BJDebugMsg("unit issued order to attack to OCenter")
endif
elseif IsPlayerInForce(GetOwningPlayer(u), udg_Raiders_AIPlayers) == true then
set stepdist[1] = CustomFunctions_Distance(GetRectCenterX(gg_rct_OFortress), GetRectCenterY(gg_rct_OFortress), GetRectCenterX(gg_rct_BottomLeft), GetRectCenterY(gg_rct_BottomLeft))-10
set unitdist[1] = CustomFunctions_Distance(uX, uY, GetRectCenterX(gg_rct_BottomLeft), GetRectCenterY(gg_rct_BottomLeft))
set stepdist[2] = CustomFunctions_Distance(GetRectCenterX(gg_rct_TopLeft), GetRectCenterY(gg_rct_TopLeft), GetRectCenterX(gg_rct_BottomLeft), GetRectCenterY(gg_rct_BottomLeft))+10
set unitdist[2] = CustomFunctions_Distance(uX, uY, GetRectCenterX(gg_rct_TopLeft), GetRectCenterY(gg_rct_TopLeft))
set stepdist[3] = CustomFunctions_Distance(GetRectCenterX(gg_rct_TopLeft), GetRectCenterY(gg_rct_TopLeft), GetRectCenterX(gg_rct_HFortress), GetRectCenterY(gg_rct_HFortress))+10
set unitdist[3] = CustomFunctions_Distance(uX, uY, GetRectCenterX(gg_rct_HFortress), GetRectCenterY(gg_rct_HFortress))
call BJDebugMsg("distances set (right)")
if unitdist[1] < stepdist[1] and unitdist[2] > stepdist[2] and unitdist[3] > stepdist[3] then
call IssuePointOrder(u, "attack", GetRectCenterX(gg_rct_BottomLeft), GetRectCenterY(gg_rct_BottomLeft))
call BJDebugMsg("unit issued order to attack to bottomleft")
elseif unitdist[2] < stepdist[2] and unitdist[3] > stepdist[3] then
call IssuePointOrder(u, "attack", GetRectCenterX(gg_rct_TopLeft), GetRectCenterY(gg_rct_TopLeft))
call BJDebugMsg("unit issued order to attack to topleft")
elseif unitdist[2] < stepdist[2] and unitdist[3] < stepdist[3] then
call IssuePointOrder(u, "attack", GetRectCenterX(gg_rct_HFortress), GetRectCenterY(gg_rct_HFortress))
call BJDebugMsg("unit issued order to attack to HCenter")
endif
endif
elseif udg_AI_CurrentLane[int] == "right" then
if IsPlayerInForce(GetOwningPlayer(u), udg_Defenders_AIPlayers) == true then
set stepdist[1] = CustomFunctions_Distance(GetRectCenterX(gg_rct_HFortress), GetRectCenterY(gg_rct_HFortress), GetRectCenterX(gg_rct_TopRight), GetRectCenterY(gg_rct_TopRight))-10
set unitdist[1] = CustomFunctions_Distance(uX, uY, GetRectCenterX(gg_rct_TopRight), GetRectCenterY(gg_rct_TopRight))
set stepdist[2] = CustomFunctions_Distance(GetRectCenterX(gg_rct_TopRight), GetRectCenterY(gg_rct_TopRight), GetRectCenterX(gg_rct_BottomRight), GetRectCenterY(gg_rct_BottomRight))+10
set unitdist[2] = CustomFunctions_Distance(uX, uY, GetRectCenterX(gg_rct_BottomRight), GetRectCenterY(gg_rct_BottomRight))
set stepdist[3] = CustomFunctions_Distance(GetRectCenterX(gg_rct_BottomRight), GetRectCenterY(gg_rct_BottomRight), GetRectCenterX(gg_rct_OFortress), GetRectCenterY(gg_rct_OFortress))+10
set unitdist[3] = CustomFunctions_Distance(uX, uY, GetRectCenterX(gg_rct_OFortress), GetRectCenterY(gg_rct_OFortress))
call BJDebugMsg("distances set (right)")
if unitdist[1] < stepdist[1] and unitdist[2] > stepdist[2] and unitdist[3] > stepdist[3] then
call IssuePointOrder(u, "attack", GetRectCenterX(gg_rct_TopRight), GetRectCenterY(gg_rct_TopRight))
call BJDebugMsg("unit issued order to attack to topright")
elseif unitdist[2] < stepdist[2] and unitdist[3] > stepdist[3] then
call IssuePointOrder(u, "attack", GetRectCenterX(gg_rct_BottomRight), GetRectCenterY(gg_rct_BottomRight))
call BJDebugMsg("unit issued order to attack to bottomright")
elseif unitdist[2] < stepdist[2] and unitdist[3] < stepdist[3] then
call IssuePointOrder(u, "attack", GetRectCenterX(gg_rct_OFortress), GetRectCenterY(gg_rct_OFortress))
call BJDebugMsg("unit issued order to attack to OCenter")
endif
elseif IsPlayerInForce(GetOwningPlayer(u), udg_Raiders_AIPlayers) == true then
set stepdist[1] = CustomFunctions_Distance(GetRectCenterX(gg_rct_OFortress), GetRectCenterY(gg_rct_OFortress), GetRectCenterX(gg_rct_BottomRight), GetRectCenterY(gg_rct_BottomRight))-10
set unitdist[1] = CustomFunctions_Distance(uX, uY, GetRectCenterX(gg_rct_BottomRight), GetRectCenterY(gg_rct_BottomRight))
set stepdist[2] = CustomFunctions_Distance(GetRectCenterX(gg_rct_TopRight), GetRectCenterY(gg_rct_TopRight), GetRectCenterX(gg_rct_BottomRight), GetRectCenterY(gg_rct_BottomRight))+10
set unitdist[2] = CustomFunctions_Distance(uX, uY, GetRectCenterX(gg_rct_TopRight), GetRectCenterY(gg_rct_TopRight))
set stepdist[3] = CustomFunctions_Distance(GetRectCenterX(gg_rct_TopRight), GetRectCenterY(gg_rct_TopRight), GetRectCenterX(gg_rct_HFortress), GetRectCenterY(gg_rct_HFortress))+10
set unitdist[3] = CustomFunctions_Distance(uX, uY, GetRectCenterX(gg_rct_HFortress), GetRectCenterY(gg_rct_HFortress))
call BJDebugMsg("distances set (right)")
if unitdist[1] < stepdist[1] and unitdist[2] > stepdist[2] and unitdist[3] > stepdist[3] then
call IssuePointOrder(u, "attack", GetRectCenterX(gg_rct_BottomRight), GetRectCenterY(gg_rct_BottomRight))
call BJDebugMsg("unit issued order to attack to bottomright")
elseif unitdist[2] < stepdist[2] and unitdist[3] > stepdist[3] then
call IssuePointOrder(u, "attack", GetRectCenterX(gg_rct_TopRight), GetRectCenterY(gg_rct_TopRight))
call BJDebugMsg("unit issued order to attack to topright")
elseif unitdist[2] < stepdist[2] and unitdist[3] < stepdist[3] then
call IssuePointOrder(u, "attack", GetRectCenterX(gg_rct_HFortress), GetRectCenterY(gg_rct_HFortress))
call BJDebugMsg("unit issued order to attack to HCenter")
endif
endif
elseif udg_AI_CurrentLane[int] == "center" then
if IsPlayerInForce(GetOwningPlayer(u), udg_Defenders_AIPlayers) == true then
call IssuePointOrder(u, "attack", GetRectCenterX(gg_rct_OFortress), GetRectCenterY(gg_rct_OFortress))
call BJDebugMsg("unit ordered to attack to OBase")
elseif IsPlayerInForce(GetOwningPlayer(u), udg_Raiders_AIPlayers) == true then
call IssuePointOrder(u, "attack", GetRectCenterX(gg_rct_HFortress), GetRectCenterY(gg_rct_HFortress))
call BJDebugMsg("unit ordered to attack to HBase")
endif
endif
set u = null
endfunction
endscope
scope AIEasyLevel initializer init
private function GroupActions takes nothing returns nothing
local unit u = GetEnumUnit()
local string o = udg_AI_CurrentOrder[GetConvertedPlayerId(GetOwningPlayer(u))]
if GetUnitCurrentOrder(u) == null and o != "retreat" then
call AIEasyLevelFunctions_Roam(GetConvertedPlayerId(GetOwningPlayer(u)))
call BJDebugMsg("roam function called...")
endif
set u = null
endfunction
private function EasyActions takes nothing returns nothing
call ForGroup(udg_AI_HeroGroup, function GroupActions)
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterTimerEventPeriodic(t, 1.00)
call TriggerAddAction(t, function EasyActions)
endfunction
endscope
And sorry about being mean about your title, I didn't realise you weren't english :'(