T32, how to use the ".startperiodic" method ? :S

Komaqtion

You can change this now in User CP.
Reaction score
469
Oh, ok XD

Well, this is what I have now, and it isn't working...

JASS:
library ScaleAndFade requires KT, ModifyAppearance

    globals
        private constant real PERIOD = 0.03125
    endglobals

    struct SmoothScale
    
        private unit u
        private real scale
        private real endScale
        private real increment
        //private code userFunc
        
        private static method periodic takes nothing returns boolean
            local SmoothScale this = KT_GetData()
            
            //set this.scale = this.scale + this.increment
            
            if ( this.scale > this.endScale and this.increment > 0 ) or ( this.scale < this.endScale and this.increment < 0 ) then
                call this.destroy()
                //call this.userFunc.execute()
                
                return true
            endif
            
            call ModifyUnitScale( this.u, this.increment )
            
            debug call BJDebugMsg( R2S( this.scale ) )
                        
            return false
        endmethod
        
        static method create takes unit Scaler, real startScale, real endScale, real Time, real Period, code userFunc returns thistype
            local thistype this = thistype.allocate()
            local real period
            
            if Period > 0 then
                set period = Period
            else
                set period = PERIOD
            endif
            
            set this.u = Scaler
            set this.scale = startScale
            set this.endScale = endScale
            //set this.userFunc = userFunc
            set this.increment = ( ( ( endScale - startScale ) * period ) / Time )
                
            call KT_Add( function thistype.periodic, this, period )
            
            return this
        endmethod
        
    endstruct
    
    function ScaleSimple takes unit Scaler, real startScale, real endScale, real Time returns SmoothScale
        return SmoothScale.create( Scaler, startScale, endScale, Time, 0., null )
    endfunction
    
    function ScaleSimplePeriod takes unit Scaler, real startScale, real endScale, real Time, real Period, code userFunc returns SmoothScale
        return SmoothScale.create( Scaler, startScale, endScale, Time, Period, null )
    endfunction
    
    function ScaleEx takes unit Scaler, real startScale, real endScale, real Time, real Period, code userFunc returns SmoothScale
        return SmoothScale.create( Scaler, startScale, endScale, Time, 0., userFunc )
    endfunction
    
    function ScaleExPeriod takes unit Scaler, real startScale, real endScale, real Time, real Period, code userFunc returns SmoothScale
        return SmoothScale.create( Scaler, startScale, endScale, Time, Period, userFunc )
    endfunction
    
    struct SmoothFade
    
        private real rincrement
        private real gincrement
        private real bincrement
        private real alpha
        private real increment
        private real endAlpha
        private unit u
        
        private static method periodic takes nothing returns boolean
            local SmoothFade this = KT_GetData()
            
            //set this.alpha = this.alpha + this.increment
            
            if ( this.alpha > this.endAlpha and this.increment > 0 ) or ( this.alpha < this.endAlpha and this.increment < 0 ) then
                call this.destroy()
                
                return true
            endif
            
            if this.rincrement == 0 and this.gincrement == 0 and this.bincrement == 0 then
                call ModifyUnitVertexColor( this.u, 255, 255, 255, R2I( this.increment ) )
            else
                call ModifyUnitVertexColor( this.u, R2I( this.rincrement ), R2I( this.gincrement ), R2I( this.bincrement ), R2I( this.increment ) )
            endif
            
            debug call BJDebugMsg( R2S( Appearance[ this.u ].alpha ) )
            
            return false
        endmethod
        
        static method create takes unit Fader, boolean StaticRGB, real startAlpha, real endAlpha, real Time, real Period, real startRed, real startGreen, real startBlue, real endRed, real endGreen, real endBlue returns thistype
            local thistype this = thistype.allocate()
            local real period
            
            if Period > 0 then
                set period = Period
            else
                set period = PERIOD
            endif
            
            set this.u = Fader
            set this.alpha = startAlpha
            set this.endAlpha = endAlpha
            set this.increment = ( ( ( endAlpha - startAlpha ) * period ) / Time )
                
            if StaticRGB != true then
                set this.rincrement = ( ( ( endRed - startRed ) * period ) / Time )
                set this.gincrement = ( ( ( endGreen - startGreen ) * period ) / Time )
                set this.bincrement = ( ( ( endBlue - startBlue ) * period ) / Time )
            endif
                
            call KT_Add( function thistype.periodic, this, period )
            
            return this
        endmethod
        
    endstruct
    
    function FadeSimple takes unit Fader, real startAlpha, real endAlpha, real Time returns SmoothFade
        return SmoothFade.create( Fader, true, startAlpha, endAlpha, Time, 0., 255., 255., 255., 255., 255., 255. )
    endfunction
    
    function FadeSimplePeriod takes unit Fader, real startAlpha, real endAlpha, real Time, real Period returns SmoothFade
        return SmoothFade.create( Fader, true, startAlpha, endAlpha, Time, Period, 255., 255., 255., 255., 255., 255. )
    endfunction
    
    function FadeEx takes unit Fader, real startAlpha, real endAlpha, real Time, real startRed, real startGreen, real startBlue, real endRed, real endGreen, real endBlue returns SmoothFade
        return SmoothFade.create( Fader, false, startAlpha, endAlpha, Time, 0., startRed, startGreen, startBlue, endRed, endGreen, endBlue )
    endfunction
    
    function FadeExStatic takes unit Fader, real startAlpha, real endAlpha, real Time, real startRed, real startGreen, real startBlue, real endRed, real endGreen, real endBlue returns SmoothFade
        return SmoothFade.create( Fader, true, startAlpha, endAlpha, Time, 0., startRed, startGreen, startBlue, endRed, endGreen, endBlue )
    endfunction
    
    function FadeExPeriod takes unit Fader, real startAlpha, real endAlpha, real Time, real Period, real startRed, real startGreen, real startBlue, real endRed, real endGreen, real endBlue returns SmoothFade
        return SmoothFade.create( Fader, true, startAlpha, endAlpha, Time, Period, startRed, startGreen, startBlue, endRed, endGreen, endBlue )
    endfunction
    
    function FadeExPeriodStatic takes unit Fader, real startAlpha, real endAlpha, real Time, real Period, real startRed, real startGreen, real startBlue, real endRed, real endGreen, real endBlue returns SmoothFade
        return SmoothFade.create( Fader, false, startAlpha, endAlpha, Time, Period, startRed, startGreen, startBlue, endRed, endGreen, endBlue )
    endfunction

