[Spell] Help making permanent invisibility that deactivates when too close to enemy

Status
Not open for further replies.
Level 2
Joined
Oct 1, 2023
Messages
4
So the concept is for a T3 unit that's sneaky but can't get too close to enemies without getting spotted.

I figured a Permanent Invisibility that deactivates when using abilities combined with a phoenix fire with no effects or damage would do the trick since the Fire would activate when the invisible unit got close to an enemy and thus deactivate the invisibility, but it doesn't work.

Any ideas? I'd like to avoid using triggers as much as possible.

Thank you very much for your help.
 
Level 29
Joined
Sep 26, 2009
Messages
2,594
I don't think you will be able to avoid triggers.

I tried giving the following abilities to the unit with perma invis:
  • Permanent Immolation - didn't work - the effect of this spell is disabled as long as the unit is invisible
  • Building Damage Aura (Tornado) - didn't work - the aura damages nearby units, but it does not force the unit out of invis
I thought of two possible solutions, both including triggers:

Option #1
Give the 'Building Damage Aura' to T3 units and via triggers detect when unit is about to take damage (for example via Bribe's DDS, or using native damage events if you are on Reforged).
If unit is about to take damage and the damage source is the T3 unit, attack type is 'spells', damage type is 'force' and the damage amount +- matches what is in object editor, then it's most likely damage caused by the aura, in which case you can remove the Permanent Invisibility (or replace it for the 'Ghost (Visible)' ability)

Option #2
You would place all those T3 units into unit group and have a trigger that periodically checks if there are any enemy units nearby each T3 unit.
Basically, for given T3 unit you would pick all units within X range that are enemies and use the following condition:
  • (Your_T3_unit is masked to (Owner of (Matching unit)).) Equal to False
What the condition checks is if given player has line of sight to 'your_t3_unit', irrespective of whether it is or is not invisible.
If any enemy unit was picked, then your unit is close enough to the enemy and the enemy could see you if you were visible, so in that case you can remove Permanent Invisibility.

--
As for regaining invisibility, for both options you would need to keep track of visible T3 units and keep track of how long it has been since each of those units last dealt damage via the damage aura (#1) or was visible to enemy in range (#2) and if enough time passed, you would add back the Permanent Invisibility


--
Edit:
Generally, I would advise using option #2.
Since option #1's aura deals damage then it would cause units to flee, which is for example the default behavior for idle workers - that may not be wanted behavior in your map
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Here's #2, with a slight twist in design to hopefully improve performance a bit. You'll need the latest patch to open the map.

It's using a system that I made for easing the use of timers in GUI. The idea is to give each stealth unit their own timer rather than have them all check for nearby enemies at the same exact time. This will hopefully improve performance when say 50 of these units are on the map at once since you won't be doing 50 "Pick Every Unit" checks in the same game frame and will instead process it over the course of many frames (assuming these 50 units didn't all spawn in at the same time). I can't say for certain but I imagine that 50 timers is a worthwhile tradeoff for avoiding a massive one-frame calculation.
But it may have been better to just stick with the single Unit Group approach :peasant-thinking:
 

Attachments

  • Stealth 1.w3m
    34.2 KB · Views: 15
Last edited:
Status
Not open for further replies.
Top