[AI] Hero not using basic abilities

I have a very simple AI script for an allied player hero in a campaign mission. The hero is preplaced and set to level 4 and has 4 skills learned through triggers at init. The next two skills are learned through the AI script.

When he levels up, he correctly learns the skills, and he uses his ult (A00J/Charge) when in combat. But he doesn't seem to use his basic abilities (except the passive Bash) for some reason. The enemy heroes do use all their abilities as far as I can tell.

The script:
JASS:
//============================================================================
//  Human 03 -- gavinrad -- AI Script
//============================================================================
function GavinradAI takes nothing returns integer
    local integer level = GetHeroLevelAI()

    if level == 5 then
        return 'AHbh' // Bash
    endif

    if level == 6 then
        return 'A00J' // Charge
    endif

	return 0
endfunction

//============================================================================
//  main
//============================================================================
function main takes nothing returns nothing
    call CampaignAI(HOUSE, null)
	call SetCaptainHome(BOTH_CAPTAINS, 2400, 250)

	call SetBuildUnitEx(1, 1, 1, 'halt')
	call SetBuildUnitEx(1, 1, 1, 'Hmkg')
	
    call SetHeroLevels(function GavinradAI)
	call CampaignDefenderEx(1, 1, 1, 'Hmkg') // Commander/Gavinrad

    call SleepForever()
endfunction
 
Last edited:
Level 30
Joined
Aug 29, 2012
Messages
1,382
What ability served as a base for the spells that he doesn't use?

As for the revive, perhaps add a SetBuildUnitEx( 1, 1, 1, [altar] ) before the hero line just in case, or even call SetReplacements(999,999,999). If that still doesn't work, I suppose triggering the revive is always an option
 
What ability served as a base for the spells that he doesn't use?
Shadow Strike and Rune of Speed (item ability). The same hero uses these same abilities just fine in an altered melee map though.

As for the revive, perhaps add a SetBuildUnitEx( 1, 1, 1, [altar] ) before the hero line just in case, or even call SetReplacements(999,999,999). If that still doesn't work, I suppose triggering the revive is always an option
Didn't work. Yeah I guess I could trigger it, but I feel it should work through AI.
 
Level 28
Joined
Dec 3, 2020
Messages
969
"call SetHeroLevels(function GavinradAI)"

Must the GavinradAI function be called inside SetHeroLevels?
If YES, are you sure you have to write "function GavinradAI" inside SetHeroLevels? Will simply writing "call SetHeroLevels(GavinradAI) work, OR call SetHeroLevels(GavinradAI())

If NOT, shouldn't you just call the GavinradAI function without the SetHeroLevels function?

I'm not an expert in JASS, beyond making simple campaign style .ai scripts BUT "call SetHeroLevels(function GavinradAI)" looks very wrong to me.
 
"call SetHeroLevels(function GavinradAI)"

Must the GavinradAI function be called inside SetHeroLevels?
If YES, are you sure you have to write "function GavinradAI" inside SetHeroLevels? Will simply writing "call SetHeroLevels(GavinradAI) work, OR call SetHeroLevels(GavinradAI())

If NOT, shouldn't you just call the GavinradAI function without the SetHeroLevels function?

I'm not an expert in JASS, beyond making simple campaign style .ai scripts BUT "call SetHeroLevels(function GavinradAI)" looks very wrong to me.
I copied this from h02_purple.ai, SetHeroLevels is a native that takes code so will only work with function function_name. I believe the passed function (GavinradAI in this case) gets called whenever the hero levels up to get the ability ID to learn. In any case, this part of the script works as expected.
 
Remove the SleepForever perhaps? Shadow strike at least should definitely work, can you check his ability levels during gameplay to see if he has all the abilities he should?
Removing SleepForever also didn't work. I checked, he does indeed have all the abilities.