endlibrary


I saw that I can't use [ljass]set this.alpha = this.alpha + this.increment[/ljass] and [ljass]call ModifyUnitVertexColor( this.u, 255, 255, 255, R2I( this.alpha ) )[/ljass] since Appearance[ this.u ].alpha became like 6000.0 big ! XD

Or, did I do something wrong now ? :S
 

Viikuna

No Marlo no game.
Reaction score
265
You should probably change syntax to something like: Apply X size over Y second.

(unit, -2. , 10. ) Would make unit shrink by 20% of its default size over 10 seconds.

You already know the current size, so you dont need that starting value.

edit. for color you could do something like: [lJASS]( unit, -20/*red*/, -20 /*green*/, 0/*blue*/, -10/*alpha*/,5./*duration*/ )[/lJASS] This would make unit lil bit more blue and transparent. ( cool for some frozen unit effect thingy )



And I dont get why you changed to KT, since T32 is better for stuff like this.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, here's what I have atm...

JASS:
library ModifyAppearance requires AIDS

    struct Appearance extends array
        //! runtextmacro AIDS()

        real scale
        
        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
        endmethod
        
    endstruct

    function ModifyUnitScale takes unit u, real addscale returns nothing
        local Appearance this = Appearance[ u ]
        
        set this.scale = this.scale + addscale
        
        call SetUnitScale( this.unit, this.scale, 0.,0. )
    endfunction
    
    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
        
        call SetUnitVertexColor( this.unit, this.red, this.green, this.blue, this.alpha )
    endfunction
    
