• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Spell] Best way to trigger AI heroes to use custom spells

Status
Not open for further replies.
Level 14
Joined
Mar 27, 2008
Messages
1,003
So basically I'm working on a hero arena map. I made the AI entirely via triggers instead of the AI editor. Only problem I'm having is that I have no clue about the best way to make a hero use a spell whenever an enemy gets close. Could someone help me with this?
 
Level 11
Joined
Jun 2, 2013
Messages
613
Well, a good place to start is: http://www.hiveworkshop.com/forums/...ustom-spells-cast-melee-game-ai-units-193280/

This will at least help you base some your spells off of ones the AI will cast without any triggering - though I'm not sure if this will still work if your AI is based in triggers. I think it should work though because according to that post there is underlying code running in the background that dictates the casting.

Alternatively you can use the "Unit - Unit Within Range" Event, but this would require you to set the unit you want to cast the ability within a variable.
 
Level 14
Joined
Mar 27, 2008
Messages
1,003
Well, a good place to start is: http://www.hiveworkshop.com/forums/...ustom-spells-cast-melee-game-ai-units-193280/

This will at least help you base some your spells off of ones the AI will cast without any triggering - though I'm not sure if this will still work if your AI is based in triggers. I think it should work though because according to that post there is underlying code running in the background that dictates the casting.

Alternatively you can use the "Unit - Unit Within Range" Event, but this would require you to set the unit you want to cast the ability within a variable.

In all honesty this is what I would prefer to use, but therein lies another problem I have.
How do I automatically make AI heroes learn skills as they level up?
 
Level 18
Joined
Nov 21, 2012
Messages
835
Im using pointValue (pv) diffrent for each hero-type.
Then set your abilities to variables, I call them Skill1, Skill2 etc.. integer array:

JASS:
set udg_Skill1[pv] = 'Amls'
set udg_Skill2[pv] = 'Ainf'
set udg_Skill3[pv] = 'something'
set udg_Skill4[pv] = 'something'

here you have trigger I use for learn abilities for AI:
JASS:
function Trig_SPHeroLevelUp_Conditions takes nothing returns boolean
local integer i= GetPlayerId(GetOwningPlayer(GetLevelingUnit()))

if GetPlayerController(Player(i))==MAP_CONTROL_COMPUTER then
    call SelectHeroSkill(udg_Hero[i+1], udg_Skill4[GetUnitPointValue(udg_Hero[i+1])])
    call SelectHeroSkill(udg_Hero[i+1], udg_Skill1[GetUnitPointValue(udg_Hero[i+1])])
    call SelectHeroSkill(udg_Hero[i+1], udg_Skill2[GetUnitPointValue(udg_Hero[i+1])])
    call SelectHeroSkill(udg_Hero[i+1], udg_Skill3[GetUnitPointValue(udg_Hero[i+1])])
endif

return false
endfunction

//===========================================================================
function InitTrig_SPHeroLevelUp takes nothing returns nothing
    set gg_trg_SPHeroLevelUp = CreateTrigger(  )
    call DisableTrigger( gg_trg_SPHeroLevelUp )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SPHeroLevelUp, EVENT_PLAYER_HERO_LEVEL )
    call TriggerAddCondition( gg_trg_SPHeroLevelUp, Condition( function Trig_SPHeroLevelUp_Conditions ) )
endfunction
dont worry with those "i+1" cause I switch from gui and was to lazy to edit all map for these integers :D
zibi
 
Level 14
Joined
Mar 27, 2008
Messages
1,003
Im using pointValue (pv) diffrent for each hero-type.
Then set your abilities to variables, I call them Skill1, Skill2 etc.. integer array:

JASS:
set udg_Skill1[pv] = 'Amls'
set udg_Skill2[pv] = 'Ainf'
set udg_Skill3[pv] = 'something'
set udg_Skill4[pv] = 'something'

here you have trigger I use for learn abilities for AI:
JASS:
function Trig_SPHeroLevelUp_Conditions takes nothing returns boolean
local integer i= GetPlayerId(GetOwningPlayer(GetLevelingUnit()))

if GetPlayerController(Player(i))==MAP_CONTROL_COMPUTER then
    call SelectHeroSkill(udg_Hero[i+1], udg_Skill4[GetUnitPointValue(udg_Hero[i+1])])
    call SelectHeroSkill(udg_Hero[i+1], udg_Skill1[GetUnitPointValue(udg_Hero[i+1])])
    call SelectHeroSkill(udg_Hero[i+1], udg_Skill2[GetUnitPointValue(udg_Hero[i+1])])
    call SelectHeroSkill(udg_Hero[i+1], udg_Skill3[GetUnitPointValue(udg_Hero[i+1])])
endif

return false
endfunction

//===========================================================================
function InitTrig_SPHeroLevelUp takes nothing returns nothing
    set gg_trg_SPHeroLevelUp = CreateTrigger(  )
    call DisableTrigger( gg_trg_SPHeroLevelUp )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SPHeroLevelUp, EVENT_PLAYER_HERO_LEVEL )
    call TriggerAddCondition( gg_trg_SPHeroLevelUp, Condition( function Trig_SPHeroLevelUp_Conditions ) )
endfunction
dont worry with those "i+1" cause I switch from gui and was to lazy to edit all map for these integers :D
zibi

Thank you so much for the help!
I have no clue at all how to write JASS so this has been a massive help + Rep
Will work just fine.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,188
You periodically run a "tactical AI" function on the unit. This is basically a function which looks for the conditions to cast abilities (eg enemy units nearby). If the AI is not in combat you can lower the poll rate to every 10-15 seconds. In combat a good rate would be every second. Obviously if the unit is dead you do not run at all.
 
Status
Not open for further replies.
Top