[AI] Have heroes learn abilities and pick up items

Every player is given 1 random hero through triggers (no buildings or other units).
I have a very simple AI script to get heroes to learn skills, but it isn't working. They also aren't picking up items.

Any help appreciated :grin:

JASS:
globals
    integer bla = 1
endglobals
//--------------------------------------------------------------------------------------------------
//  set_skills
//--------------------------------------------------------------------------------------------------
function set_skills takes nothing returns nothing

    set skill[ 1] = 'AHhb'
    set skill[ 2] = 'AHds'
    set skill[ 3] = 'AHhb'
    set skill[ 4] = 'AHre'
    set skill[ 5] = 'AHhb'
    set skill[ 6] = 'AHad'
    set skill[ 7] = 'AHds'
    set skill[ 8] = 'AHds'
    set skill[ 9] = 'AHre'
    set skill[10] = 'AHre'

    call SetSkillArray(1,'Hpal')

    set skill[ 1] = 'AHbz'
    set skill[ 2] = 'AHab'
    set skill[ 3] = 'AHbz'
    set skill[ 4] = 'AHwe'
    set skill[ 5] = 'AHbz'
    set skill[ 6] = 'AHmt'
    set skill[ 7] = 'AHab'
    set skill[ 8] = 'AHab'
    set skill[ 9] = 'AHwe'
    set skill[10] = 'AHwe'

    call SetSkillArray(1,'Hamg')

    set skill[ 1] = 'AHtc'
    set skill[ 2] = 'AHtb'
    set skill[ 3] = 'AHtc'
    set skill[ 4] = 'AHbh'
    set skill[ 5] = 'AHtc'
    set skill[ 6] = 'AHav'
    set skill[ 7] = 'AHtb'
    set skill[ 8] = 'AHtb'
    set skill[ 9] = 'AHbh'
    set skill[10] = 'AHbh'

    call SetSkillArray(1,'Hmkg')

    set skill[ 1] = 'AHfs'
    set skill[ 2] = 'AHbn'
    set skill[ 3] = 'AHfs'
    set skill[ 4] = 'AHdr'
    set skill[ 5] = 'AHfs'
    set skill[ 6] = 'AHpx'
    set skill[ 7] = 'AHbn'
    set skill[ 8] = 'AHbn'
    set skill[ 9] = 'AHdr'
    set skill[10] = 'AHdr'

    call SetSkillArray(1,'Hblm')
endfunction

//--------------------------------------------------------------------------------------------------
//    main
//--------------------------------------------------------------------------------------------------
function main takes nothing returns nothing
    call set_skills()
    call StandardAI(function SkillArrays, null, null)
    call StartThread(null)
    call PlayGame()
endfunction
 
Last edited:
Level 21
Joined
Mar 16, 2008
Messages
955
1) for items you need to modify each item's Priority in Object Editor to make the AI "think" the items are worth something

2) I think the problem is something like you didn't specify what hero the skill set array is for but... for the learning ability script, I tried modifying it as well but couldn't get it to work if I changed anything, besides just extending the array to be 11, 12, 13, .... It would work if I used a copy paste of what the GUI AI Editor generates. I was just trying to modify to get them to use more than 10 abilities, and that worked just extending what the GUI AI Editor generates. So I'm not exactly sure what's wrong but just copy paste from a GUI generated script and try to modify that as little as possible. I'm sure there is some way to clean it up but I haven't been able to figure it out. EDIT: if you are giving them a random hero via triggers, then the AI script won't "know" what their hero is, the hero "needs" (though I'm sure there is a workaround if you are good enough with JASS) to be picked within the AI script as far as I know. Currently if your script, there is no reference to what hero is learning this ability array. Alternatively, just set the abilities with triggers using "when hero levels up" event.
 
Last edited:
Hey, thanks for the reply. I ended up doing both with triggers as you suggested.

if you are giving them a random hero via triggers, then the AI script won't "know" what their hero is, the hero "needs" (though I'm sure there is a workaround if you are good enough with JASS) to be picked within the AI script as far as I know.
I figured this was what the problem is. The items are also created through triggers, maybe that was part of the problem as well.
 
Level 21
Joined
Mar 16, 2008
Messages
955
Is the problem that heroes aren't picking up items or that they aren't using items? If they aren't picking up items it means the items has no priority to the AI hero, or the item has lower priority than the hero's current items. If they aren't using the items, they only seem to use items under very specific conditions, kind of like how AI units only use abilities under conditions based on base item/ability. Such as it will only use scroll of healing if there are 5+ nearby units that are below 70% hp (just making up numbers but it's something similar to this). So it depends what the base item is. In my Kings and Knights map they seem to have no problem with trigger-created items.

I could be wrong but just wanted to share my understanding since responses to cpu questions are rarely answered.
 
Is the problem that heroes aren't picking up items or that they aren't using items?
I've made the AI pickup the items through through script, and they are using the items. I am not sure if it's because of the priority, I was just spawning standard non-modified items, but just having the killing unit pick up the created item seems to work well enough.
 
Level 21
Joined
Mar 16, 2008
Messages
955
Do the heroes currently interact or use any items without triggers? Maybe you need to be running an AI script to get the full hero behavior with items. That's why I start with all the base commands from the GUI AI Editor generated script.

What is base item of the created item? Is the created item's priority > 0 in the Object Editor?
 
Do the heroes currently interact or use any items without triggers?
They use the items (picked up through triggers/script), but do not pick any up (without triggers/script).

What is base item of the created item? Is the created item's priority > 0 in the Object Editor?
I'm only using the default unmodified items, randomly picked by level. As far as I can tell, nearly all default items have a priority > 0.
 
Top