endlibrary


And here's the other one :p

JASS:
library ScaleAndFade requires T32, ModifyAppearance

    globals
        private constant real PERIOD = 0.03125
    endglobals

    struct SmoothScale
    
        private unit u
        private real scaleMod
        private real increment
        //private code userFunc
        
        private method periodic takes nothing returns boolean
        
            if ( Appearance[ this.u ].scale > this.scaleMod and this.increment > 0 ) or ( Appearance[ this.u ].scale < this.scaleMod and this.increment < 0 ) then
                call this.destroy()
                //call this.userFunc.execute()
                
                return true
            endif
            
            call ModifyUnitScale( this.u, this.increment )
            
            debug call BJDebugMsg( R2S( Appearance[ this.u ].scale ) )
                        
            return false
        endmethod
        
        implement T32
        
        static method create takes unit Scaler, real Time, real scaleMod, code userFunc returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Scaler
            set this.scaleMod = Appearance[ Scaler ].scale + scaleMod
            //set this.userFunc = userFunc
            set this.increment = ( ( Appearance[ Scaler ].scale * PERIOD ) / Time )
                
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    function ScaleSimple takes unit Scaler, real Time, real scaleMod returns SmoothScale
        return SmoothScale.create( Scaler, Time, scaleMod, null )
    endfunction
    
    function ScaleEx takes unit Scaler, real Time, real scaleMod, code userFunc returns SmoothScale
        return SmoothScale.create( Scaler, Time, scaleMod, userFunc )
    endfunction
    
    struct SmoothFade
    
        private real rincrement
        private real gincrement
        private real bincrement
        private real increment
        private real endAlpha
        private unit u
        
        private method periodic takes nothing returns boolean

            if ( Appearance[ this.u ].alpha > this.endAlpha and this.increment > 0 ) or ( Appearance[ this.u ].alpha < this.endAlpha and this.increment < 0 ) then
                call this.destroy()
                
                return true
            endif
            
            if this.rincrement == 0 and this.gincrement == 0 and this.bincrement == 0 then
                call ModifyUnitVertexColor( this.u, 255, 255, 255, R2I( this.increment ) )
            else
                call ModifyUnitVertexColor( this.u, R2I( this.rincrement ), R2I( this.gincrement ), R2I( this.bincrement ), R2I( this.increment ) )
            endif
            
            debug call BJDebugMsg( R2S( Appearance[ this.u ].alpha ) )
            
            return false
        endmethod
        
        implement T32
        
        static method create takes unit Fader, boolean StaticRGB, real Time, real redMod, real greenMod, real blueMod, real alphaMod returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Fader
            set this.endAlpha = Appearance[ Fader ].alpha + alphaMod
            set this.increment = ( ( this.endAlpha * PERIOD ) / Time )
                
            if StaticRGB != true then
                set this.rincrement = ( ( ( Appearance[ Fader ].red + redMod ) * PERIOD ) / Time )
                set this.gincrement = ( ( ( Appearance[ Fader ].green + greenMod ) * PERIOD ) / Time )
                set this.bincrement = ( ( ( Appearance[ Fader ].blue + blueMod ) * PERIOD ) / Time )
            endif
            
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    function FadeSimple takes unit Fader, real Time, real alphaMod returns SmoothFade
        return SmoothFade.create( Fader, true, Time, 0., 0., 0., alphaMod )
    endfunction
    
    function FadeEx takes unit Fader, real Time, real redMod, real greenMod, real blueMod, real alphaMod returns SmoothFade
        return SmoothFade.create( Fader, true, Time, redMod, greenMod, blueMod, alphaMod )
    endfunction
    
    function FadeExStatic takes unit Fader, real Time, real redMod, real greenMod, real blueMod, real alphaMod returns SmoothFade
        return SmoothFade.create( Fader, false, Time, redMod, greenMod, blueMod, alphaMod )
    endfunction

