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

Is Unit invulnerable check

Status
Not open for further replies.
Level 19
Joined
Dec 12, 2010
Messages
2,069
JASS:
function IsUnitCycloned takes unit u returns boolean
	return GetUnitAbilityLevel(u,'Bcyc')>0 or GetUnitAbilityLevel(u,'Bcy2')>0//Bcyc -> Cyclone, Bcy2 -> Cyclone
endfunction

function IsUnitSleeping takes unit u returns boolean
	return (GetUnitAbilityLevel(u,('BUsp'))>0) or (GetUnitAbilityLevel(u,('BUst'))>0)
endfunction

function IsUnitInvulnerable takes unit u returns boolean
	return GetUnitAbilityLevel(u,'Avul')==1 or IsUnitSleeping(u) or IsUnitCycloned(u)
endfunction
 
Level 4
Joined
Feb 12, 2016
Messages
71
But not every magic immune unit is invulnerable.

What happens if you deal damage to an invulnerable unit via trigger? Does it actually deal damage?

If not you could deal a high amount of damage to it ( high to make sure armor and reg doesn't fuck it up) and see if the unit's hp changed afterwards.
If they did not (assuming what I asked above) it should be invulnerable.

Edit: that would kill non-invulnerable units kek, stupid me. Probably could play around with the amount of damage and reset it's ho afterward, but it's a meh solution I guess.
 
Level 19
Joined
Dec 12, 2010
Messages
2,069
just pick the buffs you actually use. I've never used Divine shield for instance. Sure, if blizzard would make a flag for invulnerability, that would be great. But so far..
Dealing damage to invul causes them to receive 0 damage, you could check for that as well, don't forget to exclude this damage from related triggers.
 
Level 12
Joined
Jan 2, 2016
Messages
973
The problem is that I want an attack to hit a random enemy in a region every x seconds.
But if there is an invulnerable enemy - it may absorb that attack, and the attack will be wasted xP
That's why I just want to avoid targetting those.

(By attack I mean a triggered damage + special effect)
 
Level 12
Joined
May 22, 2015
Messages
1,051
What you can do is use a dummy caster to cast an ability on that unit. If the order to cast the ability returns false, the unit was untargetable.

I was gonna suggest this, but you could even do it with a regular attack, couldn't you? Make sure it can hit ground and air and order the dummy to attack. The rest is the same.
 
Level 22
Joined
Feb 6, 2014
Messages
2,466
I was gonna suggest this, but you could even do it with a regular attack, couldn't you? Make sure it can hit ground and air and order the dummy to attack. The rest is the same.

But what if the unit is in ethereal form? Bribe's dummy caster suggestion is the best way to go. It's best to make the ability based on Channel with Universal Cast set to true and Targets Allowed not including Invulnerable units.
 
Last edited:
Level 12
Joined
May 22, 2015
Messages
1,051
But what if the unit is in ethereal form? Bribe's suggestion is the best way to go. It's best to make the ability based on Channel with Universal Cast set to true and Targets Allowed not including Invulnerable units.

Ah right. I forgot about ethereal lol.
 
Level 13
Joined
Mar 19, 2010
Messages
870
You can use my script if u want.

JASS:
library InvulnerabilityDetector initializer init
// ------------------------------------------------------------
//                          Invulnerability Detector
//
// Version: 1.1.2
// Author: Touko-Aozaki
// Contact: [email][email protected][/email]
// [url]http://touko.pe.kr[/url]
// ------------------------------------------------------------
// How to use:
// use function IsUnitInvulnerable(unit) to find out whether
// the unit is invulnerable or not.
// ------------------------------------------------------------
//                          CHANGELOGS
// [1.1.2]
// Changed name of the library. (won't cause incompatibility as there are no public functions)
// [1.1.1]
// Wards and invisible units are now properly handled.
// [1.1.0]
// Reduced ObjectMerger dependencies; custom dummy is no longer
// used.
// ------------------------------------------------------------
//! external ObjectMerger w3a Afod inv& anam "Invulnerability Detector" aart "" aani "" acat "" aeat "" atat "" alig "" amat "" atar 1 "air,ground,structure,vulnerable,ward" acas 1 3600 amcs 1 0 aran 1 99999.0 aher 0 alev 1 Nfd3 1 0 Nfd1 1 0 Nfd2 1 0.01 arac "other" atp1 1 "" aub1 1 "" ansf ""
    
    globals
        private constant integer INV_DETECTOR_CODE      = 'inv&'
        private constant string INV_DETECTOR_ORDERSTR   = "fingerofdeath"
        private constant integer DUMMY_UNIT_CODE        = 'nshe'
        private unit dummy
    endglobals
    
    function IsUnitInvulnerable takes unit whichUnit returns boolean
        local boolean result = false // default false
        
        if whichUnit != null and GetUnitTypeId(whichUnit) != 0 then
            // target is valid
            call PauseUnit(dummy, false) // unlock to test the order
            if not IsUnitVisible(whichUnit, Player(15)) then
                // make sure not to affect any possible game states
                call UnitShareVision(whichUnit, Player(15), true)
                set result = not IssueTargetOrder(dummy, INV_DETECTOR_ORDERSTR, whichUnit)
                call UnitShareVision(whichUnit, Player(15), false)
            else
                set result = not IssueTargetOrder(dummy, INV_DETECTOR_ORDERSTR, whichUnit)            
            endif
            call PauseUnit(dummy, true) // lock the unit;
        endif
                        
        return result
    endfunction
    
    private function init takes nothing returns nothing
        set dummy = CreateUnit(Player(15), DUMMY_UNIT_CODE, 0, 0, bj_UNIT_FACING)
        call UnitAddAbility(dummy, INV_DETECTOR_CODE)
        call ShowUnit(dummy, false) // makes any unit-type eligible for a dummy
        call PauseUnit(dummy, true) // hiding the unit doesn't prevent triggering the event
    endfunction
endlibrary
 
Level 9
Joined
Jul 30, 2012
Messages
156
Just take a look at how many things in the game can provide invulnerability:
attachment.php
Unless you can drastically reduce the amount of things in your map that will make a unit invulnerable, the only reliable way to detect that state is indeed with a dummy caster.

Checking if the unit is magic immune is usually enough, as every invulnerable unit is also magic immune.

This is not always true. Some sources of invulnerability, like Voodoo and Divine Shield, do make a unit magic immune, while others, like 'Avul', don't.
 

Attachments

  • Invulnerable.png
    Invulnerable.png
    120.5 KB · Views: 511
Status
Not open for further replies.
Top