• 🏆 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!

How to make AI cast spells.

Status
Not open for further replies.
Level 13
Joined
Oct 16, 2010
Messages
731
So for my lil hero map I'm adding in some AI and so far I'm happy with it. But problem is that I've got some custom spells which they obviously won't use of which defeats the object of having the spells in the first place!!!

I've only got 2 custom spells both which are based on Charm and do damage to the target area.

I'm also wondering how to get heroes to cast spells they normally wouldn't cast. For example; one hero has Absorb Mana but won't use it because the condition normally is for the unit/hero to have 0 mana, which isn't going to happen.

Cheers people! :D
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
You'll have to make the AI yourself via trigger editor - like a periodic loop if you want, or when your hero attacks, you check how many enemies are nearby the attacked unit, and so on, because it's just like you wrote - their base AI has different conditions to when to use those abilities.
 
Level 15
Joined
Oct 29, 2012
Messages
1,474
Unit - Order Unit to ....
If the spell is Target point , Choose the based ability and choose target
If the spell is Target Unit , Choose the based ability and choose target , too
If the spell is instant and has no target , Choose based ability and issue order
If the spell....
That's all lol
 
Level 18
Joined
May 11, 2012
Messages
2,103
When the unit is attacked, order him to cast spell (on the attacker if target unit)
Every 1.00 seconds, pick units around the hero (matching (conditions when you want it to cast spell if it's AoE spell)) and order it to cast (This way my AI is working)

Etc....
There's many ways.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
The AI uses abilities independently of if they are custom or not. This an AoE damage ability based off Thunder Clap will be automaticly casted correctly by the AI with no triggering needed. The problem comes from using standard abilities outside of their original targets (eg, storm bolt as a healing ability on allies) or abilities the AI never casts (Death Pact). Only those abilities you need to script into your custom AI.
 
BTW on the AI topic, try looping every 0.11 seconds of game time and increase a counter by 1 every time. Check if the Player[Couter] controller is computer. Most likely you should have an 'AITarget' variable, an arrayed unit for the AI. Check if the target is alive, if it's ok, if it's out of range, enemies nearer than it, etc. Treat it with care so it may kill the target.

Check if the AOE is outnumbered both in long-range and in melee range so it flees in a no-win situation. Give it a counter to specific abilities. For example, somebody casts Impale. Try make the AI dodge it by moving to the left/to the right.
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
JASS:
function PolledWait takes real duration returns nothing
    local timer t
    local real  timeRemaining
    if (duration > 0) then
        set t = CreateTimer()
        call TimerStart(t, duration, false, null)
        loop
            set timeRemaining = TimerGetRemaining(t)
            exitwhen timeRemaining <= 0
            // If we have a bit of time left, skip past 10% of the remaining
            // duration instead of checking every interval, to minimize the
            // polling on long waits.
            if (timeRemaining > bj_POLLED_WAIT_SKIP_THRESHOLD) then
                call TriggerSleepAction(0.1 * timeRemaining)
            else
                call TriggerSleepAction(bj_POLLED_WAIT_INTERVAL)
            endif
        endloop
        call DestroyTimer(t)
    endif
endfunction
It is the game time wait.
Better use periodic timer ;)
 
Status
Not open for further replies.
Top