endlibrary


Bot nothing's happening with these test triggers:
Trigger:
  • Test Scale Dec
    • Events
      • Player - Player 1 (Red) types a chat message containing scale de as An exact match
    • Conditions
    • Actions
      • Set TempGroup = (Units owned by (Triggering player))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Custom script: call SmoothScale.create( GetEnumUnit(), 2.5, -.5, null )
      • Custom script: call DestroyGroup(udg_TempGroup)


Trigger:
  • Test Fade Dec
    • Events
      • Player - Player 1 (Red) types a chat message containing fade de as An exact match
    • Conditions
    • Actions
      • Set TempGroup = (Units owned by (Triggering player))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Custom script: call SmoothFade.create( GetEnumUnit(), true, 2.5, 0., 0., 0., -.5 )
      • Custom script: call DestroyGroup(udg_TempGroup)


:(

Any ideas ? :S
 

Viikuna

No Marlo no game.
Reaction score
265
Well, in your periodic method you keep setting units scale to same value all the time: [lJASS]call ModifyUnitScale( this.u, this.increment ) [/lJASS]

edit. Also you need to learn how to properly Debug your code. Just start checking your actions line by line with some DebugMsgs to find out what works and what doesnt.

edit. Also you should probably add timeScale and ModifyUnitTimeScale to that appereance struct.

I cant really think why would someone want to fade time scale overtime,so doing fading struct for it is probably useless ,but getting units current time scale would be good as well as some function to modify it.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
edit. Also you should probably add timeScale and ModifyUnitTimeScale to that appereance struct.

I cant really think why would someone want to fade time scale overtime,so doing fading struct for it is probably useless ,but getting units current time scale would be good as well as some function to modify it.

Can't say I get whay you mean there :S
timeScale ? :eek:
 

Viikuna

No Marlo no game.
Reaction score
265
Yea, Time Scale. I belive its called Animation Speed in GUI or something like that.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, well I've now tried to do what you said (Not the timescale yet though) but now it'll only let me scale up, and not down (No message is shown when I scale down, but do when I scale up...)
And, it won't let me fade in any way :(
There's just these messages shown when I fade down for the first time:

And, then when I decrease after that, it show me this:
255.00
1.594
255.00
1.594

And, then when I fade up after that, it show me this:
255.00
3.194
255.00
3.194
258.00
3.194
258.00
3.194

So, that seems a bit wierd to me XD

Here are the test triggers (Yet again :p)
Trigger:
  • Test Scale Dec
    • Events
      • Player - Player 1 (Red) types a chat message containing scale de as An exact match
    • Conditions
    • Actions
      • Set TempGroup = (Units owned by (Triggering player))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Custom script: call SmoothScale.create( GetEnumUnit(), 2.5, -.5, null )
      • Custom script: call DestroyGroup(udg_TempGroup)

Trigger:
  • Test Scale Inc
    • Events
      • Player - Player 1 (Red) types a chat message containing scale in as An exact match
    • Conditions
    • Actions
      • Set TempGroup = (Units owned by (Triggering player))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Custom script: call SmoothScale.create( GetEnumUnit(), 2.5, .5, null )
      • Custom script: call DestroyGroup(udg_TempGroup)

Trigger:
  • Test Fade Dec
    • Events
      • Player - Player 1 (Red) types a chat message containing fade de as An exact match
    • Conditions
    • Actions
      • Set TempGroup = (Units owned by (Triggering player))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Custom script: call SmoothFade.create( GetEnumUnit(), true, 2.5, 0., 0., 0., -127.5 )
      • Custom script: call DestroyGroup(udg_TempGroup)

Trigger:
  • Test Fade Inc
    • Events
      • Player - Player 1 (Red) types a chat message containing fade in as An exact match
    • Conditions
    • Actions
      • Set TempGroup = (Units owned by (Triggering player))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Custom script: call SmoothFade.create( GetEnumUnit(), true, 2.5, 0., 0., 0., 72.5 )
      • Custom script: call DestroyGroup(udg_TempGroup)


And, here's the script ;)

JASS:
library ScaleAndFade requires T32, ModifyAppearance

    struct SmoothScale
    
        private unit u
        private real scaleMod
        private real increment
        //private code userFunc
        
        private method periodic takes nothing returns boolean
        
            if ( Appearance[ this.u ].scale >= this.scaleMod and this.increment > 0 ) or ( Appearance[ this.u ].scale <= this.scaleMod and this.increment < 0 ) then
                call this.destroy()
                //call this.userFunc.execute()
                
                return true
            endif
            
            call ModifyUnitScale( this.u, this.increment )
            
            debug call BJDebugMsg( R2S( Appearance[ this.u ].scale ) )
                        
            return false
        endmethod
        
        implement T32
        
        static method create takes unit Scaler, real Time, real scaleMod, code userFunc returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Scaler
            set this.scaleMod = Appearance[ Scaler ].scale + scaleMod
            //set this.userFunc = userFunc
            set this.increment = ( ( Appearance[ Scaler ].scale * T32_PERIOD ) / Time )
                
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    function ScaleSimple takes unit Scaler, real Time, real scaleMod returns SmoothScale
        return SmoothScale.create( Scaler, Time, scaleMod, null )
    endfunction
    
    function ScaleEx takes unit Scaler, real Time, real scaleMod, code userFunc returns SmoothScale
        return SmoothScale.create( Scaler, Time, scaleMod, userFunc )
    endfunction
    
    struct SmoothFade
    
        private real rincrement
        private real gincrement
        private real bincrement
        private real increment
        private real endAlpha
        private unit u
        
        private method periodic takes nothing returns boolean

            if ( Appearance[ this.u ].alpha >= this.endAlpha and this.increment > 0 ) or ( Appearance[ this.u ].alpha <= this.endAlpha and this.increment < 0 ) then
                call this.destroy()
                
                return true
            endif
            
            call ModifyUnitVertexColor( this.u, R2I( this.rincrement ), R2I( this.gincrement ), R2I( this.bincrement ), R2I( this.increment ) )
            
            debug call BJDebugMsg( R2S( Appearance[ this.u ].alpha ) )
            debug call BJDebugMsg( R2S( this.increment ) )
            
            return false
        endmethod
        
        implement T32
        
        static method create takes unit Fader, boolean StaticRGB, real Time, real redMod, real greenMod, real blueMod, real alphaMod returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Fader
            set this.endAlpha = Appearance[ Fader ].alpha + alphaMod
            set this.increment = ( ( this.endAlpha * T32_PERIOD ) / Time )
                
            if StaticRGB != true then
                set this.rincrement = ( ( ( Appearance[ Fader ].red + redMod ) * T32_PERIOD ) / Time )
                set this.gincrement = ( ( ( Appearance[ Fader ].green + greenMod ) * T32_PERIOD ) / Time )
                set this.bincrement = ( ( ( Appearance[ Fader ].blue + blueMod ) * T32_PERIOD ) / Time )
            endif
            
            debug call BJDebugMsg( R2S( Appearance[ this.u ].alpha ) )
            debug call BJDebugMsg( R2S( this.increment ) )
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    function FadeSimple takes unit Fader, real Time, real alphaMod returns SmoothFade
        return SmoothFade.create( Fader, true, Time, 0., 0., 0., alphaMod )
    endfunction
    
    function FadeEx takes unit Fader, real Time, real redMod, real greenMod, real blueMod, real alphaMod returns SmoothFade
        return SmoothFade.create( Fader, true, Time, redMod, greenMod, blueMod, alphaMod )
    endfunction
    
    function FadeExStatic takes unit Fader, real Time, real redMod, real greenMod, real blueMod, real alphaMod returns SmoothFade
        return SmoothFade.create( Fader, false, Time, redMod, greenMod, blueMod, alphaMod )
    endfunction

endlibrary
 

Jesus4Lyf

Good Idea™
Reaction score
397
JASS:
struct SmoothScale
    
        private unit u
        private real scaleMod
        private real increment
        //private code userFunc
        
        private method periodic takes nothing returns boolean
        
            if ( Appearance[ this.u ].scale >= this.scaleMod and this.increment > 0 ) or ( Appearance[ this.u ].scale <= this.scaleMod and this.increment < 0 ) then
                call this.destroy()
                //call this.userFunc.execute()
                
                return true
            endif
            
            call ModifyUnitScale( this.u, this.increment )
            
            debug call BJDebugMsg( R2S( Appearance[ this.u ].scale ) )
                        
            return false
        endmethod
        
        implement T32
        
        static method create takes unit Scaler, real Time, real scaleMod, code userFunc returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Scaler
            set this.scaleMod = Appearance[ Scaler ].scale + scaleMod
            //set this.userFunc = userFunc
            set this.increment = ( ( Appearance[ Scaler ].scale * T32_PERIOD ) / Time )
                
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct

-->
JASS:
struct SmoothScale
    
        private unit u
        private integer ticks
        private real increment
        //private code userFunc
        
        private method periodic takes nothing returns boolean
            call ModifyUnitScale( this.u, this.increment )
            
            if this.ticks==0 then
                call this.destroy()
                return true
            endif
            set this.ticks=this.ticks-1
            
            //debug call BJDebugMsg( R2S( Appearance[ this.u ].scale ) )
            
            return false
        endmethod
        
        implement T32
        
        static method create takes unit Scaler, real Time, real scaleMod, code userFunc returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Scaler
            //set this.userFunc = userFunc
            set this.increment = ( ( scaleMod * T32_PERIOD ) / Time )
            set this.ticks = R2I( scaleMod / this.increment ) // How many times the timer must fire...
            
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct

I recommend you remove the code parameter. ;)
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok.. Thanks ! :D

