System Fade System

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
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 you'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
 

Attachments

  • FadeSystem6.0.w3x
    35.8 KB · Views: 263
  • FadeSystem7.0b.w3x
    35.7 KB · Views: 256

Tom Jones

N/A
Reaction score
437
Your not flushing the stored values correctly:
JASS:
    set t = null
    call FlushHandleLocals(t)
It should be flushed here:
JASS:
        endif
            call DestroyTimer(t)
            set t = null
            set whichUnit = null
        endif
You can't flush a nulled variable anyways.

Replace this useless BJ please:
JASS:
PercentTo255(100.00-periodFade))
 
Reaction score
456
Oh god Demi666, you should be -repped for spamming. If I don't see a reason to bump my thread, other users have no reason to do it. Admins and mods are exceptions..

Updated!

Please still there seems to be a problem with flushing, hope you're gonna help a ol' beggar out ;D
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Good job Uber! This could come in handy to many users... But the header functions don't need initTrig functions... :p

+rep

@Demi666: Spamming is bad, and Tom Jones replied 25 minutes before you posted so it was like a semi-bump. -rep, sorry...
 

Pyrogasm

There are some who would use any excuse to ban me.
Reaction score
134
I notice that there's nothing in there that stores a unit's current transparency during the fade. What happens if you fade a unit twice before the first fade has finished?

Maybe you should add a failsafe or something that stores a unit's current transparency so that it doesn't fluctuate randomly if such a thing happens.
 
Reaction score
456
>Maybe you should add a failsafe or something that stores a unit's current transparency so that it doesn't fluctuate randomly if such a thing happens.
I was wondering about the same thing.. But actually it's quite hard, because there is no function like GetUnitTransparency(unit whichUnit) or so.. But I look forward into it.

>This could come in handy to many users... But the header functions don't need initTrig functions... :p
Maybe because Fade System doesn't have to be in the maps header ;D

>Brilliant! Very nice :D.. Especially the new function.
Thanks, I found that very useful when I didn't want to show units death animation.

Off-Topic: Why can't I see smiles on the right side..?
 

Pyrogasm

There are some who would use any excuse to ban me.
Reaction score
134
All you have to do is attach an integer or real to a unit that stores its transparency; assume that when a unit is created, it has 0% transparency.

Then, just change the value every time your system changes a unit's transparency.
 
Reaction score
456
I don't know how to attach values to an unit? Okay.. 0 is the default transparency ;D
 

Pyrogasm

There are some who would use any excuse to ban me.
Reaction score
134
Handle Variables, Structs, or even parallel arrays. I suppose you could use each unit's custom value, too.
 

Pyrogasm

There are some who would use any excuse to ban me.
Reaction score
134
Then I would just use Custom Value. In jass, you use SetUnitUserData(whichUnit, whatNumber).
 
Reaction score
456
Well.. I tried it other way around. I made a global real variable called "transparency", with an array index.

The array of the transparency would be like.. 2 last numbers of the units' handle value, multipled with player number of the owner?

And to get the transparency

JASS:
function GetUnitTransparency takes unit whichUnit returns real
     return udg_transparency[..]
endfunction
 

Pyrogasm

There are some who would use any excuse to ban me.
Reaction score
134
Sorry to be so negative, but that's not going to work.
 

Pyrogasm

There are some who would use any excuse to ban me.
Reaction score
134
As far as I know, handle Ids are somewhat constant, but there are a lot of things that can fuck with them. Additionally, I'm not even sure how you would get a formula for that.

Your best bet (if you want to do it using a global array or two) is to assign each unit that enters the map a specific spot in the array, possibly 2, like so:
JASS:
function SetUnitCustomSlot takes unit whichUnit returns nothing
    local integer i = 0
    loop
        set i = i+1
        if i < 8191 then
            if GetWidgetLife(udg_SomeUnitArray<i>) &lt; 0.406 then
                set udg_SomeUnitArray<i> = whichUnit
                set udg_SomeIntegerArray<i> = 0
                call SetUnitUserData(whichUnit, i)
                exitwhen true
            endif
        else
            if GetWidgetLife(udg_SomeOtherUnitArray[i-8191]) &lt; 0.406 then
                set udg_SomeUnitArray[i-8191] = whichUnit
                set udg_SomeIntegerArray[i-8191] = 0
                call SetUnitUserData(whichUnit, i)
                exitwhen true
            else
                if i &gt; 16382 then
                    call BJDebugMsg(&quot;Error; no space for unit&quot;)
                endif
            endif
        endif
    endloop
endfunction</i></i></i>

But at that point, why not just use Custom Value instead?
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Using custom value would mess other triggers, which use them. A lot of GUIers do use custom values...
 
General chit-chat
Help Users

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top