Cokemonkey11
Spell Reviewer
- Joined
- May 9, 2006
- Messages
- 3,575
I'm trying to make an AI just as a change of pace, but it isn't working right. No matter how many bots I turn on in the lobby only one of them works.
JASS:
globals
unit array uAI
integer iAIIndex=0
endglobals
function initAIOrder takes nothing returns nothing
local integer index=0
loop
exitwhen index>iAIIndex
if IsPlayerAlly(GetOwningPlayer(uAI[index]),Player(0)) or GetOwningPlayer(uAI[index])==Player(0) then
if GetUnitState(uAI[index],UNIT_STATE_LIFE)<1 then
elseif GetUnitState(uAI[index],UNIT_STATE_LIFE)/GetUnitState(uAI[index],UNIT_STATE_MAX_LIFE)<.5 then
call IssuePointOrder(uAI[index],"move",-2101,-6908)
elseif GetUnitState(uAI[index],UNIT_STATE_LIFE)/GetUnitState(uAI[index],UNIT_STATE_MAX_LIFE)>.5 then
call IssuePointOrder(uAI[index],"move",353,-703)
endif
else
call BJDebugMsg(GetUnitName(uAI[index])+" is on the north team. "+GetPlayerName(GetOwningPlayer(uAI[index])))
if GetUnitState(uAI[index],UNIT_STATE_LIFE)<1 then
call BJDebugMsg(GetUnitName(uAI[index])+" is dead.")
elseif GetUnitState(uAI[index],UNIT_STATE_LIFE)/GetUnitState(uAI[index],UNIT_STATE_MAX_LIFE)<.5 then
call BJDebugMsg(GetUnitName(uAI[index])+" being moved to north repair dock. "+GetPlayerName(GetOwningPlayer(uAI[index])))
call IssuePointOrder(uAI[index],"move",57,6147)
elseif GetUnitState(uAI[index],UNIT_STATE_LIFE)/GetUnitState(uAI[index],UNIT_STATE_MAX_LIFE)>.5 then
call BJDebugMsg(GetUnitName(uAI[index])+" being moved to middle of right lane. "+GetPlayerName(GetOwningPlayer(uAI[index])))
call IssuePointOrder(uAI[index],"move",353,-703)
endif
endif
set index=index+1
endloop
endfunction
function initAIChoose takes nothing returns boolean
return IsUnitType(GetFilterUnit(),UNIT_TYPE_HERO)
endfunction
function initAIA takes nothing returns nothing
local integer index=2
local group gHeroes=CreateGroup()
local timer newOrder=CreateTimer()
loop
exitwhen index>11
if GetPlayerController(Player(index))==MAP_CONTROL_COMPUTER then
call GroupEnumUnitsOfPlayer(gHeroes,Player(index),Condition(function initAIChoose))
set uAI[iAIIndex]=pickRandUnit(gHeroes)
set iAIIndex=iAIIndex+1
call GroupClear(gHeroes)
endif
set index=index+1
endloop
call DestroyGroup(gHeroes)
call TimerStart(newOrder,5,true,function initAIOrder)
endfunction
function InitTrig_initAI takes nothing returns nothing
set gg_trg_initAI=CreateTrigger()
call TriggerRegisterTimerEvent(gg_trg_initAI,10,false)
call TriggerAddAction(gg_trg_initAI,function initAIA)
endfunction