But, I don't wanna remove the "code" parameter, I want to know how to use it ;)
I'd ike the user to be able to have a callback...
Any ideas on how to do it ? :eek:
 

Jesus4Lyf

Good Idea™
Reaction score
397
Tell them to use T32? :thup:

And I'd hate to see a system like this try to provide a callback, unless you can justify it logically some how...

But the way is attach it as a condition or action to a trigger and then fire the condition or action of the trigger with [LJASS]TriggerExecute[/LJASS] or [LJASS]TriggerEvaluate[/LJASS].

Then you need ways to pass data and all kinds of junk. And it is, of course, much slower than the user just using T32. <_<
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, then...
Would you consider this system done now, then ? :eek:

Oh, btw I implemented TimeScale into the "ModifyUnitAppearence" trigger, like this:
JASS:
library ModifyAppearance requires AIDS

    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
        
        call SetUnitScale( this.unit, this.scale, 0.,0. )
    endfunction
    
    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
        
        call SetUnitVertexColor( this.unit, this.red, this.green, this.blue, this.alpha )
    endfunction
    
    function ModifyUnitTimeScale takes unit u, real addtimescale returns nothing
        local Appearance this = Appearance[ u ]
        
        set this.timescale = this.timescale + addtimescale
        
        call SetUnitTimeScale( this.unit, this.timescale )
    endfunction
    
