- Joined
- Aug 1, 2013
- Messages
- 4,658
I dont know if this already exists but in any case, I made this and thought it could also be usefull for other people.
And ofcourse lua object generation:
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.)
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.)