System Smooth Unit Modification

Komaqtion

You can change this now in User CP.
Reaction score
469
SUM
Smooth Unit Modification

Requirements ( SUM ): Timer 32, by Jesus4Lyf and my other system called "UnitAppearance" which you can see here below :D

Requirements ( UnitAppearance ): AIDS, by Jesus4Lyf

MUI/MPI: MUI

GUI/JASS/vJASS: vJASS

Ok, so after having a very long thread about this in the JASS Help section, I've now submitted this system.

This system will help the user change scale, ARGB color (Though isn't using Vex's ARGB system) and timescale smoothly over time, using T32. (With a PERIOD of 0.03125)

I currently don't have a very good example of using this, only some lame test triggers in the map, so please come with suggestions for a good example for this :D

Ok, so anyways... Here's the code for "UnitAppearance":

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                @@//
//@@               'scaling', and they look like this:                                                 @@//
//@@                                                                                                   @@//
//@@  ->       function ScaleUnitByValue takes unit Modifier, real Time,                               @@//
//@@                      real scaleMod returns SmoothScaleChange                                      @@//
//@@                                                                                                   @@//
//@@               "unit Modifier" is the unit which is to be modifier                                 @@//
//@@               (Scaled, Faded or Timescaled).                                                      @@//
//@@               "real Time" is, basically, over how long time will the unit scale...                @@//
//@@               "real scaleMod" is how much you want the "Modifier"s scale to change.               @@//
//@@               This is used to modify a unit'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...                    @@//
//@@               "returns SmoothScaleChange": 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




And, please give a lot of feedback, and critisism :D
 

Attachments

  • Smooth Unit Modification V 2.00 Test Map.w3x
    106.2 KB · Views: 362

saw792

Is known to say things. That is all.
Reaction score
280
The header says ScaleEx() is part of the system, but you removed all that callback stuff earlier. Might want to fix that up for now.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Support. =)

Hehe, thanks XD

And, updated now and added the "Test Map"...
(Which almost isn't a test map, since it doesn't really show what things this can do :()
 

Viikuna

No Marlo no game.
Reaction score
265
Try BuilderBobs Dungean Crawler map. ( If theres still working version somewhere )

It has pretty cool spammable frost bolt spell. Its basicly a collinsion missile, which on impact makes target unit lil bit slower and blueish and transparent.

Then when you keep pounding enemy with many frostbolts, it becomes even more blue, even more slower and trasnparent, untill it turns entirely to ice and cant move at all.

( That map had pretty awesome spells, like this frostbolt and implode, which had really cool imploding effect ) ( Dont actually remember if it was called implode, but anyways )

You should maybe do some stuff like that for testmap, so people see how cool stuff you can do with vertex color changes.

Or maybe some stacking rage thingy, which makes them bigger and more red when casted?

edit. Also put a list of all user functions up there in your system documentation part for both Libraries. ( Appereance still misses one, ey )
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Try BuilderBobs Dungean Crawler map. ( If theres still working version somewhere )

Well, couldn't find one :(
Any1 else can ? :S

But I'll make a few simple spells like this, and maybe if someone uses this to make a more complex spell, or can maybe put it in here ? :eek:

Also put a list of all user functions up there in your system documentation part for both Libraries.

Ok, will do :D

( Appereance still misses one, ey )

What do you mean ? :S
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Oh, yeah... Will make it too then :D

Also, I tried making this spell as a test... And everything is working fine, it's just that the spell is supposed to go on for 10 seconds on level one, and the scaling does so, but not the buff and damage bonus which is recieved... That stays for about 14 seconds ! :S

Why could that be ?

Here's the code, and I've attached the map too :D

JASS:
scope Rage initializer Init

    globals
        private constant integer ABILITY_ID = &#039;A000&#039;
        private constant integer SPELLBOOK_ID = &#039;A002&#039;
        private constant integer DAMAGEBONUS_ID = &#039;A001&#039;
    endglobals
    
    private struct Data
    
        integer lvl
        unit caster
        player owner
        
        static method create takes unit u returns Data
            local thistype this = thistype.allocate()
            
            set this. caster = u
            set this.owner = GetOwningPlayer( u )
            set this.lvl = GetUnitAbilityLevel( u, ABILITY_ID )
            
            return this
        endmethod
        
        private method onDestroy takes nothing returns nothing
            call UnitRemoveAbility( this.caster, SPELLBOOK_ID )
            call SmoothScaleChange.create( this.caster, 1.0, -( this.lvl * 0.25 ) )
            call SmoothColorChange.create( this.caster, 1.0, 0.0, 255.0, 255.0, ( this.lvl * 42.5 ) )
        endmethod
        
    endstruct
    
    private function Rage_Ends takes nothing returns nothing
        local Data d = GetTimerData( GetExpiredTimer() )
        
        call d.destroy()
        call ReleaseTimer( GetExpiredTimer() )
    endfunction

    private function Rage_Actions takes nothing returns boolean
        local timer t = NewTimer()
        local unit u = GetTriggerUnit()
        local Data d = Data.create( u )
        
        call UnitAddAbility( u, SPELLBOOK_ID )
        call SetPlayerAbilityAvailable( d.owner, SPELLBOOK_ID, false )
        call SetUnitAbilityLevel( u, DAMAGEBONUS_ID, d.lvl )
        call SmoothScaleChange.create( u, 1.0, d.lvl * 0.25 )
        call SmoothColorChange.create( u, 1.0, 0.0, -255.0, -255.0, -( d.lvl * 42.5 ) )
        
        call SetTimerData( t, d )
        call TimerStart( t, ( d.lvl * 5. ) + 5., false, function Rage_Ends )
        
        return GetSpellAbilityId() == ABILITY_ID
    endfunction

//===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( t, Condition( function Rage_Actions ) )
    endfunction

endscope


I've based the Damage Bonus ability on Trueshot Aura, and made it a Unit ability and I've added it to a spell book...
 

Attachments

  • Smooth Unit Modification, non-Test !.w3x
    44.2 KB · Views: 341

Viikuna

No Marlo no game.
Reaction score
265
Also that Get stuff belongs to appereance library.

Also GetUnitRedColor should probably be GetUnitColorRed and stuff like that.

Well, people can just use appearance[ unit ].red anyways, so those Get functions are not neccesarily needed anyways.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Also that Get stuff belongs to appereance library.

Ok, will move it then :D

Also GetUnitRedColor should probably be GetUnitColorRed and stuff like that.

Will change too XD

Well, people can just use appereance[ unit ].red anyways, so those Get functions are not neccesarily needed anyways.

I know, but it's easier to type, imho :p

What about the spell ? :eek:
 

quraji

zap
Reaction score
144
With just a quick look I have a couple suggestions.

First, I don't think those debug messages in the SUM library are that necessary (they don't show a warning/error/etc., could get annoying if I were debugging my map). But if you do keep them, I'd add some kind of description to your debug messages, like "SUM Scaling: ##", instead of just the number.

