HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Blade_DK's AI doesnt work on my map

09-08-2007, 04:27 AM#1
waaaks
my AI doesnt work...i even copied the whole trigger but still dont work...only the AIs move but dont use spells or learn any spells...

AI start
Collapse JASS:
function Trig_AIStart_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    set udg_Hero[GetPlayerId(p)] = u 
    if GetPlayerController(p) == MAP_CONTROL_COMPUTER then
        call StartAI(u)
    endif
endfunction

//===========================================================================
function InitTrig_AIStart takes nothing returns nothing
    set gg_trg_AIStart = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_AIStart, GetPlayableMapRect() )
    call TriggerAddAction( gg_trg_AIStart, function Trig_AIStart_Actions )
endfunction


AI
Collapse JASS:
function AILearnSkill takes unit h, string a returns nothing
    local integer i = GetTableInt(a, "LearnSkillOrder")+1
    if i == 1 or i == 4 or i == 8 then
        call SelectHeroSkill(h, GetStoredInteger(udg_GameCache, UnitId2String(GetUnitTypeId(h)), "BaseSkill1"))
    elseif i == 2 or i == 5 or i == 9 then
        call SelectHeroSkill(h, GetStoredInteger(udg_GameCache, UnitId2String(GetUnitTypeId(h)), "BaseSkill2"))
    elseif i == 3 or i == 7 or i == 10 then
        call SelectHeroSkill(h, GetStoredInteger(udg_GameCache, UnitId2String(GetUnitTypeId(h)), "BaseSkill3"))
    elseif i == 6 then
        call SelectHeroSkill(h, GetStoredInteger(udg_GameCache, UnitId2String(GetUnitTypeId(h)), "BaseSkill4"))
    endif
    call SetTableInt(a, "LearnSkillOrder", i)
endfunction

function AISetItem takes nothing returns nothing
    set bj_lastRemovedItem=GetEnumItem()
endfunction

function AIItemFilter takes nothing returns boolean
    return IsItemVisible(GetFilterItem()) and GetWidgetLife(GetFilterItem()) > 0
endfunction

function AIHasEmptyInventorySlot takes unit u returns boolean
    return UnitItemInSlot(u, 0) == null or UnitItemInSlot(u, 1) == null or UnitItemInSlot(u, 2) == null or UnitItemInSlot(u, 3) == null or UnitItemInSlot(u, 4) == null or UnitItemInSlot(u, 5) == null
endfunction

function AIFilterEnemyConditions takes nothing returns boolean
    return GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0 and IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(GetAttachedUnit(GetExpiredTimer(), "hero")))
endfunction

function AILoop takes nothing returns nothing
    local string a = GetAttachmentTable(GetExpiredTimer())
    local unit h = GetTableUnit(a, "hero")
    local rect i
    local location r
    local real x = GetUnitX(h)
    local real y = GetUnitY(h)
    local group g
    local boolexpr b
    local boolexpr be
    local unit f
    local string o = OrderId2String(GetUnitCurrentOrder(h))
    local real l = GetUnitState(h, UNIT_STATE_LIFE)
    local real e = 5
    if l <= 0 then
        set e = 1.5
    endif
    if l < GetUnitState(h, UNIT_STATE_MAX_LIFE)/5 then
        call IssuePointOrder(h, "move", GetUnitX(gg_unit_nfoh_0036), GetUnitY(gg_unit_nfoh_0036))
        set e = 3
    else
        if ((o == "smart") or (o == "attack") or (o == "patrol") or (o == "move") or (o == "stop") or (o == "hold") or (o == null)) then
            set g = CreateGroup()
            set b = Condition(function AIFilterEnemyConditions)
            call GroupEnumUnitsInRange(g, x, y, 500, b)
            set f = FirstOfGroup(g)
            if f == null then
                set i = Rect(x-800, y-800, x+800, y+800)
                set be = Condition(function AIItemFilter)
                set bj_lastRemovedItem=null
                call EnumItemsInRect(i, be, function AISetItem)
                if bj_lastRemovedItem != null and (GetItemType(bj_lastRemovedItem) == ITEM_TYPE_POWERUP or AIHasEmptyInventorySlot(h)) then
                    call IssueTargetOrder(h, "smart", bj_lastRemovedItem)
                else
                    set r = GetRandomLocInRect(bj_mapInitialPlayableArea)
                    call IssuePointOrderLoc(h, "patrol", r)
                    call RemoveLocation(r)
                endif
                call RemoveRect(i)
                call DestroyBoolExpr(be)
            else
                call IssueTargetOrder(h, "attack", f)
            endif
            call DestroyGroup(g)
            call DestroyBoolExpr(b)
        endif
    endif
    if GetHeroSkillPoints(h) > 0 and l > 0 then
        call AILearnSkill(h, a)
    endif
    call TimerStart(GetExpiredTimer(), e, true, function AILoop)
    set h = null
    set i = null
    set r = null
    set g = null
    set b = null
    set f = null
    set be = null
