- Reaction score
- 456
FADE SYSTEM 7.0b
This is a system that allows you to fade a unit by using your own settings.
The whole system is in one trigger, with an instructions in another trigger.
Instructions
System Trigger
The Map
This is a system that allows you to fade a unit by using your own settings.
The whole system is in one trigger, with an instructions in another trigger.
Instructions
JASS:
****************************************************************
* FADE SYSTEM 7.0b *
* * * * * *
* by: Überplayer *
****************************************************************
Implement:
This version requires ABC system by Cohadar, so copy the
"ABC" trigger into your map. Then you can copy the "Fade System"
trigger into your map. And you039;re ready!
________________________________________________________________
----------------------------------------------------------------
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
How to use:
call FadeUnit(unit whichUnit, real transFrom, real transTo, real duration, code callback)
1."whichUnit" is the unit you fade.
2."transFrom" is the transparency where the unit fades from.
3."transTo" is the transparency where the unit fades to.
4."duration" is the duration how long the fading lasts.
5."callback" is the action which is ran after fading is finished.
call GetFadedUnit()
When used in the callback action, it returns the faded unit.
Store this unit to a local variable in the callback, before
using any waits.
________________________________________________________________
----------------------------------------------------------------
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
History:
Version 1.0
¯¯¯¯¯¯¯¯¯¯¯
-First version.
Version 1.2
¯¯¯¯¯¯¯¯¯¯¯
-Added a part to the code, which prevents fading dead units.
Version 1.3
¯¯¯¯¯¯¯¯¯¯¯
-Added new argument, "removeAfterFade", which allows the user
to remove the fading unit after it has faded.
Version 1.3b
¯¯¯¯¯¯¯¯¯¯¯
-Handle variables are now flushed correctly.
-Made few minor changes to the code.
Version 2.0
¯¯¯¯¯¯¯¯¯¯¯
-Fully rewrote the code.
-System uses vJass, so NewGen is needed.
Version 2.0b
¯¯¯¯¯¯¯¯¯¯¯
-Fixed serious bug in the execution of the system.
-Dead units no longer fade, as they did after version 2.0.
Version 3.0
¯¯¯¯¯¯¯¯¯¯¯
-Fully rewrote the code.
-Changed order of the arguments.
-There is still a bug when same unit is faded repeatedly.
Version 4.0
¯¯¯¯¯¯¯¯¯¯¯
-Fully rewrote the code.
-Replaced "minimumFade" argument with "percentFrom" and "percentTo"
arguments.
-Removed "removeAfterFade" argument.
Version 5.0
¯¯¯¯¯¯¯¯¯¯¯
-There was one, but not public version
Version 6.0
¯¯¯¯¯¯¯¯¯¯¯
-Requires ABC (by Cohadar)
-Added "code callback" argument, which is ran after fade is finished.
-Added GetFadedUnit() function, which can be used in the callback action to get the faded unit.
Version 7.0
¯¯¯¯¯¯¯¯¯¯¯
-Rewrote the code, because it looked not made by me.
-Fixed few rare bugs
Version 7.0b
¯¯¯¯¯¯¯¯¯¯¯
-Renamed some arguments and variables
System Trigger
JASS:
//v7.0b
library FadeSystem uses ABC
globals
//Period of the timer
private constant real PERIOD = 0.03125
private unit bj_fadedUnit
endglobals
private struct Data
unit whichUnit
real transFrom
real transTo
real duration
triggeraction callbackAction
trigger callbackTrigger = CreateTrigger()
timer fadeTimer = CreateTimer()
integer ticks
real curFade = 0.00
real fadeInc
static method create takes unit whichUnit, real transFrom, real transTo, real duration, code callback returns Data
local Data dat = Data.allocate()
set dat.whichUnit = whichUnit
set dat.transFrom = transFrom
set dat.transTo = transTo
set dat.duration = duration
if callback != null then
set dat.callbackAction = TriggerAddAction(dat.callbackTrigger, callback)
endif
if (dat.transFrom < 0.00) then
set dat.transFrom = 0.00
elseif (dat.transFrom > 100.00) then
set dat.transFrom = 100.00
endif
if (dat.transTo < 0.00) then
set dat.transTo = 0.00
elseif (dat.transTo > 100.00) then
set dat.transTo = 100.00
endif
if dat.transFrom > dat.transTo then
set dat.fadeInc = ((dat.transFrom - dat.transTo) / dat.duration) * PERIOD
else
set dat.fadeInc = ((dat.transTo - dat.transFrom) / dat.duration) * PERIOD
endif
call SetTimerStructA(dat.fadeTimer, dat)
set dat.ticks = R2I(dat.duration / PERIOD)
return dat
endmethod
method onDestroy takes nothing returns nothing
call ClearTimerStructA(.fadeTimer)
call PauseTimer(.fadeTimer)
call DestroyTimer(.fadeTimer)
if .callbackAction != null then
set bj_fadedUnit = .whichUnit
call TriggerExecute(.callbackTrigger)
endif
call TriggerRemoveAction(.callbackTrigger, .callbackAction)
call DestroyTrigger(.callbackTrigger)
endmethod
endstruct
function GetFadedUnit takes nothing returns unit
return bj_fadedUnit
endfunction
private function FadeUnit_handler takes nothing returns nothing
local timer t = GetExpiredTimer()
local Data dat = GetTimerStructA(t)
if dat.ticks <= 0 then
call dat.destroy()
else
set dat.ticks = dat.ticks - 1
if dat.transFrom > dat.transTo then
set dat.curFade = dat.curFade + dat.fadeInc
call SetUnitVertexColor(dat.whichUnit, 255, 255, 255, R2I(PercentToInt(dat.transFrom - dat.curFade, 255)))
elseif dat.transFrom < dat.transTo then
set dat.curFade = dat.curFade + dat.fadeInc
call SetUnitVertexColor(dat.whichUnit, 255, 255, 255, R2I(PercentToInt(dat.transFrom + dat.curFade, 255)))
endif
endif
set t = null
endfunction
function FadeUnit takes unit whichUnit, real transFrom, real transTo, real duration, code callback returns nothing
local Data dat = Data.create(whichUnit, transFrom, transTo, duration, callback)
call TimerStart(dat.fadeTimer, PERIOD, true, function FadeUnit_handler)
endfunction
endlibrary
The Map