Jesus4Lyf
Good Idea™
- Reaction score
- 397
Stack Safety
(Snippet Pack)
Requirements:
- Jass NewGen
- AIDS (required by all)
Overview Description:
This is essentially a snippet pack based on recording the level of certain things so that they are not prematurely removed due to poor multi-instancability in the native functions. Released by request.
Pause Safety:
JASS:
library PauseSafety uses AIDS
private struct UnitData extends array
//! runtextmacro AIDS()
integer pauseLevel
private method AIDS_onDestroy takes nothing returns nothing
set this.pauseLevel=0
endmethod
endstruct
function SafePause takes unit whichUnit, boolean flag returns nothing
local UnitData dat=UnitData[whichUnit]
if flag then
set dat.pauseLevel=dat.pauseLevel+1
call PauseUnit(whichUnit,true)
else
set dat.pauseLevel=dat.pauseLevel-1
if dat.pauseLevel<=0 then
call PauseUnit(whichUnit,false)
set dat.pauseLevel=0
endif
endif
endfunction
endlibrary
Invulnerability Safety:
JASS:
library InvulnerableSafety uses AIDS
private struct UnitData extends array
//! runtextmacro AIDS()
integer invulnLevel
private method AIDS_onDestroy takes nothing returns nothing
set this.invulnLevel=0
endmethod
endstruct
function SafeInvulnerable takes unit whichUnit, boolean flag returns nothing
local UnitData dat=UnitData[whichUnit]
if flag then
set dat.invulnLevel=dat.invulnLevel+1
call SetUnitInvulnerable(whichUnit,true)
else
set dat.invulnLevel=dat.invulnLevel-1
if dat.invulnLevel<=0 then
call SetUnitInvulnerable(whichUnit,false)
set dat.invulnLevel=0
endif
endif
endfunction
endlibrary