endlibrary


Should I somehow use that in the "main-trigger" too ? :S
I mean, it would be kinda cool to slow down a unit over time, imho :p
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, so I've now added the TimeScale methods and struct ;)

Here's how it looks:
JASS:
library SmoothUnitMod requires T32, ModifyAppearance

    struct SmoothScaleChange
    
        //private code userFunc
        private integer ticks
        
        private real increment
        
        private unit u
        
        private method periodic takes nothing returns boolean
            set this.ticks = this.ticks - 1
        
            call ModifyUnitScale( this.u, this.increment )
            
            debug call BJDebugMsg( R2S( Appearance[ this.u ].scale ) )
            
            if this.ticks &lt;= 0 then
                call this.destroy()
                
                return true
            endif
            
            return false
        endmethod
        
        implement T32
        
        static method create takes unit Scaler, real Time, real scaleMod, code userFunc returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Scaler
            //set this.userFunc = userFunc
            set this.increment = ( ( scaleMod * T32_PERIOD ) / Time )
            set this.ticks = R2I( scaleMod / this.increment ) // How many times the timer must fire...
            
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    function ScaleSimple takes unit Scaler, real Time, real scaleMod returns SmoothScaleChange
        return SmoothScaleChange.create( Scaler, Time, scaleMod, null )
    endfunction
    
    function ScaleEx takes unit Scaler, real Time, real scaleMod, code userFunc returns SmoothScaleChange
        return SmoothScaleChange.create( Scaler, Time, scaleMod, userFunc )
    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 boolean
            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( R2S( Appearance[this.u].alpha ) )
            
            if this.ticks &lt;= 0 then
                call this.destroy()
                
                return true
            endif
            
            return false
        endmethod
        
        implement T32
        
        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 )
            set this.ticks = R2I( alphaMod / this.increment )

            debug call BJDebugMsg( R2S( Appearance[ this.u ].alpha ) )
            
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    function FadeSimple takes unit Fader, real Time, real alphaMod returns SmoothColorChange
        return SmoothColorChange.create( Fader, Time, 0., 0., 0., alphaMod )
    endfunction
    
    function FadeEx 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 GetUnitAlpha takes unit u returns integer
        return Appearance[ u ].alpha
    endfunction

    function GetUnitRedColor takes unit u returns integer
        return Appearance[ u ].red
    endfunction
    
    function GetUnitGreenColor takes unit u returns integer
        return Appearance[ u ].green
    endfunction
    
    function GetUnitBlueColor takes unit u returns integer
        return Appearance[ u ].blue
    endfunction
    
    struct SmoothTSChange
    
        //private code userFunc
        private integer ticks
        
        private real increment
        
        private unit u
        
        private method periodic takes nothing returns boolean
            set this.ticks = this.ticks - 1
        
            call ModifyUnitTimeScale( this.u, this.increment )
            
            debug call BJDebugMsg( R2S( Appearance[ this.u ].timescale ) )
            
            if this.ticks &lt;= 0 then
                call this.destroy()
                
                return true
            endif
            
            return false
        endmethod
        
        implement T32
        
        static method create takes unit Timer, real Time, real timescaleMod, code userFunc 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 TimeScaleChange takes unit Timer, real Time, real timescaleMod returns SmoothTSChange
        return SmoothTSChange.create( Timer, Time, timescaleMod, null )
    endfunction
    
    function TimeScaleChangeEx takes unit Timer, real Time, real timescaleMod, code userFunc returns SmoothTSChange
        return SmoothTSChange.create( Timer, Time, timescaleMod, userFunc )
    endfunction
    
    function GetUnitTimeScale takes unit u returns real
        return Appearance[ u ].timescale
    endfunction