endfunction

function StartAI takes unit hero returns nothing
    local timer m = CreateTimer()
    call AttachObject(m, "hero", hero)
    call TimerStart(m, 0, false, function AILoop)
    set m = null
endfunction

function PlayerLeaves takes nothing returns nothing
    local player p = GetTriggerPlayer()
    call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, GetPlayerName(p)+" has left the game.")
    if udg_Hero[GetPlayerId(p)] != null then
        call StartAI(udg_Hero[GetPlayerId(p)])
    endif
    set p = null
endfunction

function SetupSkills takes nothing returns nothing
    local string h
 //Mary
 set h = UnitId2String('E001')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A001')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A00J')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A00N')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A00P')
 //Polinar
 set h = UnitId2String('H004')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A013')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A015')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A014')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A017')
 //Alvin
 set h = UnitId2String('H00G')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A01V')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A02D')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A02T')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A02U')
 //Marco
 set h = UnitId2String('H000')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A003')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A004')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A005')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A007')
 //Tambis
 set h = UnitId2String('H003')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A00X')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A00Y')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A00Z')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A010')
 //Abangin
 set h = UnitId2String('H005')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A01H')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A00I')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A019')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A01B')
 //Danilo
 set h = UnitId2String('H00C')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A01Z')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A027')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A01U')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A01X')
 //waaaks!
 set h = UnitId2String('H00E')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A029')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A025')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A01Y')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A02C')
 //Dondoy
 set h = UnitId2String('H001')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A008')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A009')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A00F')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A00C')
 //Rafi
 set h = UnitId2String('H00B')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A01N')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A01O')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A01P')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A01Q')
 //Julyo
 set h = UnitId2String('H00D')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A020')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A021')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A022')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A023')
 //Gaby
 set h = UnitId2String('H002')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A00A')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A018')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A000')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A00L')
 //Kevin
 set h = UnitId2String('H009')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A03N')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A01I')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A01J')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A00H')
 //Secrecy
 set h = UnitId2String('H00J')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A032')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A03E')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A013')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A033')
 //Basan
 set h = UnitId2String('H00I')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A02B')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A02W')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A02X')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A02Y')
 //Montero
 set h = UnitId2String('H00K')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A034')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A035')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A036')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A037')
 //Brent James
 set h = UnitId2String('H00L')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A039')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A03B')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A03C')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A03D')
 //Saavedra
 set h = UnitId2String('H00N')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A03K')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A03L')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A03M')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A03O')
 //Mordeno
 set h = UnitId2String('H00P')
 call StoreInteger(udg_GameCache, h, "BaseSkill0", 'A00T')
 call StoreInteger(udg_GameCache, h, "BaseSkill1", 'A01K')
 call StoreInteger(udg_GameCache, h, "BaseSkill2", 'A03Q')
 call StoreInteger(udg_GameCache, h, "BaseSkill3", 'A03S')
 call StoreInteger(udg_GameCache, h, "BaseSkill4", 'A03T')
