HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

FadeUnitSystem (FUS)

06-20-2009, 10:12 PM#1
Jimmy
Hey there,

this is my first (v)Jass System and I want some feedback, if possible.
Please no "omg you n00b" ^^ I know its a temptation :D

This System requires PUI from Cohadar
Collapse JASS:
library Fade initializer Init_Fade requires PUI
// --- FadeUnitSystem (FUS) by Jimmy --- //
//  Requirements:
//      *PUI
//      *JNGP 
//
//  Setup:
//      (Currently not available. Will add something when I have the time.)
//
//  Purpose:
//      *This is a system to prevent Units from Spawning/Removing without 
//       any effect. I hate the way blizzard spawns units!
// 
//  How to use:
//      There are 4 functions in this script:
//          function UnitFadeOutSimple takes unit whichUnit returns nothing
//          -- Fades out the given unit over 1 second. Looks better than
//             simply removing the unit. REMOVES THE UNIT AT THE END OF FADING!
//      
//          function UnitFadeInSimple takes unit whichUnit returns nothing
//          -- Fades in an existing unit over 1 second. You don't have to
//             change the starting alpha-value to 0.
//
//          function UnitFadeOutComplex takes unit whichUnit, integer afterTimeInMs returns nothing
//          -- Does the same as UnitFadeOutSimple but with a delay (given in ms). 
//             YOU CAN USE THIS IN FORGROUP AND LOOPS!
//
//          function UnitFadeInComplex takes unit whichUnit, integer afterTimeInMs returns nothing
//          -- Does the same as UnitFadeInSimple but with a delay (given in ms).
//             YOU CAN USE THIS IN FORGROUP AND LOOPS!
//
//  Pros:
//      *Better Effect than standard-blizzard-removing/-spawning.
//      *Uses no Unique resources and is full MUI.
//      *You can use this system for special-effect-dummys and buildings, too.
//      *Easy to use.
//      *Low-Performance
//      *Uses no return-bug :)
//
//  Cons:
//      *Needs PUI to be implemented.
//      *Currently no Options. Will add then later.
//      *The Shadows are not influenced by fading. Only from removing. :(
//      *Don't know more. Give feedback to increase this list ;)
//
//  System:
//      The system itself is extreme easy-going.
//      All it does is changing the vertex-coloring in .01 sec steps for all units in the saved groups.
//      The groups are made of given units from the function described at top.
//
//  Thanks to:
//      *Cohadar for his brilliant PUI-System and its header i've copied, pasted and changed^^
//      *Vexorian for simply being brilliant ;)
//      *The fact, I have currently no hobbies -.-
//      *Blizzard Entertainment for creating W3 and it's editor.
//
//  How to Import:
//      Create a Trigger named Fade, convert it to custom text and replace the content with this script.
//
//  Last word(s):
//      GL and HF
// ------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------- //
globals 
    private integer array VertexAlpha
    private unit TempUnit
    private group FadeOutUnits
    private group FadeInUnits
    trigger Fade
endglobals
// -- Fade Functions -- //
function UnitFadeInSimple takes unit whichUnit returns nothing
    set VertexAlpha[GetUnitIndex(whichUnit)] = 100
    call SetUnitVertexColor(whichUnit, 255, 255, 255, 0)
    call GroupAddUnit(FadeInUnits, whichUnit)
    call EnableTrigger(Fade)
endfunction

function UnitFadeInComplex takes unit whichUnit, real afterTimeInMs returns nothing
    if(IsUnitInGroup(whichUnit, FadeOutUnits))then
        debug call BJDebugMsg("Error: Unit ("+GetUnitName(whichUnit)+") is fading out at the moment!")
        return
    endif
    if(afterTimeInMs <0)then
        call UnitFadeInSimple(whichUnit)
        return
    endif
    set VertexAlpha[GetUnitIndex(whichUnit)] = 100 + R2I(afterTimeInMs / 10)
    call SetUnitVertexColor(whichUnit, 255, 255, 255, 0)
    call GroupAddUnit(FadeInUnits, whichUnit)
    call EnableTrigger(Fade)