endlibrary


And then "Mod" code:
JASS:
library ModifyAppearance requires AIDS

    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
        
        call SetUnitScale( this.unit, this.scale, 0.,0. )
    endfunction
    
    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
        
        call SetUnitVertexColor( this.unit, this.red, this.green, this.blue, this.alpha )
    endfunction
    
    function ModifyUnitTimeScale takes unit u, real addtimescale returns nothing
        local Appearance this = Appearance[ u ]
        
        set this.timescale = this.timescale + addtimescale
        
        call SetUnitTimeScale( this.unit, this.timescale )
    endfunction
    
endlibrary


Some changes as you can see...
Many names has been changed, any comments ?
The triggers are now called "SmoothUnitModification" and "UnitAppearance"...
Comments there ? :S

If you'd suggest any other names, please post them :D
 

Viikuna

No Marlo no game.
Reaction score
265
Well Cassiels UnitProperties new version 2.0 will probably have vertexcolor, scale and timescale ( At least it has those in ToB testmap ) so when Cassiels releases that new UnitProperties, you could maybe make these functions to use it instead of appereance struct or something.

( Not really neccessary, though. Its only little editing for those who use unit properties. )

Also, you could maybe store scale and timescale in numbers from 0 to 100, instead of 0 to 1, since Jass handles mathematical operations with small numbers kinda badly.

