Komaqtion
You can change this now in User CP.
- Reaction score
- 469
SUM
Smooth Unit Modification
Smooth Unit Modification
Requirements ( SUM ): Timer 32, by Jesus4Lyf and my other system called "UnitAppearance" which you can see here below
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
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" /> @@//
//@@ @@//
//@@ -> function ScaleUnitToValue takes unit Modifier, real Time, @@//
//@@ real scaleValue 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 scaleValue" is to what value you want the modifier's scale to change to. @@//
//@@ Unlike that "ScaleUnitByValue" function, here you input a specific value @@//
//@@ you want the unit to be scaled to. @@//
//@@ "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" /> @@//
//@@ @@//
//@@ -> function GetUnitScale takes unit u returns real @@//
//@@ @@//
//@@ "unit u" is the unit of which scale you wish to retrieve. @@//
//@@ "returns real": This is the current scale of the unit. @@//
//@@ @@//
//@@ And here's an example of how to use these "scaling" functions: @@//
//@@ @@//
//@@ call ScaleUnitToValue( GetTriggerUnit(), 2.0, GetUnitScale( GetTriggerUnit() ) / 2. ) @@//
//@@ @@//
//@@ Will scale the triggering unit to half it'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 'scaling' functions ): @@//
//@@ @@//
//@@ -> function ChangeTimeScaleByValue takes unit Modifier, real Time, @@//
//@@ real timescaleMod returns SmoothTSChange @@//
//@@ @@//
//@@ -> function ChangeTimeScaleToValue takes unit Modifier, real Time, @@//
//@@ real timescaleValue returns SmoothTSChange @@//
//@@ @@//
//@@ -> function GetUnitTimeScale takes unit u returns real @@//
//@@ @@//
//@@ These functions, and their parameters, work exactly the same as the "scaling" @@//
//@@ part of this system/snippet: @@//
//@@ @@//
//@@ "unit Modifier" is the unit you wish to change the time-scale of. @@//
//@@ "real Time" is the amount of time you wish the modification should take. @@//
//@@ "real timescaleMod/Value" is, as in the "scaling" functions, the amount @@//
//@@ you want the unit's time-scale to change by/to. @@//
//@@ "returns SmoothTSChange", just as in the "scaling" 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 "GetUnitTimeScale" 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: @@//
//@@ @@//
//@@ -> function FadeUnitByValue takes unit Modifier, real Time, @@//
//@@ real alphaMod returns SmoothColorChange @@//
//@@ @@//
//@@ -> function FadeUnitARGBByValue takes unit Modifier, real Time, @@//
//@@ real redMod, real greenMod, real blueMod, @@//
//@@ real alphaMod returns SmoothColorChange @@//
//@@ @@//
//@@ -> function FadeUnitToValue takes unit Modifier, real Time, @@//
//@@ real alphaValue returns SmoothColorChange @@//
//@@ @@//
//@@ -> 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: @@//
//@@ @@//
//@@ "unit Modifier", as in all other functions, this is the unit to be modified. @@//
//@@ "real Time", and again, this is the amount of time the process is gonna take. @@//
//@@ "real alphaMod" is the amount you wish to change the unit's alpha color. @@//
//@@ "real alphaValue" is the value you wish to get after the smooth fading @@//
//@@ process is done. @@//
//@@ "real redMod/Value" is the same as above. @@//
//@@ "real greenMod/Value" is, yet again, same as two/three lines above. @@//
//@@ "real blueMod/Value" 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" /> @@//
//@@ @@//
//@@ -> function GetUnitColorAlpha takes unit u returns integer @@//
//@@ @@//
//@@ -> function GetUnitColorRed takes unit u returns integer @@//
//@@ @@//
//@@ -> function GetUnitColorGreen takes unit u returns integer @@//
//@@ @@//
//@@ -> 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's parameter is: @@//
//@@ @@//
//@@ "unit u", 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'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 @@//
//@@ "currentScale" and "doneScale" 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'll also have to update JASS Helper to the latest version... @@//
//@@ And, then you'll need the system called Timer32 (T32), and also my other @@//
//@@ snippet, called "UnitAppearance" <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 "UnitAppearance" ! @@//
//@@ 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'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 > 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., "#SUM# - Scale: " + R2S( Appearance[ u ].currentScale ) )
if ticks <= 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 > 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., "#SUM# - Red: " + I2S( R2I( Appearance<u>.currentRed ) ) )
debug call DisplayTimedTextToPlayer( GetLocalPlayer(), 0., 0., 6000., "#SUM# - Green: " + I2S( R2I( Appearance<u>.currentGreen ) ) )
debug call DisplayTimedTextToPlayer( GetLocalPlayer(), 0., 0., 6000., "#SUM# - Blue: " + I2S( R2I( Appearance<u>.currentBlue ) ) )
debug call DisplayTimedTextToPlayer( GetLocalPlayer(), 0., 0., 6000., "#SUM# - Alpha: " + I2S( R2I( Appearance<u>.currentAlpha ) ) )
if ticks <= 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 > 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., "#SUM# - Timescale :" + R2S( Appearance[ u ].currentTimescale ) )
if ticks <= 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