Wc3C.net

Wc3C.net (http://www.wc3c.net/forums.php)
-   Scripts (http://www.wc3c.net/forumdisplay.php?f=737)
-   -   Invulnerability Detector (http://www.wc3c.net/showthread.php?t=103889)

ToukoAozaki 01-01-2009 03:36 PM

Invulnerability Detector
 
2 Attachment(s)
This is an invulnerability detector library. Uses finger of death as a dummy ability, and won't fire any order events.

Simply check the return value of IsUnitInvulnerable(unit).

Collapse JASS:
library InvulnerabilityDetector initializer init
// ------------------------------------------------------------
//                          Invulnerability Detector
//
// Version: 1.1.2
// Author: Touko-Aozaki
// Contact: nes1209@hotmail.com
// http://touko.pe.kr
// ------------------------------------------------------------
// 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

Demo map attached. You can test with a set of settings, units and spells. (invisible, ward, structures, normal units, heroes, etc.)
Tips for comparison with GetUnitAbilityLevel method:
Blademaster: Mirror Image (use upper-left buttons to select while casting)
Shadow Hunter: Big Bad Voodoo
Phoenix: At the point of death; while morphing into an egg.
Paladin: Divine Shield
Crypt Lord: Impale (target units are temporarily invulnerable)

* Testmap updated; you can now see every issued order on the screen.

Troll-Brain 01-01-2009 03:43 PM

Collapse JASS:
return GetUnitAbilityLevel(<yourUnit>,'Avul')>0
is not enough ?

And at least if the unit witchUnit is null, it will return true.

It will also return true if the unit is not visible for Player(15)

chobibo 01-01-2009 04:49 PM

Collapse JASS:
return GetUnitAbilityLevel(<yourUnit>,'Avul')>0

Last time I checked, it doesn't work for SetUnitInvulnerable.

EDIT: It works! lol.

Troll-Brain 01-01-2009 05:03 PM

You should test again.

chobibo 01-01-2009 05:23 PM

I just checked it, it works.

Rising_Dusk 01-01-2009 07:57 PM

I am sorry, but this is utterly useless, so I am graveyarding it. We have IsUnitInvulnerable for a reason. And yes, chobibo, it works with SetUnitInvulnerable since it uses 'Avul' internally.

ToukoAozaki 01-02-2009 10:01 AM

Quote:

Originally Posted by Rising_Dusk
We have IsUnitInvulnerable for a reason.


What do you mean? I really don't get what you're saying.

Quote:

Originally Posted by Rising_Dusk
And yes, chobibo, it works with SetUnitInvulnerable since it uses 'Avul' internally.


Checking 'Avul' works for most cases, but not so much reliable. Ofc it works with neutral building with the ability and units set by SetUnitInvulnerable, but I've tested and found out some cases that don't work well with it. It seems that the presence of 'Avul' cannot tell much about spell-driven invulnerabilities (e.g. Divine Shield, Big Bad Voodoo, Phoenix morphing to an egg).

Anitarf 01-02-2009 01:50 PM

Well, I'll move this back to resource submissions so the discussion about the code's usefulness can be resolved.

Also, couldn't you just keep the unit permanently paused, instead of pausing and unpausing it each time?

ToukoAozaki 01-02-2009 03:16 PM

Quote:

Originally Posted by Anitarf
Also, couldn't you just keep the unit permanently paused, instead of pausing and unpausing it each time?


While writing the code, I thought about that idea because I didn't want to trigger any events. However, when I tested it, it didn't work properly; it later turned out that ordering paused units always returned false. Then I just guessed wild and tried what it is now; it finally worked.

Vexorian 01-02-2009 04:19 PM

Is there a case in which (GetUnitAbilityLevel(u,'Avul')>0) returns false while this method doesn't?

If there isn't, this function should probably be graveyarded or modified to just check the level for 'Avul'.

Troll-Brain 01-02-2009 04:56 PM

As he said it doesn't work for the invulnerable spells.
So the other way is to check all invulnerable custom and native buffs, but personnaly i will use this i think ...

@ToukoAozaki : I have tested myself, but you should add a demo witch prove why your script is usefull, and why GetUnitAbilityLevel(u,'Avul')>0 is not enough.

Rising_Dusk 01-02-2009 07:38 PM

Quote:

Originally Posted by Vexorian
Is there a case in which (GetUnitAbilityLevel(u,'Avul')>0) returns false while this method doesn't?

Just the hardcoded cases based upon Divine Shield. It's not like you couldn't just check for that buff or something if a given mapmaker is ridiculous enough to use that instead of triggering it. This is still in the exact same position it was before, it is not useful.

Troll-Brain 01-02-2009 08:00 PM

Quote:

Originally Posted by Rising_Dusk
Just the hardcoded cases based upon Divine Shield. It's not like you couldn't just check for that buff or something if a given mapmaker is ridiculous enough to use that instead of triggering it. This is still in the exact same position it was before, it is not useful.

It's not only hardcoded based upon Divine shield but all abilities custom or natives with a different Invulnerable buff.

So you can inline it with checking all the invulnerable buff, but you have to made this for all custom maps.
But imho only if you have really to care about speed.

With this solution you don't need to care about it.

Rising_Dusk 01-02-2009 08:18 PM

Quote:

Originally Posted by Troll-Brain
It's not only hardcoded based upon Divine shield but all abilities custom or natives with a different Invulnerable buff.

There are no other natives. And what other custom abilities, huh?

Troll-Brain 01-02-2009 08:22 PM

I mean all original spells like ToukoAozaki said.
And if for some reason you use a custom buff it will also fail.

EDIT : But as i said he should make a demo map witch prove this fact.


All times are GMT. The time now is 05:12 AM.

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services