Edit: The enemy AIs are reviving heroes and using abilities correctly, weirdly. Really don't know what's wrong here :(
 
Last edited:
Level 28
Joined
Dec 3, 2020
Messages
969
Btw for the hero to be revived as a defender, you must have the altar as a building in the script, like this:

call SetBuildUnitEx( 1,1,1, 'halt' ) // Altar of Kings

before the campaign defender ---> call CampaignDefenderEx( 1, 1, 1, 'H60B' ) // Archmage -> Dalar Dawnweaver


Also ---> call SetBuildUnitEx( 1, 1, 1, 'Hpal' ------------> you have to close the brackets ---> call SetBuildUnitEx( 1, 1, 1, 'Hpal')

Btw you don't need the call SetBuildUnitEx( 1, 1, 1, 'Hpal') if the hero is preplaced on the map.

Edit: The enemy AIs are reviving heroes and using abilities correctly, weirdly. Really don't know what's wrong here :(
Does it use the exact same script?
 
Btw for the hero to be revived as a defender, you must have the altar as a building, like this:
Tried that, no luck :( Updating OP.

Edit:
Does it use the exact same script?
No, they have a standard "suicide on player" script:
JASS:
//============================================================================
//  Human 03 -- red player -- AI Script
//============================================================================
globals
    player villagers = Player(4)
	integer villagersid = 4
	
	constant integer CHIEFTAIN = TAUREN_CHIEF
	constant integer ORC_LUMBER_MILL = FORGE
	constant integer ORC_BLACKSMITH = VOODOO_LOUNGE
	constant integer SPEARMAN = HEAD_HUNTER
endglobals

//============================================================================
//  main
//============================================================================
function main takes nothing returns nothing
    debug set do_debug_cheats = true

    call CampaignAI(PIG_FARM,null)
	call SetCaptainHome(BOTH_CAPTAINS,-5400,4500)

    call SetBuildUnitEx( 1, 1, 1, GREAT_HALL      )
    call SetBuildUnitEx( 1, 1, 1, PEON           )
    call SetBuildUnitEx( 1, 1, 1, ORC_ALTAR      )
    call SetBuildUnitEx( 2, 2, 2, ORC_BARRACKS             )
    call SetBuildUnitEx( 8, 8, 8, PEON           )
	call SetBuildUnitEx( 1, 1, 1, CHIEFTAIN				)
    call SetBuildUnitEx( 4, 4, 4, PIG_FARM        )
    call SetBuildUnitEx( 1, 1, 1, ORC_LUMBER_MILL           )
    call SetBuildUnitEx( 1, 1, 1, ORC_BLACKSMITH     )
	
    call SetHarvestLumber(true)
	call SetGoldPeons(5)
    call SetWoodPeons(3)

    call CampaignDefenderEx( 3,4,5, GRUNT       )
    call CampaignDefenderEx( 2,2,3, SPEARMAN       )
	call CampaignDefenderEx( 1,1,1, CATAPULT	)
	call CampaignDefenderEx( 1,1,1, CHIEFTAIN		)

    call WaitForSignal()

    set allow_signal_abort = true

    //* WAVE 1 Time elapsed 1min *
    call InitAssaultGroup()
    call CampaignAttackerEx( 3,3,5, GRUNT       )
    call SuicideOnPlayerEx(0, 0, 0,villagers)

    //* WAVE 2 Time elapsed 4min *
    call InitAssaultGroup()
    call CampaignAttackerEx( 3,3,3, GRUNT       )
    call CampaignAttackerEx( 0,0,1, CATAPULT  )
    call CampaignAttackerEx( 0,0,1, SPEARMAN       )
    call SuicideOnPlayerEx(M3, M3, M2,villagers)

	call SetBuildUpgrEx( 1,1,1, UPG_ORC_ARMOR   )
	call SetBuildUpgrEx( 1,1,1, UPG_ORC_MELEE   )

    //* WAVE 3 Time elapsed 7min *
    call InitAssaultGroup()
    call CampaignAttackerEx( 4,4,5, GRUNT       )
    call CampaignAttackerEx( 1,1,2, SPEARMAN       )
    call SuicideOnPlayerEx(M3, M3, M2,villagers)
	
	call SetBuildUpgrEx( 1,1,1, UPG_ORC_RANGED   )

    //* WAVE 4 Time elapsed 10min *
    call InitAssaultGroup()
    call CampaignAttackerEx( 3,3,4, GRUNT       )
    call CampaignAttackerEx( 1,1,1, SPEARMAN       )
    call CampaignAttackerEx( 1,1,2, CATAPULT  )
    call SuicideOnPlayerEx(M3, M3, M2,villagers)

    //* WAVE 5 Time elapsed 13min *
    call InitAssaultGroup()
    call CampaignAttackerEx( 6,6,8, GRUNT       )
    call SuicideOnPlayerEx(M3, M3, M2,villagers)

	//* WAVE 6 Time elapsed 16min *
    call InitAssaultGroup()
    call CampaignAttackerEx( 6,6,8, GRUNT )
	call CampaignAttackerEx( 1,1,2, CATAPULT  )
    call SuicideOnPlayerEx(M3, M3, M2,villagers)

    //* WAVE 7 Time elapsed 19min *
    call InitAssaultGroup()
    call CampaignAttackerEx( 6,6,8, GRUNT       )
	call CampaignAttackerEx( 1,1,4, SPEARMAN       )
    call SuicideOnPlayerEx(M3, M3, M2,villagers)

	//* WAVE 8 Time elapsed 22min *
    call InitAssaultGroup()
    call CampaignAttackerEx( 6,6,6, GRUNT       )
	call CampaignAttackerEx( 2,2,6, SPEARMAN       )
	call CampaignAttackerEx( 1,1,2, CATAPULT  )
    call SuicideOnPlayerEx(M3, M3, M2,villagers)

    call ForeverSuicideOnPlayer(M3,villagers)

    call SuicideUnitsEx( villagersid, CATAPULT, GRUNT, SPEARMAN, CHIEFTAIN, 0, 0, 0, 0, 0, 0 )
endfunction
 
Last edited:
Try removing or commenting out the following line:

And keep the preplaced Paladin on the map.
Omg I'm so stupid, I've been using the wrong unit ID xD It's 'Hmkg' not 'Hpal', that's a different hero lol. Okay, now he's being revived, but still not using his basic abilities.
 
Did you remove the line of code I told you to remove?
You never now until you try.

Also, what patch are you playing on?
Yeah, didn't work, still not using the abilities :( He doesn't even use the abilities if I don't load the AI script at all, so I don't think it's a problem with the script.
Latest patch, 2.0.1.

Edit: hmmmmmmmmmmmmmmmm ok it seem the hero is using its abilities, but only on heroes. WTF
Edit2: TIL that the AI uses certain abilities only on certain enemies. E.g. Shadow Strike (what the ability here in question is based on) is only used on heroes (and possibly big/strong units). Same for Storm Bolt it seems. This is what the problem was all along with the abilities.
 
Last edited:
Level 28
Joined
Dec 3, 2020
Messages
969
Yeah, didn't work, still not using the abilities :( He doesn't even use the abilities if I don't load the AI script at all, so I don't think it's a problem with the script.
Latest patch, 2.0.1.

Edit: hmmmmmmmmmmmmmmmm ok it seem the hero is using its abilities, but only on heroes. WTF
Edit2: TIL that the AI uses certain abilities only on certain enemies. E.g. Shadow Strike (what the ability here in question is based on) is only used on heroes (and possibly big/strong units). Same for Storm Bolt it seems. This is what the problem was all along with the abilities.
I think that units with the Shadow Strike ability primarily (if not ONLY) use it on heroes.
Same for Firelord's Soul Burn. Once I wanted to make it target non heroic units and the AI would never use the ability.
It uses it only on heroes.
 
I think that units with the Shadow Strike ability primarily (if not ONLY) use it on heroes.
Same for Firelord's Soul Burn. Once I wanted to make it target non heroic units and the AI would never use the ability.
It uses it only on heroes.
Yeah, big bummer. I never noticed it on the melee map this is also used on. I will either have to live with it or remake the ability from scratch.
 
You could trigger it with a dummy ability.
Yeah, can probably do it with Channel or something. But then I have to script the entire thing to replicate shadow strike, including floating text and everything ^^ For now I'll just accept that AI only uses it on heroes lol.

Maybe for campaign purposes it would be easier to make a trigger that forces the hero to use the ability on units. But that's a bit hacky for my tastes.
 
Level 28
Joined
Dec 3, 2020
Messages
969
Yeah, can probably do it with Channel or something. But then I have to script the entire thing to replicate shadow strike, including floating text and everything ^^ For now I'll just accept that AI only uses it on heroes lol.

Maybe for campaign purposes it would be easier to make a trigger that forces the hero to use the ability on units. But that's a bit hacky for my tastes.
You can create a dummy unit, give it shadow strike and order it to use on the target (regardless if it's a unit or hero).

The dummy ability itself could either be an auto-cast, such as faerie fire (ESPECIALLY if ONLY used by the AI), or Channel if used by the player.
 
You can create a dummy unit, give it shadow strike and order it to use on the target (regardless if it's a unit or hero).

The dummy ability itself could either be an auto-cast, such as faerie fire (ESPECIALLY if ONLY used by the AI), or Channel if used by the player.
Hmm yeah, that's a good idea. Then I don't have to mess around with timers and floating text. On the other if I script it from scratch I can make the floating text red lol, but that's probably not worth the effort.
 
Level 28
Joined
Dec 3, 2020
Messages
969
Hmm yeah, that's a good idea. Then I don't have to mess around with timers and floating text. On the other if I script it from scratch I can make the floating text red lol, but that's probably not worth the effort.
Yeah!!!
Also yeah, it isn't really worth the effort in my opinion :xxd: .

Again, my best recommendation if you need to use an auto-cast ability to target enemies: either Slow or Faerie Fire. I always use Faerie Fire though and it works perfectly. Works perfectly with AI too. (Talking about single target spells of course).

For the player, if you don't want an auto-cast ability, then Channel is your best option.

Although I assume you already know this but maybe the Faerie Fire trick might help you out. I will give you an example:
I made an auto-cast Firebolt for the Orc Warlock in some of my maps and I really love how the AI is using it.
They will NOT all cast "Firebolt" on the same unit. They wait like 3-5 seconds until it casting it again on the same unit, which prevents them from sniping said unit to the Nether (and beyond).
I replaced Firebolt with a dummy ability since the AI either only uses it on heroes or on units that are attacking the spellcaster who has the Firebolt ability, which is logical (the latter specifically), but very underwhelming when you want to have a big, chaotic battle.
 
Also yeah, it isn't really worth the effort in my opinion :xxd: .

Again, my best recommendation if you need to use an auto-cast ability to target enemies: either Slow or Faerie Fire. I always use Faerie Fire though and it works perfectly. Works perfectly with AI too. (Talking about single target spells of course).
Probably not haha. Doesn't need to be autocast, so I guess Channel is my best option. But that's good to know about Faerie Fire for the future!
 
Top