System Smooth Unit Modification

Weep

Godspeed to the sound of the pounding
Reaction score
401
Oh, hm, I guess I was mixing the version of SUM from the demo map with the version of UnitApperance from the post. It was the GetUnitRedColor, etc. functions. I had problems the first time I tried to paste the version from the original post. :p

I should re-test the problems I saw with starting two FadeUnitRGB's in a row.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Actually, while I tested my newest version of it it didn't even work XD

So I redid some stuff, and now it should work fine :D
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Yeah, I'm gonna as soon as I've fixed a few more bugs I found in this system...

First one is that it's extremely inaccurate, e.g I use this:
JASS:
        call FadeUnitRGB( u, 2.0, -32, -150, -200, 0 )


Just to test it simply, and the outcome of the real vertex colors the unit has after the fade, is Red: 255 Green: 129 Blue: 66... ?!?!?!?!?!?!?!?!

Why would this happen ?

This is what I'm using:
JASS:
library SmoothUnitMod requires T32, UnitAppearance

///////////////////////////////////////////////////////////////////////////////////////////////////////
//***************************************************************************************************//
//@@//////////////////////////////// *//SmoothUnitModification\\* /////////////////////////////////@@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%            @@//
//@@           %%                                                                    %%            @@//
//@@           %%        /////////     ///          \\\   ///\\\            ///\\\   %%            @@//
//@@           %%      /////    ////   ///          \\\   ///\\\            ///\\\   %%            @@//
//@@           %%     /////            ///          \\\   /// \\\          /// \\\   %%            @@//
//@@           %%    /////             ///          \\\   /// \\\          /// \\\   %%            @@//
//@@           %%     /////            ///          \\\   ///  \\\        ///  \\\   %%            @@//
//@@           %%      /////           ///          \\\   ///  \\\        ///  \\\   %%            @@//
//@@           %%       ////\\\\       ///          \\\   ///   \\\      ///   \\\   %%            @@//
//@@           %%           \\\\\      ////        \\\\   ///   \\\      ///   \\\   %%            @@//
//@@           %%            \\\\\     ////        \\\\   ///    \\\    ///    \\\   %%            @@//
//@@           %%              \\\\    ////        \\\\   ///    \\\    ///    \\\   %%            @@//
//@@           %%            \\\\\      ////      \\\\    ///     \\\  ///     \\\   %%            @@//
//@@           %%   \\\\    \\\\\        ////    \\\\     ///     \\\  ///     \\\   %%            @@//
//@@           %%      \\\\\\\\             ///\\\        ///      \\\///      \\\   %%            @@//
//@@           %%                                                                    %%            @@//
//@@           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%            @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                    Made by , Komaqtion                                        @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                          Purpose:                                             @@//
//@@                                                                                               @@//
//@@             ¤ This is a system, which will give the user the opportunity to easily modify     @@//
//@@               3 main aspects of units: Scale, ARGB color and Time Scale (Animation Speed).    @@//
//@@                                                                                               @@//
//@@                                           Usage:                                              @@//
//@@                                                                                               @@//
//@@             ¤ The function that this system provides the user are:                            @@//
//@@                                                                                               @@//
//@@             function ScaleSimple takes unit Scaler, real Time, real scaleMod                  @@//
//@@             function ScaleEx takes unit Scaler, real Time, real scaleMod, code userFunc       @@//
//@@                                                                                               @@//
//@@               "Scaler" is the unit which is to be scaled.                                     @@//
//@@               "Time" is basically, over how long time will the unit scale...                  @@//
//@@               "scaleMod" is how much the unit's scale will change, example:                   @@//
//@@               "userFunc" is the callback, if wanted, the system will execute                  @@//
//@@               when the scaling is done.                                                       @@//
//@@               Example:                                                                        @@//
//@@                                                                                               @@//
//@@               call ScaleSimple( GetTriggerUnit(), 2.0, 0.5 )                                  @@//
//@@                                                                                               @@//
//@@               Will scale the unit to +50% over 2 seconds.                                     @@//
//@@               And, also the modification is in decimal form, meaning that 1.0 will            @@//
//@@               double the unit's size...                                                       @@//
//@@                                                                                               @@//
//@@               The timescale part of this system is basically the same as this, and uses       @@//
//@@               the same amount of "takes"...                                                   @@//
//@@                                                                                               @@//
//@@               The fade part, on the other hand, has more "takes", simply because it handles   @@//
//@@               the red, green and blue colors too, and not only transparency...                @@//
//@@               An example:                                                                     @@//
//@@                                                                                               @@//
//@@               call FadeEX( GetTriggerUnit(), 2.0, 0.0, -255, -255, -127.5 )                   @@//
//@@                                                                                               @@//
//@@               This little sample will make the unit 50% transparent, and also RED.            @@//
//@@               And all the arguments here ranges from 0.0 - 255.0, meaning that a 50%          @@//
//@@               transparent unit has an alpha value of 127.5...                                 @@//
//@@                                                                                               @@//
//@@               You can also use this system to "get" any of the values you can change with     @@//
//@@               it, using functions like this:                                                  @@//
//@@                                                                                               @@//
//@@               function GetUnitScale takes unit u returns real                                 @@//
//@@                                                                                               @@//
//@@               Which will give you the current scale of the unit...                            @@//
//@@                                                                                               @@//
//@@                                           Note:                                               @@//
//@@                                                                                               @@//
//@@             ¤ This system does not support pre-changed RGB colors from the Object Editor,     @@//
//@@               and I'd suggest you manually change the color of the units in-game instead.     @@//
//@@               It presumes that all colors of all units are set to 255 from the start !        @@//
//@@                                                                                               @@//
//@@                                       Requirements:                                           @@//
//@@                                                                                               @@//
//@@             ¤ A vJASS preprocessor, which is easiest found by downloading JASS Newgen Pack    @@//
//@@               <a href="http://www.thehelper.net/forums/showthread.php?t=73936" class="link link--internal">http://www.thehelper.net/forums/showthread.php?t=73936</a>                          @@//
//@@               You&#039;ll also have to update JASS Helper to the latest version...                 @@//
//@@               And, then you&#039;ll need the system called Timer32 (T32), and also my other        @@//
//@@               system, called &quot;UnitAppearance&quot; <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />                                              @@//
//@@                                                                                               @@//
//@@                                         Credits:                                              @@//
//@@                                                                                               @@//
//@@             ¤ Viikuna, for helping me out, and also helping me make &quot;UnitAppearance&quot; !        @@//
//@@               Jesus4Lyf, for also helping me out alot, and making Timer 32 ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />               @@//
//@@               Azlier, for some help too <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />                                                    @@//
//@@                                                                                               @@//
//@@               And credits, if you use this that is, is not needed to give me                  @@//
//@@               though it&#039;s always welcome <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />                                                   @@//
//@@                                                                                               @@//
//@@///////////////////////////////////////////////////////////////////////////////////////////////@@//
//***************************************************************************************************//
///////////////////////////////////////////////////////////////////////////////////////////////////////

    struct SmoothScaleChange
    
        private integer ticks
        
        private real increment
        
        private unit u
        
        private method periodic takes nothing returns nothing
            set this.ticks = this.ticks - 1
        
            call ModifyUnitScale( this.u, this.increment ) // This will save the scale of the unit in a struct using AIDS...
            
            debug call BJDebugMsg( &quot;#SUM# - Scale: &quot; + R2S( Appearance[ this.u ].scale ) )
            
            if this.ticks &lt;= 0 then
                call this.destroy() // When ticks becomes 0 (Meaning that the scaling is done) destroy it ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
                
                call this.stopPeriodic()
            endif
            
        endmethod
        
        implement T32x
        
        static method create takes unit Scaler, real Time, real scaleMod returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Scaler // Which unit to scale XD
            set this.increment = ( ( scaleMod * T32_PERIOD ) / Time ) // How much the scale will increase each PERIOD...
            set this.ticks = R2I( scaleMod / this.increment ) // How many times the timer must fire...
            
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    function ScaleUnit takes unit Scaler, real Time, real scaleMod returns SmoothScaleChange
        return SmoothScaleChange.create( Scaler, Time, scaleMod )
    endfunction
    
    function GetUnitScale takes unit u returns real
        return Appearance[ u ].scale
    endfunction
    
    struct SmoothColorChange
    
        private integer ticks
        
        private real rincrement
        private real gincrement
        private real bincrement
        private real increment
        
        private unit u
        
        private method periodic takes nothing returns nothing
            set this.ticks = this.ticks - 1
        
            call ModifyUnitVertexColor( this.u, R2I( this.rincrement ), R2I( this.gincrement ), R2I( this.bincrement ), R2I( this.increment ) )
            
            /*debug call BJDebugMsg( &quot;#SUM# - Alpha: &quot; + R2S( Appearance[this.u].alpha ) )
            debug call BJDebugMsg( &quot;#SUM# - Red: &quot; + R2S( Appearance[this.u].red ) )
            debug call BJDebugMsg( &quot;#SUM# - Green: &quot; + R2S( Appearance[this.u].green ) )
            debug call BJDebugMsg( &quot;#SUM# - Blue: &quot; + R2S( Appearance[this.u].blue ) )*/
            
            if this.ticks &lt;= 0 then
                call this.destroy()
                
                call this.stopPeriodic()
            endif
            
        endmethod
        
        implement T32x
        
        static method create takes unit Fader, real Time, real redMod, real greenMod, real blueMod, real alphaMod returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Fader
            set this.increment = ( ( alphaMod * T32_PERIOD ) / Time )
            set this.rincrement = ( ( redMod * T32_PERIOD ) / Time )
            set this.gincrement = ( ( greenMod * T32_PERIOD ) / Time )
            set this.bincrement = ( ( blueMod * T32_PERIOD ) / Time )
            
            /*if alphaMod != 0 then
                set this.ticks = R2I( alphaMod / this.increment )
            elseif redMod != 0 then
                set this.ticks = R2I( redMod / this.rincrement )
            elseif greenMod != 0 then
                set this.ticks = R2I( greenMod / this.gincrement )
            elseif blueMod != 0 then
                set this.ticks = R2I( blueMod / this.bincrement )
            endif*/
            
            set this.ticks = R2I( Time / T32_PERIOD )
            
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    function FadeUnit takes unit Fader, real Time, real alphaMod returns SmoothColorChange
        return SmoothColorChange.create( Fader, Time, 0., 0., 0., alphaMod )
    endfunction
    
    function FadeUnitRGB takes unit Fader, real Time, real redMod, real greenMod, real blueMod, real alphaMod returns SmoothColorChange
        return SmoothColorChange.create( Fader, Time, redMod, greenMod, blueMod, alphaMod )
    endfunction
    
    function GetUnitColorAlpha takes unit u returns integer
        return R2I( Appearance[ u ].alpha )
    endfunction

    function GetUnitColorRed takes unit u returns integer
        return R2I( Appearance[ u ].red )
    endfunction
    
    function GetUnitColorGreen takes unit u returns integer
        return R2I( Appearance[ u ].green )
    endfunction
    
    function GetUnitColorBlue takes unit u returns integer
        return R2I( Appearance[ u ].blue )
    endfunction
    
    struct SmoothTSChange
    
        //private code userFunc
        private integer ticks
        
        private real increment
        
        private unit u
        
        private method periodic takes nothing returns nothing
            set this.ticks = this.ticks - 1
        
            call ModifyUnitTimeScale( this.u, this.increment )
            
            debug call BJDebugMsg( &quot;#SUM# - Timescale :&quot; + R2S( Appearance[ this.u ].timescale ) )
            
            if this.ticks &lt;= 0 then
                call this.destroy()
                
                call this.stopPeriodic()
            endif
            
        endmethod
        
        implement T32x
        
        static method create takes unit Timer, real Time, real timescaleMod returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Timer
            //set this.userFunc = userFunc
            set this.increment = ( ( timescaleMod * T32_PERIOD ) / Time )
            set this.ticks = R2I( timescaleMod / this.increment ) // How many times the timer must fire...
            
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    function ChangeTimeScale takes unit Timer, real Time, real timescaleMod returns SmoothTSChange
        return SmoothTSChange.create( Timer, Time, timescaleMod )
    endfunction
    
    function GetUnitTimeScale takes unit u returns real
        return Appearance[ u ].timescale
    endfunction

endlibrary


JASS:
library UnitAppearance requires AIDS

    struct Appearance extends array
        //! runtextmacro AIDS()

        real scale
        
        real timescale
        
        real alpha
        real red
        real green
        real blue
        
        private method AIDS_onCreate takes nothing returns nothing
            set this.scale = 1.0
            
            set this.alpha = 255.0
            set this.red = 255.0
            set this.green = 255.0
            set this.blue = 255.0
            
            set this.timescale = 1.0
        endmethod
        
    endstruct

    function ModifyUnitScale takes unit u, real addscale returns nothing
        local Appearance this = Appearance[ u ]
        
        if this.scale &gt; 0 then
            set this.scale = this.scale + addscale
            
            call SetUnitScale( this.unit, this.scale, 0.,0. )
        endif
        
    endfunction
    
    function ModifyUnitVertexColor takes unit u, real addred, real addgreen, real addblue, real addalpha returns nothing
        local Appearance this = Appearance[ u ]
        
        if this.alpha &gt; 0 then
            set this.alpha = this.alpha + addalpha
        endif
        
        if this.red &gt; 0 then
            set this.red = this.red + addred
        endif
        
        if this.green &gt; 0 then
            set this.green = this.green + addgreen
        endif
        
        if this.blue &gt; 0 then
            set this.blue = this.blue + addblue
        endif
        
        if this.alpha &gt; 0 or this.red &gt; 0 or this.green &gt; 0 or this.blue &gt; 0 then
            call SetUnitVertexColor( this.unit, R2I( this.red ), R2I( this.green ), R2I( this.blue ), R2I( this.alpha ) )
        endif
        
    endfunction
    
    function ModifyUnitTimeScale takes unit u, real addtimescale returns nothing
        local Appearance this = Appearance[ u ]
        
        if this.timescale &gt; 0 then
            set this.timescale = this.timescale + addtimescale
        
            call SetUnitTimeScale( this.unit, this.timescale )
        endif
    endfunction
    
endlibrary


As you can see I've made some small changes here and there, but nothing major...

I'd believe this is because you need to use integers when setting the vertex colors, but there's no other way of doing it, right ? :S
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, so I've now updated this quite a bit, and it should now be VERY accurate ! :D

The documentation has also undergone an EXTREME makeover, and I'd now like to say it is very structured, and well written :p

I'm not too sure if I'm satisfied about the function names though... :S
Comment on them, please ! :D

Anyways, here's the new version:

JASS:
library SmoothUnitMod requires T32, UnitAppearance

///////////////////////////////////////////////////////////////////////////////////////////////////////////
//*******************************************************************************************************//
//@@////////////////////////////////// *//SmoothUnitModification\\* ///////////////////////////////////@@//
//@@                                                                                                   @@//
//@@                                                                                                   @@//
//@@             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%              @@//
//@@             %%                                                                    %%              @@//
//@@             %%        /////////     ///          \\\   ///\\\            ///\\\   %%              @@//
//@@             %%      /////    ////   ///          \\\   ///\\\            ///\\\   %%              @@//
//@@             %%     /////            ///          \\\   /// \\\          /// \\\   %%              @@//
//@@             %%    /////             ///          \\\   /// \\\          /// \\\   %%              @@//
//@@             %%     /////            ///          \\\   ///  \\\        ///  \\\   %%              @@//
//@@             %%      /////           ///          \\\   ///  \\\        ///  \\\   %%              @@//
//@@             %%       ////\\\\       ///          \\\   ///   \\\      ///   \\\   %%              @@//
//@@             %%           \\\\\      ////        \\\\   ///   \\\      ///   \\\   %%              @@//
//@@             %%            \\\\\     ////        \\\\   ///    \\\    ///    \\\   %%              @@//
//@@             %%              \\\\    ////        \\\\   ///    \\\    ///    \\\   %%              @@//
//@@             %%            \\\\\      ////      \\\\    ///     \\\  ///     \\\   %%              @@//
//@@             %%   \\\\    \\\\\        ////    \\\\     ///     \\\  ///     \\\   %%              @@//
//@@             %%      \\\\\\\\             ///\\\        ///      \\\///      \\\   %%              @@//
//@@             %%                                                                    %%              @@//
//@@             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%              @@//
//@@                                                                                                   @@//
//@@                                                                                                   @@//
//@@                                                                                                   @@//
//@@                                        Made by , Komaqtion                                        @@//
//@@                                                                                                   @@//
//@@                                                                                                   @@//
//@@                                              Purpose:                                             @@//
//@@                                                                                                   @@//
//@@             ¤ This is a system, which will give the user the opportunity to easily modify         @@//
//@@               3 main aspects of units: Scale, ARGB color and Time Scale (Animation Speed).        @@//
//@@                                                                                                   @@//
//@@                                               Usage:                                              @@//
//@@                                                                                                   @@//
//@@             ¤ The first functions that this system provides the user are all about                @@//
//@@               &#039;scaling&#039;, and they look like this:                                                 @@//
//@@                                                                                                   @@//
//@@  -&gt;       function ScaleUnitByValue takes unit Modifier, real Time,                               @@//
//@@                      real scaleMod returns SmoothScaleChange                                      @@//
//@@                                                                                                   @@//
//@@               &quot;unit Modifier&quot; is the unit which is to be modifier                                 @@//
//@@               (Scaled, Faded or Timescaled).                                                      @@//
//@@               &quot;real Time&quot; is, basically, over how long time will the unit scale...                @@//
//@@               &quot;real scaleMod&quot; is how much you want the &quot;Modifier&quot;s scale to change.               @@//
//@@               This is used to modify a unit&#039;s scale, not setting it to a specific value.          @@//
//@@               And by modifying I mean e.g set it to 0.5 less than it is now...                    @@//
//@@               &quot;returns SmoothScaleChange&quot;: Since these functions inlines to a struct-             @@//
//@@               creation, just thought it might as well returns that struct too <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />                  @@//
//@@                                                                                                   @@//
//@@  -&gt;       function ScaleUnitToValue takes unit Modifier, real Time,                               @@//
//@@                      real scaleValue returns SmoothScaleChange                                    @@//
//@@                                                                                                   @@//
//@@               &quot;unit Modifier&quot; is the unit which is to be modifier                                 @@//
//@@               (Scaled, Faded or Timescaled).                                                      @@//
//@@               &quot;real Time&quot; is, basically, over how long time will the unit scale...                @@//
//@@               &quot;real scaleValue&quot; is to what value you want the modifier&#039;s scale to change to.      @@//
//@@               Unlike that &quot;ScaleUnitByValue&quot; function, here you input a specific value            @@//
//@@               you want the unit to be scaled to.                                                  @@//
//@@               &quot;returns SmoothScaleChange&quot;: Since these functions inlines to a struct-             @@//
//@@               creation, just thought it might as well returns that struct too <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />                  @@//
//@@                                                                                                   @@//
//@@  -&gt;       function GetUnitScale takes unit u returns real                                         @@//
//@@                                                                                                   @@//
//@@               &quot;unit u&quot; is the unit of which scale you wish to retrieve.                           @@//
//@@               &quot;returns real&quot;: This is the current scale of the unit.                              @@//
//@@                                                                                                   @@//
//@@               And here&#039;s an example of how to use these &quot;scaling&quot; functions:                      @@//
//@@                                                                                                   @@//
//@@       call ScaleUnitToValue( GetTriggerUnit(), 2.0, GetUnitScale( GetTriggerUnit() ) / 2. )       @@//
//@@                                                                                                   @@//
//@@               Will scale the triggering unit to half it&#039;s current size over 2 seconds.            @@//
//@@                                                                                                   @@//
//@@               Now we get to the time-scale part of the API, which consists                        @@//
//@@               these three functions (Which are noticably like the &#039;scaling&#039; functions ):          @@//
//@@                                                                                                   @@//
//@@  -&gt;       function ChangeTimeScaleByValue takes unit Modifier, real Time,                         @@//
//@@                       real timescaleMod returns SmoothTSChange                                    @@//
//@@                                                                                                   @@//
//@@  -&gt;       function ChangeTimeScaleToValue takes unit Modifier, real Time,                         @@//
//@@                       real timescaleValue returns SmoothTSChange                                  @@//
//@@                                                                                                   @@//
//@@  -&gt;       function GetUnitTimeScale takes unit u returns real                                     @@//
//@@                                                                                                   @@//
//@@               These functions, and their parameters, work exactly the same as the &quot;scaling&quot;       @@//
//@@               part of this system/snippet:                                                        @@//
//@@                                                                                                   @@//
//@@               &quot;unit Modifier&quot; is the unit you wish to change the time-scale of.                   @@//
//@@               &quot;real Time&quot; is the amount of time you wish the modification should take.            @@//
//@@               &quot;real timescaleMod/Value&quot; is, as in the &quot;scaling&quot; functions, the amount             @@//
//@@               you want the unit&#039;s time-scale to change by/to.                                     @@//
//@@               &quot;returns SmoothTSChange&quot;, just as in the &quot;scaling&quot; functions, this inlines          @@//
//@@               to a struct-creation, so it also returns that <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />                                    @@//
//@@                                                                                                   @@//
//@@               And the &quot;GetUnitTimeScale&quot; function takes the unit you wish to get the              @@//
//@@               time-scale of, and it will return the current time-scale of that unit.              @@//
//@@                                                                                                   @@//
//@@               As said, the scaling and time-scaling parts of this snippet are very much           @@//
//@@               alike, but now we get to the more advanced and extended part of it:                 @@//
//@@               The smooth coloring and fading of units !                                           @@//
//@@                                                                                                   @@//
//@@               And all of these function have more parameters than the other two parts,            @@//
//@@               simply because they handle 4 aspects (ARGB colors <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />) instead of one.               @@//
//@@                                                                                                   @@//
//@@               Now to the functions provided by this section of code:                              @@//
//@@                                                                                                   @@//
//@@  -&gt;       function FadeUnitByValue takes unit Modifier, real Time,                                @@//
//@@                    real alphaMod returns SmoothColorChange                                        @@//
//@@                                                                                                   @@//        
//@@  -&gt;       function FadeUnitARGBByValue takes unit Modifier, real Time,                            @@//
//@@                    real redMod, real greenMod, real blueMod,                                      @@//
//@@                    real alphaMod returns SmoothColorChange                                        @@//
//@@                                                                                                   @@//
//@@  -&gt;       function FadeUnitToValue takes unit Modifier, real Time,                                @@//
//@@                     real alphaValue returns SmoothColorChange                                     @@//
//@@                                                                                                   @@//
//@@  -&gt;       function FadeUnitARGBToValue takes unit Modifier, real Time,                            @@//
//@@                    real redValue, real greenValue, real blueValue,                                @@//
//@@                    real alphaValue returns SmoothColorChange                                      @@//
//@@                                                                                                   @@//
//@@               Here comes the explanation of the parameters used in these functions:               @@//
//@@                                                                                                   @@//
//@@               &quot;unit Modifier&quot;, as in all other functions, this is the unit to be modified.        @@//
//@@               &quot;real Time&quot;, and again, this is the amount of time the process is gonna take.       @@//
//@@               &quot;real alphaMod&quot; is the amount you wish to change the unit&#039;s alpha color.            @@//
//@@               &quot;real alphaValue&quot; is the value you wish to get after the smooth fading              @@//
//@@               process is done.                                                                    @@//
//@@               &quot;real redMod/Value&quot; is the same as above.                                           @@//
//@@               &quot;real greenMod/Value&quot; is, yet again, same as two/three lines above.                 @@//
//@@               &quot;real blueMod/Value&quot; is, for the last time, same as three/four lines above.         @@//
//@@                                                                                                   @@//
//@@               *NOTE*: The alpha value (And all other colors too) range from 0 - 255,              @@//
//@@                       where 0 is none of that color (Or transparent with the alpha color)         @@//
//@@                       and 255 is full color, and not seethrough with the alpha color <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />           @@//
//@@                                                                                                   @@//
//@@  -&gt;       function GetUnitColorAlpha takes unit u returns integer                                 @@//
//@@                                                                                                   @@//
//@@  -&gt;       function GetUnitColorRed takes unit u returns integer                                   @@//
//@@                                                                                                   @@//
//@@  -&gt;       function GetUnitColorGreen takes unit u returns integer                                 @@//
//@@                                                                                                   @@//
//@@  -&gt;       function GetUnitColorBlue takes unit u returns integer                                  @@//
//@@                                                                                                   @@//
//@@               All of the four above function will let the user get the current amount             @@//
//@@               of a specific color the exists on a unit, where it&#039;s parameter is:                  @@//
//@@                                                                                                   @@//
//@@               &quot;unit u&quot;, which is the unit you wish the the the color of.                          @@//
//@@                                                                                                   @@//
//@@               And it will then return a number somewhere between 0 and 255.                       @@//
//@@                                                                                                   @@//
//@@               Now, to an example of how to use these functions to get a hang of it:               @@//
//@@                                                                                                   @@//
//@@       call FadeUnitARGBToValue( GetTriggerUnit(), 5.0, GetUnitColorRed( GetTriggerUnit() ),       @@//
//@@                                 0.0, ( GetUnitColorBlue( GetTriggerUnit() ) / 2. ),               @@//
//@@                                 GetUnitColorAlpha( GetTriggerUnit() ) / 4. )                      @@//
//@@                                                                                                   @@//
//@@               This little sample will make the unit 75% transparent, and also a                   @@//
//@@               mix of 66% red color and 33% blue color (We remove the green color                  @@//
//@@               and half the blue color. This is also all done, smoothly, over 5.0 seconds.         @@//
//@@                                                                                                   @@//
//@@                                                                                                   @@//
//@@                                               Note:                                               @@//
//@@                                                                                                   @@//
//@@             ¤ This system does not support pre-changed RGB colors from the Object Editor,         @@//
//@@               and I&#039;d suggest you manually change the color of the units in-game instead.         @@//
//@@               It presumes that all colors of all units are set to 255 from the start !            @@//
//@@               It will also use the scale of units as if they were set to 1.0 from                 @@//
//@@               the start, so if you change that scale of a unit, you should change the value       @@//
//@@               &quot;currentScale&quot; and &quot;doneScale&quot; for each unit of that type to the scale they         @@//
//@@               have in the Object Editor.                                                          @@//
//@@                                                                                                   @@//
//@@                                                                                                   @@//
//@@                                           Requirements:                                           @@//
//@@                                                                                                   @@//
//@@             ¤ A vJASS preprocessor, which is easiest found by downloading JASS Newgen Pack        @@//
//@@               <a href="http://www.thehelper.net/forums/showthread.php?t=73936" class="link link--internal">http://www.thehelper.net/forums/showthread.php?t=73936</a>                              @@//
//@@               You&#039;ll also have to update JASS Helper to the latest version...                     @@//
//@@               And, then you&#039;ll need the system called Timer32 (T32), and also my other            @@//
//@@               snippet, called &quot;UnitAppearance&quot; <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />                                                 @@//
//@@                                                                                                   @@//
//@@                                             Credits:                                              @@//
//@@                                                                                                   @@//
//@@             ¤ Viikuna, for helping me out, and also helping me make &quot;UnitAppearance&quot; !            @@//
//@@               Jesus4Lyf, for also helping me out alot, and making Timer 32 ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />                   @@//
//@@               Azlier, for some help too <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />                                                        @@//
//@@                                                                                                   @@//
//@@               And credits, if you use this that is, is not needed to give me                      @@//
//@@               though it&#039;s always welcome <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />                                                       @@//
//@@                                                                                                   @@//
//@@///////////////////////////////////////////////////////////////////////////////////////////////////@@//
//*******************************************************************************************************//
///////////////////////////////////////////////////////////////////////////////////////////////////////////

    struct SmoothScaleChange
    
        integer ticks
        
        real increment
        
        unit u
        
        static method create takes unit Modifier, real Time, real scaleMod returns thistype
            local thistype this = thistype.allocate()
            
            set u = Modifier // Which unit to scale <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />
            
            set Appearance[ Modifier ].doneScale = Appearance[ Modifier ].doneScale + scaleMod
            
            if Time &gt; 0. then
                set ticks = R2I( Time / T32_PERIOD ) // How many times the timer must fire...
                
                set increment = scaleMod / ticks // How much the scale will increase each PERIOD...
                
                call startPeriodic()
            else
                call ModifyUnitScale( u, scaleMod )
            endif
            
            return this
        endmethod
        
        private method periodic takes nothing returns nothing
            set ticks = ticks - 1
            
            call ModifyUnitScale( u, increment ) // This will save the scale of the unit in a struct using AIDS...
            
            debug call DisplayTimedTextToPlayer( GetLocalPlayer(), 0., 0., 6000., &quot;#SUM# - Scale: &quot; + R2S( Appearance[ u ].currentScale ) )
            
            if ticks &lt;= 0 then // When ticks becomes 0 (Meaning that the scaling is done) destroy it, and remove it from the T32 queue ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
                call stopPeriodic()
                
                call destroy()
            endif
            
        endmethod
        
        implement T32x
        
    endstruct
    
    function ScaleUnitByValue takes unit Modifier, real Time, real scaleMod returns SmoothScaleChange
        return SmoothScaleChange.create( Modifier, Time, scaleMod )
    endfunction
    
    function ScaleUnitToValue takes unit Modifier, real Time, real scaleValue returns SmoothScaleChange
        return SmoothScaleChange.create( Modifier, Time, scaleValue - Appearance[ Modifier ].doneScale )
    endfunction
    
    function GetUnitScale takes unit u returns real
        return Appearance[ u ].currentScale
    endfunction
    
    struct SmoothColorChange
    
        integer ticks
        
        real rincrement
        real gincrement
        real bincrement
        real increment
        
        unit u
        
        static method create takes unit Modifier, real Time, real redMod, real greenMod, real blueMod, real alphaMod returns thistype
            local thistype this = thistype.allocate()
            
            set u = Modifier
            set Appearance[ Modifier ].doneAlpha = Appearance[ Modifier ].doneAlpha + alphaMod
            set Appearance[ Modifier ].doneRed = Appearance[ Modifier ].doneRed + redMod
            set Appearance[ Modifier ].doneGreen = Appearance[ Modifier ].doneGreen + greenMod
            set Appearance[ Modifier ].doneBlue = Appearance[ Modifier ].doneBlue + blueMod
            
            if Time &gt; 0. then
                set ticks = R2I( Time / T32_PERIOD )
                
                set increment = alphaMod / ticks
                set rincrement = redMod / ticks
                set gincrement = greenMod / ticks
                set bincrement = blueMod / ticks
                
                call startPeriodic()
            else
                call ModifyUnitVertexColor( u, redMod, greenMod, blueMod, alphaMod )
            endif
            
            return this
        endmethod
        
        private method periodic takes nothing returns nothing
            set ticks = ticks - 1
        
            call ModifyUnitVertexColor( u, rincrement, gincrement, bincrement, increment )
            
            debug call DisplayTimedTextToPlayer( GetLocalPlayer(), 0., 0., 6000., &quot;#SUM# - Red: &quot; + I2S( R2I( Appearance<u>.currentRed ) ) )
            debug call DisplayTimedTextToPlayer( GetLocalPlayer(), 0., 0., 6000., &quot;#SUM# - Green: &quot; + I2S( R2I( Appearance<u>.currentGreen ) ) )
            debug call DisplayTimedTextToPlayer( GetLocalPlayer(), 0., 0., 6000., &quot;#SUM# - Blue: &quot; + I2S( R2I( Appearance<u>.currentBlue ) ) )
            debug call DisplayTimedTextToPlayer( GetLocalPlayer(), 0., 0., 6000., &quot;#SUM# - Alpha: &quot; + I2S( R2I( Appearance<u>.currentAlpha ) ) )
            
            if ticks &lt;= 0 then
                call destroy()
                
                call stopPeriodic()
            endif
            
        endmethod
        
        implement T32x
        
    endstruct
    
    function FadeUnitByValue takes unit Modifier, real Time, real alphaMod returns SmoothColorChange
        return SmoothColorChange.create( Modifier, Time, 0., 0., 0., alphaMod )
    endfunction
    
    function FadeUnitARGBByValue takes unit Modifier, real Time, real redMod, real greenMod, real blueMod, real alphaMod returns SmoothColorChange
        return SmoothColorChange.create( Modifier, Time, redMod, greenMod, blueMod, alphaMod )
    endfunction
    
    function FadeUnitToValue takes unit Modifier, real Time, real alphaValue returns SmoothColorChange
        return SmoothColorChange.create( Modifier, Time, 0., 0., 0., alphaValue - Appearance[ Modifier ].doneAlpha )
    endfunction
    
    function FadeUnitARGBToValue takes unit Modifier, real Time, real redValue, real greenValue, real blueValue, real alphaValue returns SmoothColorChange
        return SmoothColorChange.create( Modifier, Time, redValue - Appearance[ Modifier ].doneRed, greenValue - Appearance[ Modifier ].doneGreen,/*
    */                                                   blueValue - Appearance[ Modifier ].doneBlue, alphaValue - Appearance[ Modifier ].doneAlpha )
    endfunction
    
    function GetUnitColorAlpha takes unit u returns integer
        return R2I( Appearance[ u ].currentAlpha )
    endfunction

    function GetUnitColorRed takes unit u returns integer
        return R2I( Appearance[ u ].currentRed )
    endfunction
    
    function GetUnitColorGreen takes unit u returns integer
        return R2I( Appearance[ u ].currentGreen )
    endfunction
    
    function GetUnitColorBlue takes unit u returns integer
        return R2I( Appearance[ u ].currentBlue )
    endfunction
    
    struct SmoothTSChange
    
        integer ticks
        
        real increment
        
        unit u
        
        static method create takes unit Modifier, real Time, real timescaleMod returns thistype
            local thistype this = thistype.allocate()
            
            set u = Modifier
            set Appearance[ Modifier ].doneTimescale = Appearance[ Modifier ].doneTimescale + timescaleMod
            
            if Time &gt; 0 then
                set ticks = R2I( Time * T32_PERIOD )    // How many times the timer must fire...
                
                set increment = timescaleMod / ticks    // How much to increase/decrease each period <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
                
                call startPeriodic()
            else
                call ModifyUnitTimeScale( u, timescaleMod )
            endif
            
            return this
        endmethod
        
        private method periodic takes nothing returns nothing
            set ticks = ticks - 1
        
            call ModifyUnitTimeScale( u, increment )
            
            debug call DisplayTimedTextToPlayer( GetLocalPlayer(), 0., 0., 6000., &quot;#SUM# - Timescale :&quot; + R2S( Appearance[ u ].currentTimescale ) )
            
            if ticks &lt;= 0 then
                call destroy()
                
                call stopPeriodic()
            endif
            
        endmethod
        
        implement T32x
        
    endstruct
    
    function ChangeTimeScaleByValue takes unit Modifier, real Time, real timescaleMod returns SmoothTSChange
        return SmoothTSChange.create( Modifier, Time, timescaleMod )
    endfunction
    
    function ChangeTimeScaleToValue takes unit Modifier, real Time, real timescaleValue returns SmoothTSChange
        return SmoothScaleChange.create( Modifier, Time, timescaleValue - Appearance[ Modifier ].doneTimescale )
    endfunction
    
    function GetUnitTimeScale takes unit u returns real
        return Appearance[ u ].currentTimescale
    endfunction

endlibrary</u></u></u></u>


JASS:
library UnitAppearance requires AIDS

    struct Appearance extends array
        //! runtextmacro AIDS()

        public real currentScale
        
        public real currentTimescale
        
        public real currentAlpha
        public real currentRed
        public real currentGreen
        public real currentBlue
        
        public real doneScale
        
        public real doneTimescale
        
        public real doneAlpha
        public real doneRed
        public real doneGreen
        public real doneBlue
        
        private method AIDS_onCreate takes nothing returns nothing
            set currentScale = 1.0
            
            set currentAlpha = 255.0
            set currentRed = 255.0
            set currentGreen = 255.0
            set currentBlue = 255.0
            
            set currentTimescale = 1.0
            
            set doneScale = 1.0
            
            set doneAlpha = 255.0
            set doneRed = 255.0
            set doneGreen = 255.0
            set doneBlue = 255.0
            
            set doneTimescale = 1.0
        endmethod
        
    endstruct

    function ModifyUnitScale takes unit u, real addscale returns nothing
        local Appearance this = Appearance[ u ]
        
        if addscale != 0. then
            set this.currentScale = this.currentScale + addscale
            
            call SetUnitScale( this.unit, this.currentScale, 0.,0. )
        endif
        
    endfunction
    
    function ModifyUnitVertexColor takes unit u, real addred, real addgreen, real addblue, real addalpha returns nothing
        local Appearance this = Appearance[ u ]
        
        if addalpha != 0. then
            set this.currentAlpha = this.currentAlpha + addalpha
        endif
        
        if addred != 0. then
            set this.currentRed = this.currentRed + addred
        endif
        
        if addgreen != 0. then
            set this.currentGreen = this.currentGreen + addgreen
        endif
        
        if addblue != 0. then
            set this.currentBlue = this.currentBlue + addblue
        endif
        
        if addalpha != 0. or addred != 0. or addgreen != 0. or addblue != 0. then
            call SetUnitVertexColor( this.unit, R2I( this.currentRed ), R2I( this.currentGreen ), R2I( this.currentBlue ), R2I( this.currentAlpha ) )
        endif
        
    endfunction
    
    function ModifyUnitTimeScale takes unit u, real addtimescale returns nothing
        local Appearance this = Appearance[ u ]
        
        if addtimescale != 0. then
            set this.currentTimescale = this.currentTimescale + addtimescale
        
            call SetUnitTimeScale( this.unit, this.currentTimescale )
        endif
        
    endfunction
    
endlibrary


EDIT: Just added a new and much improved Test Map to the first post, please take time and check it out ! ;)
 

Laiev

Hey Listen!!
Reaction score
188
just a note xD (making my tesh and i notice that)

JASS:
//@@  -&gt;       function ChangeTimeScaleTyValue takes unit Modifier, real Time,                         @@//


should be

JASS:
//@@  -&gt;       function ChangeTimeScaleToValue takes unit Modifier, real Time,                         @@//
 

Komaqtion

You can change this now in User CP.
Reaction score
469
ARE YOU F&%@ING KIDDING ME ?! YOU GRAVEYARDED THIS ?!

YOU JUST LOST A VERY HAPPY AND DEDICATED USER OF THIS FORUM...

Sorry guys, I put WAY too much effort into this for it to be graveyarded, so good bye :'(
 

Laiev

Hey Listen!!
Reaction score
188
:/ komaqtion, just request this to back to resources... some mod/admin just clear all resources submitted and don't see all cases >< don't go (?)
 

Weep

Godspeed to the sound of the pounding
Reaction score
401
Stuff automatically gets graveyarded after a while, I think. :( I'm surprised you hadn't noticed. Don't be so quick to react. :eek:
 

BlackRose

Forum User
Reaction score
239
ARE YOU F&%@ING KIDDING ME ?! YOU GRAVEYARDED THIS ?!

YOU JUST LOST A VERY HAPPY AND DEDICATED USER OF THIS FORUM...

Sorry guys, I put WAY too much effort into this for it to be graveyarded, so good bye :'(

LOL <3 Discuss it, not leave. I don't even see some sort of 'review & consequent rejection' post.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top