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

An always Auto-Cast on enemies ability

Status
Not open for further replies.
Level 4
Joined
Jan 27, 2016
Messages
89
I'm looking for an ability that a unit will always autocast when it is near an enemy with the enemy as a target. Frenzy does this but obviously doesn't target the enemy and is self cast. I tried faerie fire but the problem is often times the unit won't cast it until its in melee range and even if the buff lasts .01 seconds it's impossible to get them to cast the ability I need. For the record, I'm trying to create what's basically a charge ability, but using unstable concoction instead, making the unit invulnerable and flying it to the enemy. Triggering every aspect of it is impossible due to the potential performance problems with scale.

Are there any other autocast abilities that can be used for this?
 
Level 12
Joined
Jan 2, 2016
Messages
973
Do you really need an auto-cast spell to do that?
You can solve your problem in more than 1 ways.
The simplest one would be if you know JASS:
Event: A unit enters playable map area
Condition: ---- your conditions (like... is the unit a certain unit-type) ----
Actions: Create a trigger (requires jass), with event "A unit comes in range"
Save the Triggering unit into a hashtable, with a key - the new trigger (still requires jass)
And as actions (technically "conditions") - add the function you want executed when the event runs.
like...
JASS:
local unit charger = LoadUnitHandle(TableName, GetHandleId(GetTriggeringTrigger()), 'unit')
local unit target = GetTriggerUnit()
// do stuff

Another way to do that, which is less eficient, but doesn't require JASS knowledge would be:
make a trigger with no events, that does the stuff you want the happen (something like the trigger you currently have for the 'on spell cast' event)
And every time a unit enters the playable map area, if it's matching your conditions - add an event to the 1-st trigger "A unit comes in range xxx from Triggering unit"
However, using this way - you will be getting the "target" as "Triggering unit", but you woudln't be able to directly tell which is the unit that needs to do the charge. You'd need to group all the units in range from the triggering unit, and check if they are of type 'the type that can charge' (for example). And if more than 1 unit matches that condition - you need to filter somehow which is the correct unit.

ANOTHER way would be to:
Make a periodic event (let's say it runs every 0.1 seconds)
It loops trough a unit group, and for every picked unit - it picks all the units in xxx range from it, and checks if that unit is enemy or ally. If it's enemy - it makes the initially picked unit charge the newly picked one.

You also need to have a trigger "A unit enters playable map area", if it matches your conditions - add the unit to the group the 1-st trigger is looping trough.


DON'T FORGET: to do an extra check to see if the unit hasn't already done that "charge", so it doesn't start charging like crazy :p
 
Level 12
Joined
Nov 3, 2013
Messages
989
Ok, so you're not really looking for an actual auto cast ability, abilities that you can rightclick on and then the unit will use them automatically, like bloodlust, are you?

IIRC Chain Lightning is used at any opportunity by the computer AI, as long as it deals at least 1 damage.
 
Status
Not open for further replies.
Top