endfunction

//===========================================================================
function InitTrig_AI takes nothing returns nothing
    local integer i = 0
    set gg_trg_AI = CreateTrigger(  )
    loop
        exitwhen i > 11
        call TriggerRegisterPlayerEventLeave( gg_trg_AI, Player(i) )
        set i = i + 1
    endloop
    call TriggerAddAction( gg_trg_AI, function PlayerLeaves )
    call ExecuteFunc("SetupSkills")
endfunction


note that all the raw codes has been changed to the raw codes of the spells and the heroes

Heres the map
IV - Polaris Wars v5
09-08-2007, 04:50 AM#2
The Elite
with the seconds trigger did you put it in the custom script section of your map or in a trigger, if you put it in a trigger put it in the custom script section. if it is in the custom script section then i have no idea
09-08-2007, 05:24 AM#3
waaaks
but in Blade_DK's AI map....it is in a trigger not in custom script header....

ill try it later...after i collected some answers
i need more answers before i leave this pc because this pc has no wc3
09-08-2007, 08:08 AM#4
Alexander244
For learning the skills: Check your gamecache is working correctly, you have all the requirements for the system etc.

For casting: If they are not being learned, they won't be cast, but once you have sorted the learning issue there are some things you should consider:
  • Computer AI does not use channel, so if your spells are based off that you will need to manually cast them from within the hero loop.
  • When a player leaves, their slot does not become computer controlled, and as far as I am aware there is no way to make it computer controlled either. As such you will have to trigger the casting of all non-autocast abilities for players who have left.

Edit: The problem is the gamecache. I could not find where you initialize it, but when I put an init before the setup skills, the heroes learned their abilities. I presume your are either not initializing it, or initializing it after SetupSkills.
Collapse fix:
function InitTrig_AI takes nothing returns nothing
    //...
    set udg_GameCache = InitGameCache("test.w3v")
    call ExecuteFunc("SetupSkills")
endfunction
09-08-2007, 11:22 AM#5
waaaks
so does it work on ur the map already...

if it works thanks!

does the function above is what i missed in my trigger?
so that means ill just copy that function to my map? or i need to modify it?
if i need to modify it...then what?

ill try this later

thanks!
09-08-2007, 11:26 AM#6
Alexander244
If you replace the the old function InitTrig_AI with this one, it will work:

Collapse JASS:
//===========================================================================
function InitTrig_AI takes nothing returns nothing
    local integer i = 0
    set gg_trg_AI = CreateTrigger(  )
    loop
        exitwhen i > 11
        call TriggerRegisterPlayerEventLeave( gg_trg_AI, Player(i) )
        set i = i + 1
    endloop
    call TriggerAddAction( gg_trg_AI, function PlayerLeaves )
    set udg_GameCache = InitGameCache("test.w3v")
    call ExecuteFunc("SetupSkills")
endfunction

Edit:
  • Make sure udg_GameCache is not Initialized elsewhere.
  • test.w3v can be anything.w3v
09-08-2007, 11:32 AM#7
botanic
the function above initializes the gamecache, think of it as creating a text file that you will write to later. If you don't have the file how can you write to it at a later date :P

As for having to modify it I would recommended that you at least change the "test.w3v" (the name of the gamecache file) to something a bit less general like AI_Cache.w3v or w/e... but thats just me. So long as you don't use that filename for another cache you will be fine.

The only other things you might have change are the function name (if a function of the same name already exists) and the "call ExecuteFunc("SetupSkills")" in your AI trigger to "call InitTrig_AI"
09-08-2007, 11:10 PM#8
waaaks
Quote:
The only other things you might have change are the function name (if a function of the same name already exists) and the "call ExecuteFunc("SetupSkills")" in your AI trigger to "call InitTrig_AI"

what does this mean?
does it mean i must not have the same function name in my trigger?

now it works thanks!