endfunction

function UnitFadeOutSimple takes unit whichUnit returns nothing
    if (IsUnitInGroup(whichUnit, FadeInUnits))then
        debug call BJDebugMsg("Unit is fading in at the moment")
        return
    endif
    call SetUnitVertexColor(whichUnit, 255, 255, 255, 255)
    set VertexAlpha[GetUnitIndex(whichUnit)] = 0
    call GroupAddUnit(FadeOutUnits, whichUnit)
    call EnableTrigger(Fade)
    set whichUnit = null
endfunction

function UnitFadeOutComplex takes unit whichUnit, real afterTimeInMs returns nothing
    if(IsUnitInGroup(whichUnit, FadeInUnits))then
        debug call BJDebugMsg("Error: Unit ("+GetUnitName(whichUnit)+") is fading in at the moment!")
        return
    endif
    if(afterTimeInMs <0)then
        call UnitFadeOutSimple(whichUnit)
        return
    endif
    call SetUnitVertexColor(whichUnit, 255, 255, 255, 255)
    set VertexAlpha[GetUnitIndex(whichUnit)] = 0 - R2I(afterTimeInMs / 10)
    call GroupAddUnit(FadeOutUnits, whichUnit)
    call EnableTrigger(Fade)
endfunction

//-- FadeIN --//
private function Conditions takes nothing returns boolean
    if((CountUnitsInGroup(FadeInUnits) == 0) and (CountUnitsInGroup(FadeOutUnits) == 0))then
        call DisableTrigger(GetTriggeringTrigger())
        return false
    endif
    return true    
endfunction

private function ForGroupActionsIn takes nothing returns nothing
    set TempUnit = GetEnumUnit()
    set VertexAlpha[GetUnitIndex(TempUnit)] = VertexAlpha[GetUnitIndex(TempUnit)] -1
    call SetUnitVertexColor( TempUnit, 255, 255, 255, PercentTo255(100 - VertexAlpha[GetUnitIndex(TempUnit)])) 
    if ( VertexAlpha[GetUnitIndex(TempUnit)] == 0) then
        call GroupRemoveUnit(FadeInUnits, TempUnit )
    endif
    set TempUnit = null    
endfunction

private function ForGroupActionsOut takes nothing returns nothing
    set TempUnit = GetEnumUnit()
    if(IsUnitInGroup(TempUnit, FadeInUnits))then
        call GroupRemoveUnit(FadeOutUnits, TempUnit )
    else
        call SetUnitVertexColor( TempUnit, 255, 255, 255, PercentTo255(100 - VertexAlpha[GetUnitIndex(TempUnit)]) )
        set VertexAlpha[GetUnitIndex(TempUnit)] = VertexAlpha[GetUnitIndex(TempUnit)] + 1 
        if ( VertexAlpha[GetUnitIndex(TempUnit)] == 100 and (not (IsUnitInGroup(TempUnit, FadeInUnits)))) then
            call GroupRemoveUnit(FadeOutUnits, TempUnit )
            call RemoveUnit(TempUnit)
        endif
    endif
    set TempUnit = null
endfunction

private function Actions takes nothing returns nothing
    call ForGroup( FadeOutUnits, function ForGroupActionsOut )
    call ForGroup( FadeInUnits, function ForGroupActionsIn )
    if (CountUnitsInGroup(FadeOutUnits) == 0 and CountUnitsInGroup(FadeInUnits) == 0)then
        call DisableTrigger(GetTriggeringTrigger())
    endif
endfunction

private function Init_Fade takes nothing returns nothing
    set Fade = CreateTrigger()
    set FadeInUnits = CreateGroup()
    set FadeOutUnits = CreateGroup()
    call DisableTrigger(Fade)
    call TriggerRegisterTimerEvent(Fade, 0.01, true)
    call TriggerAddCondition(Fade, Condition(function Conditions))
    call TriggerAddAction(Fade, function Actions)
endfunction
endlibrary

Jimmy
Attached Files
File type: w3xFadeTestMap.w3x (26.6 KB)