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

Unit Invisibility

Status
Not open for further replies.
Level 24
Joined
Aug 1, 2013
Messages
4,657
I dont know if this already exists but in any case, I made this and thought it could also be usefull for other people.

JASS:
library Invisibility initializer Init uses TimerUtils
    
    globals
        
        private unit CASTER
        private integer INVISIBILITY_ORDER = 852069 // OrderId("invisibility")
        private integer BUFF_ID            = 'Binv'
        
        private timer array t
        
    endglobals
    
    private function callback takes nothing returns nothing
        local integer id = GetTimerData(GetExpiredTimer())
        call UnitRemoveAbility(udg_UDexUnits[id], BUFF_ID)
        call ReleaseTimer(t[id])
        set t[id] = null
    endfunction
    
    public function add takes unit whichUnit, real duration returns nothing
        local integer id = GetUnitUserData(whichUnit)
        
        if t[id] == null then
            set t[id] = NewTimerEx(id)
        endif
        
        if GetUnitAbilityLevel(whichUnit, BUFF_ID) == 0 then
            call IssueTargetOrderById(CASTER, INVISIBILITY_ORDER, whichUnit)
            call TimerStart(t[id], duration, false, function callback)
        elseif duration > TimerGetRemaining(t[id]) then
            call TimerStart(t[id], duration, false, function callback)
        endif
    endfunction
    
    private function Init takes nothing returns nothing
        set CASTER = CreateUnit(Player(15), 'uINV', 0, 0, 0)
    endfunction
    
endlibrary

And ofcourse lua object generation:
JASS:
//! externalblock extension=lua ObjectMerger $FILENAME$

//      Create caster:
//! i   setobjecttype("units")
//! i   createobject("hfoo", "uINV")
//! i   makechange(current, "uabi", "Aloc,AINV")
//! i   makechange(current, "ucbs", "0")
//! i   makechange(current, "ucpt", "0")
//! i   makechange(current, "umxp", "0")
//! i   makechange(current, "umxr", "0")
//! i   makechange(current, "umdl", "")
//! i   makechange(current, "uprw", "0")
//! i   makechange(current, "ushu", "")
//! i   makechange(current, "uaen", "0")
//! i   makechange(current, "utar", "invulnerable")
//! i   makechange(current, "umvs", "0")
//! i   makechange(current, "umvr", "0")
//! i   makechange(current, "ufoo", "0")
//! i   makechange(current, "usid", "0")
//! i   makechange(current, "usin", "0")

//      Create ability:
//! i   setobjecttype("abilities")
//! i   createobject("Aivs", "AINV")
//! i   makechange(current, "atat", "")
//! i   makechange(current, "ata0", "")
//! i   makechange(current, "areq", "")
//! i   makechange(current, "abuf", "1", "Binv")
//! i   makechange(current, "aran", "1", "1000000000")
//! i   makechange(current, "atar", "1", "invulnerable,vulnerable")
//! i   makechange(current, "ahdu", "1", "0")
//! i   makechange(current, "adur", "1", "0")
//! i   makechange(current, "amcs", "1", "0")

//! endexternalblock

Simply said, you call "Invisibility_add(myTarget, myDuration)" and your unit will be invisible for that duration.
If you already had another invisibility on that unit that lasts longer, then it will just get ignored.

It uses the standard buff but you can use your own if you like.
You just have to set it in either the object editor or in the lua script and set it in the globals.

(Uses TimerUtils and Bribes Unit Indexer.)
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
He probably means you can remove ability directly instead of removing buff.

Edit: Nevermind, I just realized using invisibility + dummy is correct way of doing it.
 
Status
Not open for further replies.
Top