Second, in the Appearance library, I'd add hooks for the functions, that way you can detect if the user sets the values instead of modifying them with your functions (so your values in the struct aren't wrong). Ex:
JASS:
private function SetUnitScale_hook takes unit whichUnit, real scaleX, real scaleY, real scaleZ returns nothing
    local Appearance this = Appearance[ whichUnit ]
    
    set this.scale = scaleX
endfunction
hook SetUnitScale SetUnitScale_hook


function ModifyUnitScale takes unit u, real addscale returns nothing
    local Appearance this = Appearance[ u ]

    call SetUnitScale( this.unit, this.scale + addscale, 0.,0. ) // how come you only change scaleX?
endfunction


I like the idea of being able to modify the unit property instead of having to set it, cool stuff.

Lastly, I suggest that you make the property members (scale, timescale, red, green, blue, alpha) private and only allow access through get/set methods. Otherwise you can have someone do [ljass]exampleunit.scale = 5.0[/ljass] which will only set the value and not change the unit scale, which will screw the system up.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Thanks soo much for that feedback !!!

It really helped :thup:

First question: Ok, changed that now... It displays "SUM Scaling: ##", "SUM Fading: ##" and "SUM TimeScaling: ##" now, is that OK ?

Seconds question: Good thinking :D Thanks, will make that too ;)

Third:

Lastly, I suggest that you make the property members (scale, timescale, red, green, blue, alpha) private and only allow access through get/set methods. Otherwise you can have someone do [ljass]exampleunit.scale = 5.0[/ljass] which will only set the value and not change the unit scale, which will screw the system up.

Well, people can just use appearance[ unit ].red anyways, so those Get functions are not neccesarily needed anyways.

Who to listen to ?! :S
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, I don't really know how they work...

Could you give me an example ? :eek:

Also:
// how come you only change scaleX?

That's because "X" is the only one needed, as the other ones don't actually do anything...
That's what J4L and Azlier and some other guys told me, wierd isn't it XD
 

Viikuna

No Marlo no game.
Reaction score
265
Yep, thats how it is sadly. I rememebr I once wanted to make a jelly like abomination hero, who would have changed x and y scale alla time, so that total scale stays same. ( Can you imagine how cool that would have been? )

