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

[AI] Writing an autocast AI for abilities

Status
Not open for further replies.

Ardenian

A

Ardenian

I quickly looked through some AI tutorials, but I don't get how I can write an AI for autocasting.
My aim is to make player-owned units automatically cast spells.

My current approach is to add all units of a type ( e.g. priest) to a unit group,
then periodically looping through all units of this unit group,
checking if they have enough mana and all other conditions are met ( like already has buff)
and then ordering the unit to cast the spell.

Is this how I write a good AI ?
I do not use the AI Editor, do I ?
 
Level 18
Joined
Nov 21, 2012
Messages
835
My aim is to make player-owned units automatically cast spells.
If so, you do not need to touch Ai Editor. I prefer ai scripts over Ai Editor, and those are related to computer slots only /Map scenario/player properties/. I can suggest JassCraft to write ai script file and them import file into your map.

But if you have not used slots you can use these slots to change owner of units to computer /allied to player/ and use simpler way to cast custom spells:
http://www.hiveworkshop.com/forums/jass-ai-scripts-tutorials-280/base-abilities-custom-spells-cast-melee-game-ai-units-193280/
so build-in Ai will make part of work instead of your triggers
 

Ardenian

A

Ardenian

Thanks, I see, that's interesting to work with.

I take a look on the test map, up to now I don't see how the AI determinates events.

I would also be glad to receive a comment on my idea to write triggers using unit groups for each unit type.
From my perspective this allowes heavy customization instead of using Ai scripts, using global variables, doesn't it ?
 
Level 18
Joined
Nov 21, 2012
Messages
835
In my opinion coding every aspect of unit behavior is fine for heroes.
But that's ok if you want to try it for units, heavy customizatiot: true, but heavy work also ;]

Instead of periodical ForGroup call you can catch fake-ability casted and reorder your priest to cast something else. Thats the idea.
how the AI determinates events.
well lets assume your priest has fake Rain of Fire, then you know when it will be casted - Will cast if there are at least 2 to 3 units in a group. when priest start effect of an ability /here's event/ you reorder priest to cast something else.
So no need to periodical check for enemies around, how many enemies, how close they are, etc., you intercept the event and reorder. Saves much code.

Or Finger of Death - Uses whenever is available very usefull, is casted by Ai on every cooldown, on any enemy.Please notice that you have to set cooldowns of fake, and real abilites, target allowed for both, mana.
 

Ardenian

A

Ardenian

So I basically make use of the already coded behaviour.
However, what if I would like to code the behaviour from the very beginning, 100% scratch ?
I read in the linked tutorial one does not need to code what already runs in the background,
however, I aim to code AI from the very beginning, including events/checks and the fake-abilities you mention.

About these fake-abilities, aren't they shown, too ?
If priest for example has Rain of Fire, isn't the user able to cast that.
Even if it triggers the heal, wouldn't the user be able to cast both abilities manually ?
 

Ardenian

A

Ardenian

Oh, I see, then it would work, of course.
I aim for player controlled units though.

I aim for creating a ( for now) melee AI.
Players can control the units and cast abilities manually, however, I would like to script abilities,
as example, making the paladin cast Divine Shield himself under certain circumstances and so on.
So it is less an AI like 'a playing computer player' but rather 'make units cast abilities themselves which they usually do not cast themselves'.
 
Now I wonder how are you going to manage AoE spells and check for immunities :)

Because, for example, Unit A has Storm Bolt and attempts to cast it on Invulnerable unit, that may cause malfunction

for AoE spells, they just check the valid number of units for it to cast e.g. Shockwave usually procs when it is available and there are 2+ units in front of the unit
 

Ardenian

A

Ardenian

Yes, requirements are surely a challenge :/

As for AoE spells, as you said, a simple loop through all nearby units counting valid ones in seperate groups should be fine, I would say.

Probably would need to trigger each spell, for example, using a DDS to check if a Footman receives Pierce damage, ordering him to Defend and such.
 
Yes, requirements are surely a challenge :/

As for AoE spells, as you said, a simple loop through all nearby units counting valid ones in seperate groups should be fine, I would say.

Probably would need to trigger each spell, for example, using a DDS to check if a Footman receives Pierce damage, ordering him to Defend and such.

That's if you can detect what is the attack type of the damage ;)
 

Ardenian

A

Ardenian

Oh wait, one cannot detect the attack type of the damage ?
I already searched a bit around in the Jass natives, but I couldn't really find a way to get it or I missed something..

I wonder, if it is not possible to get the attack type, how does the default AI knows when to activate Defend ?
Don't tell me they just activate it stupidely once they are in combat, haha...
 
Oh wait, one cannot detect the attack type of the damage ?
I already searched a bit around in the Jass natives, but I couldn't really find a way to get it or I missed something..

I wonder, if it is not possible to get the attack type, how does the default AI knows when to activate Defend ?
Don't tell me they just activate it stupidely once they are in combat, haha...

yes you can't detect it.

the detection of Pierce damage should've been hardcoded
 

Ardenian

A

Ardenian

Hm, I recall someone tried to write a system to get the attack type based on the damage dealt, was that dropped ?
 

Ardenian

A

Ardenian

Hu, it is a long time ago and I don't think it was a stand-alone thread.
If I recall right they speculated whether they can, since they can get the armor of a unit using the damage received, also the attack type this way.
 
Status
Not open for further replies.
Top