Also, I dont really think that smooth timescale change has any use, but someone just might find some use for it, and having it there doesnt really hurt anyways, since Optimizer removes un-used code, so its ok.

Anyways, this stuff is really useful for many map makers. I myself need this kind of stuff too alla time.

So, in other words: Good job.
 

Jesus4Lyf

Good Idea™
Reaction score
397
>Well Cassiels UnitProperties new version 2.0 will probably have vertexcolor, scale and timescale ( At least it has those in ToB testmap ) so when Cassiels releases that new UnitProperties, you could maybe make these functions to use it instead of appereance struct or something.

Never really heard of UnitProperties (except from Viikuna, I suppose). Sounds like it is standard on WC3C but isn't released here at all. (I wouldn't bother, what you've written is good and probably more efficient - might even work better, don't know how unit properties is done, but I trust well written AIDS structs.)

>Also, you could maybe store scale and timescale in numbers from 0 to 100, instead of 0 to 1, since Jass handles mathematical operations with small numbers kinda badly.

I vote against. JASS is bad at comparing low numbers, but multiplying seems fine. Am I mistaken? Also I think subtracting tiny numbers can botch, I forget. :)

>So, in other words: Good job.
Yeah. I was going to add vertex scale struct and such to stack safety originally, but I never got it working in my head. *Shrugs*

I think this is something nice to submit.
 

Viikuna

No Marlo no game.
Reaction score
265
Well, UnitProperties isnt really standard anywhere. It was first uploaded in wc3c, then removed from there and moved to hive. Ive only seen people using it here in TheHelper, actually o_O.

edit.
Actually and actually, it seems that I am no longer allowed to even mention UnitProperties in wc3c. Dusk removed my posts when I advertised it some weeks ago.
endedit.

UnitProperties stores all property instances to properties array using UnitId as an array index. It is up to you which indexing system you use. AIDS has cool AIDS structs, but Id probably prefer AutoIndex, since it handles unit removal detection better and is closer to my coding style and everything.

But yea, AIDS has GetUnitId, so it is possible to use UnitProperties together with AIDS.

And yea, those low numbers. Well, it will probably work just fine like this too. But using numbers from 0-100 doesnt really have any downsides, so why not, just in case?
 

Jesus4Lyf

Good Idea™
Reaction score
397
>But using numbers from 0-100 doesnt really have any downsides, so why not, just in case?
Efficiency. Multiplying reals is about the same speed as [LJASS]Sin[/LJASS] (pretty damn fast, but why bother if unneeded).

Hum, well that's very interesting. By the way, I don't see why I wouldn't update AIDS to use AutoIndex style removal, even if it is effectively less efficient (AIDS will never recycle a heap of units suddenly, but I see the niceness in detecting removal). Actually, it is my intention one day. I wrote the interface in a way that the implementation can be changed completely with no effect. The main complication is AIDS struct locking (something AutoIndex lacks to the best of my knowledge :)). Oops, off topic.
 

Viikuna

No Marlo no game.
Reaction score
265
Efficienty yea.

Well, its not a big edit to do, if some guyb really wants to use numbers from 1 to 100.

That locking sounds interesting, Im moving to AIDS thread to post more stuff.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
So... What did we get out of this little discussion here then, huh ? :p
Any ideas for other names ? :O
Or new features ? :S
 
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