But then when I tried it I found out the terrible truth. :(

Anyways, back on topic.

Quraji is right, make all those members [lJASS]readonly[/lJASS] and use hooks to make sure that struct has correct values. ( Good idea, I must say. :thup: )

edit. Or method operators instead of readonly, they do the job too, like quraji mentioned.
 

Romek

Super Moderator
Reaction score
963
JASS:
struct Example

static method operator example takes nothing returns string
   // Do stuff
   return &quot;A&quot;
endmethod

static method operator example= takes string value returns nothing
  call BJDebugMsg(&quot;Hello&quot;)
endmethod

static method operator [] takes integer index returns string
   // Stuff
   return &quot;B&quot;
endmethod

static method operator []= takes integer index, string value returns nothing
   call BJDebugMsg(&quot;World&quot;)
endmethod

endstruct


[ljass]call BJDebugMsg(Example.example)[/ljass] will display "A". Note the struct member syntax. This is not treated as a method.
[ljass]set Example.example = "Anything"[/ljass] will display "Hello". Although we seem to be setting a value, the method operator example= doesn't do anything other than display a message.

The [] and []= operators are similar, except that they each take an additional value (which could be any type), as an index.
[ljass]Example[-1][/ljass] will return "B". Note that similarly to above, the index isn't used.
[ljass]set Example[-1] = "Anything"[/ljass] will display "World". I'm sure you can figure out why now. :p
 

Viikuna

No Marlo no game.
Reaction score
265
Something like this should do the job too:
JASS:
library UnitAppearance requires AIDS

    struct Appearance extends array
        //! runtextmacro AIDS()

        readonly real scale
        
        readonly real timescale
        
        readonly integer alpha
        readonly integer red
        readonly integer green
        readonly integer blue
        
        private method AIDS_onCreate takes nothing returns nothing
            set .scale = 1.
            
            set .alpha = 255
            set .red = 255
            set .green = 255
            set .blue = 255
            
            set .timescale = 1.
        endmethod
        
        static method saveScale takes unit whichUnit, real newScaleX, real ewScaleY, real ewScaleZ returns nothing
               local Appearance this=Appearance[ whichUnit ]
               set .scale=newScaleX
        endmethod
        
        static method saveColor takes unit whichUnit, real newRed, real newGreen, real newBlue, real newAlpha returns nothing
               local Appearance this=Appearance[ whichUnit ]
               set .red=.newRed
               set .green=.greenRed
               set .blue=.blueRed
               set .alpha=.alphaRed
        endmethod
        
        static method saveTimeScale takes unit whichUnit, real newTimeScale returns nothing
               local Appearance this=Appearance[ whichUnit ]
               set .timescale=newTimeScale
        endmethod
        
    endstruct
    
    hook SetUnitScale       Appearance.saveScale
    hook SetUnitVertexColor Appearance.saveColor
    hook SetUnitTimeScale   Appearance.saveTimeScale
    
    function ModifyUnitScale takes unit u, real addscale returns nothing
        local Appearance this=Appearance[ u ]
        call SetUnitScale(.unit,.scale+addscale,0.,0.)
    endfunction
    
    function ModifyUnitVertexColor takes unit u, integer addred, integer addgreen, integer addblue, integer addalpha returns nothing
        local Appearance this=Appearance<u>
        call SetUnitVertexColor(.unit,.red+addred,.green+addgreen,.blue+addblue,.alpha+addalpha)
    endfunction
    
    function ModifyUnitTimeScale takes unit u, real addtimescale returns nothing
        local Appearance this=Appearance[ u ]
        call SetUnitTimeScale(.unit,.timescale+addtimescale )
    endfunction
    
endlibrary</u>


edit. [lJASS]readonly[/lJASS] means that you can only set those values to those members inside the struct.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, I did this... Though haven't used operators or readonly yer, but :
JASS:
library UnitAppearance requires AIDS

///////////////////////////////////////////////////////////////////////////////////////////////////////
//***************************************************************************************************//
//@@/////////////////////////////////// *// UnitAppearance \\* ////////////////////////////////////@@//
//@@                                     Made by , Komaqtion !                                     @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                          Purpose:                                             @@//
//@@                                                                                               @@//
//@@             ¤ An easy way of simply adding or remove a set value from a unit&#039;s scale,         @@//
//@@               vertex color or timescale... This will also save the unit&#039;s current value       @@//
//@@               in a truct using AIDS, which gives the user the opportunity to &quot;Get&quot; that       @@//
//@@               value at any time.                                                              @@//
//@@                                                                                               @@//
//@@                                           Usage:                                              @@//
//@@                                                                                               @@//
//@@             ¤ The function that this system provides the user are:                            @@//
//@@               You can also use this system to &quot;get&quot; 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...                            @@//
//@@                                                                                               @@//
//@@               function GetUnitColorAlpha takes unit u returns real                            @@//
//@@               function GetUnitColorRed takes unit u returns real                              @@//
//@@               function GetUnitColorGreen takes unit u returns real                            @@//
//@@               function GetUnitColorBlue takes unit u returns real                             @@//
//@@                                                                                               @@//
//@@               Which will give you the current colors of the unit...                           @@//
//@@                                                                                               @@//
//@@               function GetUnitTimeScale takes unit u returns real                             @@//
//@@                                                                                               @@//
//@@               Which will give you the current timescale of the unit...                        @@//
//@@                                                                                               @@//
//@@                                           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 !        @@//
//@@                                                                                               @@//
//@@                                       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 AIDS !                                  @@//
//@@                                                                                               @@//
//@@                                         Credits:                                              @@//
//@@                                                                                               @@//
//@@             ¤ Viikuna, for helping me out, and also helping me make &quot;UnitAppearance&quot; !        @@//
//@@               Jesus4Lyf, for also helping me out alot, and making AIDS ! <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" />                   @@//
//@@               Quiraji, for some suggestions and 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 Appearance extends array
        //! runtextmacro AIDS()

        real scale
        
        real timescale
        
        integer alpha
        integer red
        integer green
        integer blue
        
        private method AIDS_onCreate takes nothing returns nothing
            set this.scale = 1.
            
            set this.alpha = 255
            set this.red = 255
            set this.green = 255
            set this.blue = 255
            
            set this.timescale = 1.
        endmethod
        
    endstruct

    function ModifyUnitScale takes unit u, real addscale returns nothing
        local Appearance this = Appearance[ u ]
        
        set this.scale = this.scale + addscale
        
        if this.scale &lt; 0 then
            set this.scale = 0
        endif
        
        call SetUnitScale( this.unit, this.scale, 0.,0. )
    endfunction
    
    function GetUnitScale takes unit u returns real
        return Appearance[ u ].scale
    endfunction
    
    private function ScaleHook takes unit u, real x, real y, real z returns nothing
        local Appearance this = Appearance[ u ]
    
        set this.scale = x
    endfunction
    
    hook SetUnitScale ScaleHook
    
    function ModifyUnitVertexColor takes unit u, integer addred, integer addgreen, integer addblue, integer addalpha returns nothing
        local Appearance this = Appearance[ u ]
        
        set this.alpha = this.alpha + addalpha
        set this.red = this.red + addred
        set this.green = this.green + addgreen
        set this.blue = this.blue + addblue
        
        if this.alpha &lt; 0 then
            set this.alpha = 0
        endif
        
        if this.red &lt; 0 then
            set this.red = 0
        endif
        
        if this.green &lt; 0 then
            set this.green = 0
        endif
        
        if this.blue &lt; 0 then
            set this.blue = 0
        endif
        
        call SetUnitVertexColor( this.unit, this.red, this.green, this.blue, this.alpha )
    endfunction
    
    function GetUnitColorAlpha takes unit u returns integer
        return Appearance[ u ].alpha
    endfunction

    function GetUnitColorRed takes unit u returns integer
        return Appearance[ u ].red
    endfunction
    
    function GetUnitColorGreen takes unit u returns integer
        return Appearance[ u ].green
    endfunction
    
    function GetUnitColorBlue takes unit u returns integer
        return Appearance[ u ].blue
    endfunction
    
    private function FadeHook takes unit u, integer red, integer green, integer blue, integer alpha returns nothing
        local Appearance this = Appearance[ u ]
    
        set this.alpha = alpha
        set this.red = red
        set this.green = green
        set this.blue = blue
    endfunction
    
    hook SetUnitVertexColor FadeHook
    
    function ModifyUnitTimeScale takes unit u, real addtimescale returns nothing
        local Appearance this = Appearance[ u ]
        
        set this.timescale = this.timescale + addtimescale
        
        if this.timescale &lt; 0 then
            set this.timescale = 0
        endif
        
        call SetUnitTimeScale( this.unit, this.timescale )
    endfunction
    
    function GetUnitTimeScale takes unit u returns real
        return Appearance[ u ].timescale
    endfunction
    
    private function TimeScaleHook takes unit u, real timescale returns nothing
        local Appearance this = Appearance[ u ]
    
        set this.timescale = timescale
    endfunction
    
    hook SetUnitTimeScale TimeScaleHook
    
endlibrary


Btw, I'd rather us operators, how to ? :S
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top