Snippet Creating an Effect for X seconds

SineCosine

I'm still looking for my Tangent
Reaction score
77
JASS:

//==[WIP] System: Effects v3 ===========================================================
//                             SineCosine's
//   _______  _______  _______  _______   ______ .___________.    _______.
//  |   ____||   ____||   ____||   ____| /      ||           |   /       |
//  |  |__   |  |__   |  |__   |  |__   |  ,----'`---|  |----`  |   (----`
//  |   __|  |   __|  |   __|  |   __|  |  |         |  |        \   \    
//  |  |____ |  |     |  |     |  |____ |  `----.    |  |    .----)   |   
//  |_______||__|     |__|     |_______| \______|    |__|    |_______/    
//                             Credits To:                              
//        ____    ____  ____   
//        \   \  /   / |___ \  kingkingyyk3    BlackRose
//         \   \/   /    __) | Komaqtion       Tyrande_ma3x
//          \      /    |__ <  J4L             SanKakU
//           \    /     ___) | Executor        Vikuna
//            \__/     |____/  -For All The Valuable Input =)
//                          
//======================================================================================


Eh, It's a really long bunch of stuff to type, so..
I hope you aren't too lazy and actually read the documentation :)

Changes in V3
01) No more KT as an optional library
02) TimerUtils is a must
03) Added more effect making functions
04) Added some ways to modify the effects

To be honest, I haven't checked if all of the methods will work =x
But I think they do, except for SetEffectVertexColor.
I need help on that one :thdown:

Also, can anyone think of a better function name for all my functions? XD
I am horrible with naming standards.

The Code..
JASS:

//==[WIP] System: Effects v3 ===========================================================
//                             SineCosine's
//   _______  _______  _______  _______   ______ .___________.    _______.
//  |   ____||   ____||   ____||   ____| /      ||           |   /       |
//  |  |__   |  |__   |  |__   |  |__   |  ,----'`---|  |----`  |   (----`
//  |   __|  |   __|  |   __|  |   __|  |  |         |  |        \   \    
//  |  |____ |  |     |  |     |  |____ |  `----.    |  |    .----)   |   
//  |_______||__|     |__|     |_______| \______|    |__|    |_______/    
//                             Credits To:                              
//        ____    ____  ____   
//        \   \  /   / |___ \  kingkingyyk3    BlackRose
//         \   \/   /    __) | Komaqtion       Tyrande_ma3x
//          \      /    |__ <  J4L             SanKakU
//           \    /     ___) | Executor        Vikuna
//            \__/     |____/  -For All The Valuable Input =)
//                          
//======================================================================================                          
//  What this system does for you:
//  01) It provides an easy way to deal with effects =)
//  02) You can create effects easily and define how long they will be shown
//  03) You can remove effects prematurely
//  04) You can move an effect any way you like
//  05) You can create an effect in the air (Z-Offset)
//  06) You can change the size of an effect
//  07) You can rotate an effect (SetEffectFacing)
//  08) You can change how high an effect is floating
//  09) You can extend the duration of an effect
//  10) You can shorten the duration of an effect
//  11) You can delay the appearance of an effect
//  12) There are 12 different ways to create an effect using EFFECTS
//
//  How do I implement it?
//  01) Go to the trigger editor
//  02) Create a New Trigger
//  03) Rename the Trigger to "Effects"
//  04) Go to: Edit -> Convert To Custom Text
//  05) Copy+Paste this entire library in
//  06) Go to the Object Editor
//  07) Copy+Paste the dummy unit in there, it was used in Vexorians xefx thingy.
//  08) Modify the DummyID constant below to match the raw-code in the Object editor
//  09) Enjoy =)
//
//  Q: How do I use it?
//  A: Well, generally, you'd do it this way..
/*

    function TestEffect takes nothing returns nothing
        local Effect_Timed ET = 0
        //That's the creation of the effect
        set ET = AddTimedSpecialEffect(modelName, x, y, duration)
        
        //This is the modifying of effect while it still exists
        call ET.AddEffectDuration(9001.00)
    endfunction

                                */
                                
//  Q: Okay.. So what Effect Creating functions does your library offer?
//  A: A lot. I mean it.
//     01) AddTimedSpecialEffect takes string modelName, real x, real y, real duration returns Effect_Timed                 
//     02) AddTimedSpecialEffectZ takes string modelName, real x, real y, real z, real duration returns Effect_Timed
//     03) AddTimedSpecialEffectDelayed takes string modelName, real x, real y, real duration, real delay returns Effect_Timed
//     04) AddTimedSpecialEffectDelayedZ takes string modelName, real x, real y, real z, real duration, real delay returns Effect_Timed
//     05) AddTimedSpecialEffectLoc takes string modelName, location where, real duration returns Effect_Timed
//     06) AddTimedSpecialEffectLocZ takes string modelName, location where, real z, real duration returns Effect_Timed
//     07) AddTimedSpecialEffectLocDelayed takes string modelName, location where, real duration, real delay returns Effect_Timed
//     08) AddTimedSpecialEffectLocDelayedZ takes string modelName, location where, real z, real duration, real delay returns Effect_Timed
//     09) AddTimedSpecialEffectTarget takes string modelName, widget targetWidget, string attachPointName, real duration returns Effect_Timed
//     10) AddTimedSpecialEffectTargetDelayed takes string modelName, widget targetWidget, string attachPointName, real duration, real delay returns Effect_Timed
//     11) UnitPosTimedSpecialEffect takes string modelName, unit targetUnit, real duration returns Effect_Timed
//     12) UnitPosTimedSpecialEffectDelayed takes string modelName, unit targetUnit, real duration, real delay returns Effect_Timed
//
//  Q: F*CK YOU! Why so many functions?
//  A: Err, I duno, I just figured that you wouldn't wanna' put 0.0 as the 'delay' 
//     everytime you wanna' create an Effect =)
//
//  Q: Then how will I understand the Jumble of functions? How will I know which to use?
//  A: functions that end with 'Z' allow you to specify a 'Fly-Height' for your effect
//     (Same can be achieved with SetEffectZ and SetEffectPositionZ)
//
//     functions that end with Delayed allow you to specify a delay-time before
//     EFFECTS creates an effect at the defined location.
//
//     AddTimedSpecialEffectTarget and AddTimedSpecialEffectTargetDelayed are for
//     attaching effects to units.
//
//     UnitPosTimedSpecialEffect creates an effect at a unit's X-Y-Z co-ordinates by
//     default but the effect does not follow the unit.
//
//     UnitPosTimedSpecialEffectDelayed creates an effect at a unit's X-Y-Z co-ordinates
//     after a specified amount of delay by default. The effect does not follow the unit.
//
//  Q: What methods do you offer for me to mess around with my effects?
//  A: Quite a bit, and I am looking for ideas for this library/snippet thingy.
//     01) SetEffectDuration takes real newDuration, boolean Reset returns nothing
//     02) AddEffectDuration takes real addDuration returns nothing
//     03) MinusEffectDuration takes real minusDuration returns nothing
//     04) ClearEffect takes nothing returns nothing
//     05) ScaleEffect takes real newSize returns nothing
//     06) SetEffectVertexColor takes integer red, integer green, integer blue, integer alpha returns nothing
//         Warning: do not use SetEffectVertexColor for now, I am trying to fix it =)
//     07) SetEffectFacing takes real newFacing returns nothing
//     08) SetEffectPosition takes real newX, real newY returns nothing
//     09) SetEffectPositionZ takes real newX, real newY, real newZ returns nothing
//     10) SetEffectZ takes real newZ returns nothing
//
//  Q: What does 'boolean reset' do in SetEffectDuration?
//  A: Well, if 'reset' is set to true..
//     Let us say you want Effect X to be displayed for 10seconds
//     8seconds through the effect, you decide to set it to 15seconds
//     So, you call SetEffectDuration. If 'reset' is true, it will cause your effect to
//     last for an extra 15seconds, so, it will have been around for 8 + 15 seconds.
//
//     If 'reset' is set to false, SetEffectDuration will only increase the
//     life-span of the effect by 15 - 8 seconds = 7seconds.
//     It will have lasted exactly 15seconds.
//
//     If an effect has lasted for 30seconds and you use:
//     call ET.SetEffectDuration(6, false)
//     It will immediately remove the effect from the game.
//     Why? Because 30 - 6seconds will result in a negative value.
//
//
//  Extra info:
//  01) This library requires TimerUtils (It is NOT an option, it is a REQUIREMENT =P)
//
//  Known attachment points: 
//  (Copied + Pasted from <a href="http://world-editor-tutorials.thehelper.net/" target="_blank" class="link link--external" rel="nofollow ugc noopener">http://world-editor-tutorials.thehelper.net/</a>)
//  --&gt;Attachment Point Names:
//  01) overhead (floats over the unit&#039;s head, but doesn&#039;t sway with)
//  02) head (sways with the unit&#039;s animation)
//  03) chest (also good for wings)
//  04) origin (usually at the base of a unit&#039;s feet)
//  05) hand
//  06) foot
//  07) weapon (for heroes)
//  08) sprite (for buildings)
//  09) medium (for buildings)
//  10) large (for buildings)
//
//  --&gt;Attachment Point Modifiers:
//  01) left
//  02) right
//  03) mount (for mounted units)
//  04) rear (for quadrupeds)
//  05) first (for buildings)
//  06) second (for buildings)
//  07) third (for buildings)
//  08) fourth (for buildings)
//  09) fifth (for buildings)
//  10) sixth (for buildings)
//  11) rallypoint (for buildings) 

library Effects requires TimerUtils
    
    globals
        private constant integer DummyID = &#039;e000&#039;
    endglobals
    
    struct Effect_Timed
    
        private string ModelName
        private string AttachPointName
        
        private real X
        private real Y
        private real Z
        private real Facing
        private real Duration
        
        private widget TargetWidget
        private effect e
        private unit Dummy
        
        private timer t
        
        private boolean AttachToUnit
        private boolean DelayOver
        
        private real Scale
        private integer Red
        private integer Green
        private integer Blue
        private integer Alpha
        
        private unit TargetUnit
        //This is the &#039;Core&#039; of Effects
        static method End takes nothing returns nothing
            local thistype this = GetTimerData(GetExpiredTimer())
            
            call DestroyEffect(e)
            call ReleaseTimer(t)
            
            if AttachToUnit == false then
                call KillUnit(Dummy)
                call RemoveUnit(Dummy)
            endif
            
            set e = null
            set Dummy = null
            set t = null
            set TargetWidget = null
            set TargetUnit = null
                
            call this.destroy()
        endmethod
        
        static method Delay takes nothing returns nothing
            local thistype this = GetTimerData(GetExpiredTimer())
            
            if AttachToUnit == false and TargetUnit == null then
                set Dummy = CreateUnit(Player(15), DummyID, X, Y, Facing)
                call SetUnitInvulnerable(Dummy, true)
                call UnitAddAbility(Dummy, &#039;Amrf&#039;)
                call SetUnitFlyHeight(Dummy, Z, 0)
                call UnitRemoveAbility(Dummy, &#039;Amrf&#039;)
                call SetUnitPathing(Dummy, false)
                set e = AddSpecialEffectTarget(ModelName, Dummy, &quot;origin&quot;)
                call SetUnitScale(Dummy, Scale, Scale, Scale)
                call SetUnitVertexColor(Dummy, Red, Green, Blue, Alpha)
                call SetUnitFacing(Dummy, Facing)
            elseif TargetUnit != null then
                set X = GetUnitX(TargetUnit)
                set Y = GetUnitY(TargetUnit)
                
                if Z == 0.0 then
                    set Z = GetUnitFlyHeight(TargetUnit)
                endif
                
                set Dummy = CreateUnit(Player(15), DummyID, X, Y, Facing)
                call SetUnitInvulnerable(Dummy, true)
                call UnitAddAbility(Dummy, &#039;Amrf&#039;)
                call SetUnitFlyHeight(Dummy, Z, 0)
                call UnitRemoveAbility(Dummy, &#039;Amrf&#039;)
                call SetUnitPathing(Dummy, false)
                set e = AddSpecialEffectTarget(ModelName, Dummy, &quot;origin&quot;)
                call SetUnitScale(Dummy, Scale, Scale, Scale)
                call SetUnitVertexColor(Dummy, Red, Green, Blue, Alpha)
                call SetUnitFacing(Dummy, Facing)
            else
                set e = AddSpecialEffectTarget(ModelName, TargetWidget, AttachPointName)
            endif
            
            set DelayOver = true
            call TimerStart(t, Duration, false, function thistype.End)
        endmethod
        
        static method Start takes string modelName, string attachPointName, real x, real y, real z, real duration, real delay, widget targetWidget, unit targetUnit returns Effect_Timed
            local thistype this = thistype.allocate()
            
            set ModelName = modelName
            set AttachPointName = attachPointName
            set X = x
            set Y = y
            set Z = z
            set Facing = bj_UNIT_FACING
            set Duration = duration
            set TargetWidget = targetWidget
            set DelayOver = false
            set Scale = 1.0
            set TargetUnit = targetUnit
            
            if TargetWidget != null then
                set AttachToUnit = true
            else    
                set AttachToUnit = false
            endif
            
            set t = NewTimer()
            call SetTimerData(t, this)
            call TimerStart(t, delay, false, function thistype.Delay)
            
            return this
        endmethod
        
        //The following methods are for manipulating the effects created
        method SetEffectDuration takes real newDuration, boolean Reset returns nothing
            if DelayOver == false then
                set Duration = newDuration
            else
                call PauseTimer(t)
                if Reset == true then
                    set Duration = newDuration
                    call TimerStart(t, newDuration, false, function thistype.End)
                else
                    set Duration = newDuration - (TimerGetElapsed(t))
                    
                    if Duration &lt;= 0.0 then
                        call DestroyEffect(e)
                        call ReleaseTimer(t)
            
                        if AttachToUnit == false then
                            call KillUnit(Dummy)
                            call RemoveUnit(Dummy)
                        endif
            
                        set e = null
                        set Dummy = null
                        set t = null
                        set TargetWidget = null
                        set TargetUnit = null
                    else
                        call TimerStart(t, Duration, false, function thistype.End)
                    endif
                            
                endif
            endif
        endmethod
    
        method AddEffectDuration takes real addDuration returns nothing
            if DelayOver == false then
                set Duration = Duration + addDuration
            else
                set Duration = TimerGetRemaining(t) + addDuration
                call PauseTimer(t)
                call TimerStart(t, Duration, false, function thistype.End)
            endif
        endmethod
        
        method MinusEffectDuration takes real minusDuration returns nothing
            if DelayOver == false then
                set Duration = Duration - minusDuration
            else
                set Duration = TimerGetRemaining(t) - minusDuration
                
                if Duration &lt;= 0.0 then
                    call DestroyEffect(e)
                    call ReleaseTimer(t)
            
                    if AttachToUnit == false then
                        call KillUnit(Dummy)
                        call RemoveUnit(Dummy)
                    endif
            
                    set e = null
                    set Dummy = null
                    set t = null
                    set TargetWidget = null
                    set TargetUnit = null
                
                    call this.destroy()
                else
                    call PauseTimer(t)
                    call TimerStart(t, Duration, false, function thistype.End)
                endif
                
            endif
        endmethod
    
        method ClearEffect takes nothing returns nothing
            if DelayOver == true then
                call DestroyEffect(e)
                call ReleaseTimer(t)
            
                if AttachToUnit == false then
                    call KillUnit(Dummy)
                    call RemoveUnit(Dummy)
                endif
            
                set e = null
                set Dummy = null
                set t = null
                set TargetWidget = null
                set TargetUnit = null
                
                call this.destroy()
            else
                call ReleaseTimer(t)
                set t = null
                set TargetWidget = null
            endif
        endmethod
    
        method ScaleEffect takes real newSize returns nothing
            if DelayOver == true then
                set Scale = newSize
                call SetUnitScale(Dummy, newSize, newSize, newSize)
            else
                set Scale = newSize
            endif
        endmethod
        
        method SetEffectVertexColor takes integer red, integer green, integer blue, integer alpha returns nothing
            if DelayOver == true then
                set Red = red
                set Green = green
                set Blue = blue
                set Alpha = alpha
                call SetUnitVertexColor(Dummy, red, green, blue, alpha)
            else
                set Red = red
                set Green = green
                set Blue = blue
                set Alpha = alpha
            endif
        endmethod
        
        method SetEffectFacing takes real newFacing returns nothing
            if DelayOver == true then
                set Facing = newFacing
                call SetUnitFacing(Dummy, newFacing)
            else
                set Facing = newFacing
            endif
        endmethod
        
        method SetEffectPosition takes real newX, real newY returns nothing
            if DelayOver == true then
                call SetUnitPosition(Dummy, newX, newY)
            else
                set X = newX
                set Y = newY
            endif
        endmethod
        
        method SetEffectPositionZ takes real newX, real newY, real newZ returns nothing
            if DelayOver == true then
                set X = newX
                set Y = newY
                set Z = newZ
                call SetUnitPosition(Dummy, newX, newY)
                call UnitAddAbility(Dummy, &#039;Amrf&#039;)
                call SetUnitFlyHeight(Dummy, newZ, 0)
                call UnitRemoveAbility(Dummy, &#039;Amrf&#039;)
            else
                set X = newX
                set Y = newY
                set Z = newZ
            endif
        endmethod
        
        method SetEffectZ takes real newZ returns nothing
            if DelayOver == true then
                set Z = newZ
                call UnitAddAbility(Dummy, &#039;Amrf&#039;)
                call SetUnitFlyHeight(Dummy, newZ, 0)
                call UnitRemoveAbility(Dummy, &#039;Amrf&#039;)
            else
                set Z = newZ
            endif
        endmethod
        
    endstruct

//All the functions that you will need to make the Effects are below.
    function AddTimedSpecialEffect takes string modelName, real x, real y, real duration returns Effect_Timed
        return Effect_Timed.Start(modelName, null, x, y, 0.0, duration, 0.0, null, null)
    endfunction
    
    function AddTimedSpecialEffectZ takes string modelName, real x, real y, real z, real duration returns Effect_Timed
        return Effect_Timed.Start(modelName, null, x, y, z, duration, 0.0, null, null)
    endfunction
    
    function AddTimedSpecialEffectDelayed takes string modelName, real x, real y, real duration, real delay returns Effect_Timed
        return Effect_Timed.Start(modelName, null, x, y, 0.0, duration, delay, null, null)
    endfunction
    
    function AddTimedSpecialEffectDelayedZ takes string modelName, real x, real y, real z, real duration, real delay returns Effect_Timed
        return Effect_Timed.Start(modelName, null, x, y, z, duration, delay, null, null)
    endfunction
    
    function AddTimedSpecialEffectLoc takes string modelName, location where, real duration returns Effect_Timed
        return Effect_Timed.Start(modelName, null, GetLocationX(where), GetLocationY(where), GetLocationZ(where), duration, 0.0, null, null)
    endfunction
    
    function AddTimedSpecialEffectLocZ takes string modelName, location where, real z, real duration returns Effect_Timed
        return Effect_Timed.Start(modelName, null, GetLocationX(where), GetLocationY(where), z, duration, 0.0, null, null)
    endfunction
    
    function AddTimedSpecialEffectLocDelayed takes string modelName, location where, real duration, real delay returns Effect_Timed
        return Effect_Timed.Start(modelName, null, GetLocationX(where), GetLocationY(where), GetLocationZ(where), duration, delay, null, null)
    endfunction
    
    function AddTimedSpecialEffectLocDelayedZ takes string modelName, location where, real z, real duration, real delay returns Effect_Timed
        return Effect_Timed.Start(modelName, null, GetLocationX(where), GetLocationY(where), z, duration, delay, null, null)
    endfunction
    
    function AddTimedSpecialEffectTarget takes string modelName, widget targetWidget, string attachPointName, real duration returns Effect_Timed
        return Effect_Timed.Start(modelName, attachPointName, 0.0, 0.0, 0.0, duration, 0.0, targetWidget, null)
    endfunction
    
    function AddTimedSpecialEffectTargetDelayed takes string modelName, widget targetWidget, string attachPointName, real duration, real delay returns Effect_Timed
        return Effect_Timed.Start(modelName, attachPointName, 0.0, 0.0, 0.0, duration, delay, targetWidget, null)
    endfunction
    
    //Extra functionality
    function UnitPosTimedSpecialEffect takes string modelName, unit targetUnit, real duration returns Effect_Timed
        return Effect_Timed.Start(modelName, null, 0.0, 0.0, 0.0, duration, 0.0, null, targetUnit)
    endfunction
    
    function UnitPosTimedSpecialEffectDelayed takes string modelName, unit targetUnit, real duration, real delay returns Effect_Timed
        return Effect_Timed.Start(modelName, null, 0.0, 0.0, 0.0, duration, delay, null, targetUnit)
    endfunction
    
endlibrary


The demo-map has only 3 GUI examples =x

First-Example:
AddSpecialEffectTargetTimed
When Rifleman attacks
It creates the starfall effect and destroys it 2.0 seconds later.

Second-Example:
AddSpecialEffectLocTimed
When DragonWhelp attacks
It creates a ring of fire effect and destroys it 3.0 seconds later.
Tip: Try running around, you'll see that the 'ring of fire' effect will appear at the sniper every time xD

Third-Example:
AddSpecialEffectTimed
It creates the Phoenix-Egg effect for 5 seconds after a DragonWhelp dies.
The effect will last for another 5seconds, then, the DragonWhelp will revive.

You'll notice that those 3examples were done without waits in the effects =)
(Perfect for GUI-users)

It's a simple snippet, but works =x
Seriously, I had no idea xefx and a hell lot of other libraries like this existed =x
 

Attachments

  • EFFECTS v3.w3x
    43.4 KB · Views: 303

SineCosine

I'm still looking for my Tangent
Reaction score
77
Aw, damn!
Oh, well.

I just hope the guy who requested for that function sees this before it gets graveyarded =x
 

Komaqtion

You can change this now in User CP.
Reaction score
469
You should really learn to use [ljass]thistype[/ljass] and [ljass]this[/ljass], as it'll make your life much easier ;)

And also, I think KeyTimers2 will work better for this, as there might be some lower periods too...

I'd suggest something like this:
JASS:
//====Snippet=Effect-Timed==========================================================================
//
//   _______  _______  _______  _______   ______ .___________.    _______.
//  |   ____||   ____||   ____||   ____| /      ||           |   /       |
//  |  |__   |  |__   |  |__   |  |__   |  ,----&#039;`---|  |----`  |   (----`
//  |   __|  |   __|  |   __|  |   __|  |  |         |  |        \   \    
//  |  |____ |  |     |  |     |  |____ |  `----.    |  |    .----)   |   
//  |_______||__|     |__|     |_______| \______|    |__|    |_______/    
//                                                                      
//  What this snippet does:
//  01) It provides a leak-free method of creating Effects that last for a defined period of time.
//  
//  Q: What inspired the creation of this snippet?
//  A: Someone in the EGUI section was asking if it was possible to add a functionality for EGUI 
//  where an effect was created for X seconds. I don&#039;t know how to modify EGUI, but I can do this =)
//
//  How do I implement it?
//  01) Create a new trigger
//  02) Go to Edit -&gt; Convert to Custom Text
//  03) Copy + Paste this entire thing
//  04) ???
//  05) Win.
//
//  Extra info:
//  01) This library requires TimerUtils
//
//  Functions this snippet provides:
//  01) AddSpecialEffectTimed takes string modelName, real x, real y, real duration returns nothing
//  02) AddSpecialEffectTargetTimed takes string modelName, widget targetWidget, string attachPointName, real duration returns nothing
//  03) AddSpecialEffectLocTimed takes string modelName, location where, real duration returns nothing
//  Note: Do not use AddSpecialEffectLoc unless you really have to..
//        Or you use GUI and this is more convenient xD
//        Remember to clear location leaks!
//
//  Known attachment points: 
//  (Copied + Pasted from <a href="http://world-editor-tutorials.thehelper.net/" target="_blank" class="link link--external" rel="nofollow ugc noopener">http://world-editor-tutorials.thehelper.net/</a>)
//  --&gt;Attachment Point Names:
//  01) overhead (floats over the unit&#039;s head, but doesn&#039;t sway with)
//  02) head (sways with the unit&#039;s animation)
//  03) chest (also good for wings)
//  04) origin (usually at the base of a unit&#039;s feet)
//  05) hand
//  06) foot
//  07) weapon (for heroes)
//  08) sprite (for buildings)
//  09) medium (for buildings)
//  10) large (for buildings)
//
//  --&gt;Attachment Point Modifiers:
//  01) left
//  02) right
//  03) mount (for mounted units)
//  04) rear (for quadrupeds)
//  05) first (for buildings)
//  06) second (for buildings)
//  07) third (for buildings)
//  08) fourth (for buildings)
//  09) fifth (for buildings)
//  10) sixth (for buildings)
//  11) rallypoint (for buildings) 

library Effects requires optional TimerUtils, optional KT
    
    //This is the section for AddSpecialEffectTargetTimed(modelName, targetWidget, attachPointName, duration)
    private struct AddEffectTarget_Timed
    
        effect e
        static if LIBRARY_TimerUtils then
            timer t
        endif
        
        static method End takes nothing returns nothing
            local thistype this
            
            static if LIBRARY_TimerUtils then
                set this = GetTimerData(GetExpiredTimer())
            elseif LIBRARY_KT then
                set this = KT_GetData()
            endif
            
            call this.destroy()
        endmethod
        
        static method Start takes string modelName, widget targetWidget, string attachPointName, real duration returns nothing
            local thistype this = thistype.allocate()
            
            set e = AddSpecialEffectTarget(modelName, targetWidget, attachPointName)
            
            static if LIBRARY_TimerUtils then
                set t = NewTimer()
                
                call SetTimerData(t, this)
                call TimerStart(t, duration, false, function thistype.End)
            elseif LIBRARY_KT then
                KT_Add(thistype.End, this, duration)
            endif
            
        endmethod
        
        method onDestroy takes nothing returns nothing
            call DestroyEffect(e)
            
            static if LIBRARY_TimerUtils then
                call ReleaseTimer(t)
                
                set t = null
            endif
            
            set e = null
        endmethod
    
    endstruct

    function AddSpecialEffectTargetTimed takes string modelName, widget targetWidget, string attachPointName, real duration returns nothing
        call AddEffectTarget_Timed.Start(modelName, targetWidget, attachPointName, duration)
    endfunction
    
    //This is the section for AddSpecialEffectTimed(modelName, x, y, duration)
    
    private struct AddEffect_Timed
    
        effect e
        static if LIBRARY_TimerUtils then
            timer t
        endif
        
        static method End takes nothing returns nothing
            local thistype this
            
            static if LIBRARY_TimerUtils then
                set this = GetTimerData(GetExpiredTimer())
            elseif LIBRARY_KT then
                set this = KT_GetData()
            endif
            
            call this.destroy()
        endmethod
        
        static method Start takes string modelName, real x, real y, real duration returns nothing
            local thistype this = thistype.allocate()
            
            set e = AddSpecialEffect(modelName, x, y)
            
            static if LIBRARY_TimerUtils then
                set t = NewTimer()
                
                call SetTimerData(t, this)
                call TimerStart(t, duration, false, function thistype.End)
            elseif LIBRARY_KT then
                KT_Add(thistype.End, this, duration)
            endif
            
        endmethod
        
        method onDestroy takes nothing returns nothing
            call DestroyEffect(e)
            
            static if LIBRARY_TimerUtils then
                call ReleaseTimer(t)
                
                set t = null
            endif
            
            set e = null
        endmethod
    
    endstruct

    function AddSpecialEffectTimed takes string modelName, real x, real y, real duration returns nothing
        call AddEffect_Timed.Start(modelName, x, y, duration)
    endfunction
    
    //This is the section for AddSpecialEffectLoc(modelName, where, duration)
    function AddSpecialEffectLocTimed takes string modelName, location where, real duration returns nothing
        local real x = GetLocationX(where)
        local real y = GetLocationY(where)
        
        call AddEffect_Timed.Start(modelName, x, y, duration)
    endfunction
endlibrary


But I think this is quite good, and it covers the areas it's needed for well :D

I made a much smaller snippet than this a long time ago, and it got graveyarded, but I think this is better :D
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
OUH!!
So that's how people are making certain systems optional ._.

I have learned something new xD

What if the mapper has BOTH timer systems? o.0
Wouldn't this break something?

JASS:
static if LIBRARY_TimerUtils then
    call ReleaseTimer(t)         
    set t = null
endif


Imma' go edit it now, even if it does get graveyarded =x

[EDIT]
If both libraries are optional..
What if the user doesn't get both? o.0
Will I have to resort to Creating and destroying timers?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
And also, I think KeyTimers2 will work better for this, as there might be some lower periods too...
Actually KT is not so useful in this case. :) Jesus4Lyf benchmarked himself, KT is slower than TimerUtils in long period.
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
He said KT2 is better for shorter periods xD
Hmm..

Around how 'short' is KT2 better than TimerUtils?
I could make a check for both the library and the 'duration' ;D

[EDIT]
I already made it to select TimerUtils in case both are present..
Now..

Should I make a constant for the user to decide on which system they prefer? o.0
Lol, this is my learning experience.
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
O_O
But I use better names xD
(I'm kidding)

Ouh, he has a delay function ._.
But he requires you to stop your effects with: [lJASS]call StopTimedEffect(integer)[/lJASS]
Mine just lets you be lazy and define when you want it to be gone ._.
Unless you're telling me I should add in both functions =x

One thing, though, I still don't know exactly when KT is better than TimerUtils..
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Around how 'short' is KT2 better than TimerUtils?
< THRESHOLD(Get it in KT2 thread)
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Still, that system isn't on our site, so we could also have one here ;)
All don't have to use the same, and this one doesn't work the same way still...

And yeah, you should make a comparison like:
JASS:
static if LIBRARY_KT then
    if duration &lt;= 0.5 then
    endif
endif


the 0.5 is just an example ;)
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
There are, like, 2 thresholds ._.

0.3 and 0.03125

I'm guessing it would be 0.03125, right? o.0
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
private constant real PERIODTHRESHOLD=0.3 // MUST be below 10.24 seconds.
This.
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
Done editing, I just need to know if it is this..

Use KT if duration is smaller than or equals to PERIODTHRESHOLD

or this..

Use KT if duration is smaller than PErIODTHRESHOLD
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
I already have everything down.

Problem is, when I disable TimerUtils or KT..
(To simulate a mapper not having TimerUtils or KT)
(Was making sure everything would run if I disabled either KT or TimerUtils)

My whole library goes haywire with the undeclared functions..
Even though it will never call those functions if the library isn't there o.0

JASS:
//====Snippet=Effect-Timed==========================================================================
//  Credits To:
//  kingkingyyk3
//  Komaqtion
//  -For all their valuable input.
//   _______  _______  _______  _______   ______ .___________.    _______.
//  |   ____||   ____||   ____||   ____| /      ||           |   /       |
//  |  |__   |  |__   |  |__   |  |__   |  ,----&#039;`---|  |----`  |   (----`
//  |   __|  |   __|  |   __|  |   __|  |  |         |  |        \   \    
//  |  |____ |  |     |  |     |  |____ |  `----.    |  |    .----)   |   
//  |_______||__|     |__|     |_______| \______|    |__|    |_______/    
//                          ____    ____   ___   
//                          \   \  /   /  |__ \  
//                           \   \/   /     ) | 
//                            \      /     / /  
//                             \    /     / /_  
//                              \__/     |____|                 
//                                                                      
//  What this snippet does:
//  01) It provides a leak-free method of creating Effects that last for a defined period of time.
//  
//  Q: What inspired the creation of this snippet?
//  A: Someone in the EGUI section was asking if it was possible to add a functionality for EGUI 
//  where an effect was created for X seconds. I don&#039;t know how to modify EGUI, but I can do this =)
//
//  How do I implement it?
//  01) Create a new trigger
//  02) Go to Edit -&gt; Convert to Custom Text
//  03) Copy + Paste this entire thing
//  04) ???
//  05) Win.
//
//  Extra info:
//  01) This library requires TimerUtils as an optional library
//  02) This library requires KeyTimers2 as an optional library
//  03) This library will select the the optimal Timer System for each case in the event that both TimerUtils and KT are used by the mapper =)
//
//  Functions this snippet provides:
//  01) AddSpecialEffectTimed takes string modelName, real x, real y, real duration returns nothing
//  02) AddSpecialEffectTargetTimed takes string modelName, widget targetWidget, string attachPointName, real duration returns nothing
//  03) AddSpecialEffectLocTimed takes string modelName, location where, real duration returns nothing
//  Note: Do not use AddSpecialEffectLoc unless you really have to..
//        Or you use GUI and this is more convenient xD
//        Remember to clear location leaks!
//
//  Known attachment points: 
//  (Copied + Pasted from <a href="http://world-editor-tutorials.thehelper.net/" target="_blank" class="link link--external" rel="nofollow ugc noopener">http://world-editor-tutorials.thehelper.net/</a>)
//  --&gt;Attachment Point Names:
//  01) overhead (floats over the unit&#039;s head, but doesn&#039;t sway with)
//  02) head (sways with the unit&#039;s animation)
//  03) chest (also good for wings)
//  04) origin (usually at the base of a unit&#039;s feet)
//  05) hand
//  06) foot
//  07) weapon (for heroes)
//  08) sprite (for buildings)
//  09) medium (for buildings)
//  10) large (for buildings)
//
//  --&gt;Attachment Point Modifiers:
//  01) left
//  02) right
//  03) mount (for mounted units)
//  04) rear (for quadrupeds)
//  05) first (for buildings)
//  06) second (for buildings)
//  07) third (for buildings)
//  08) fourth (for buildings)
//  09) fifth (for buildings)
//  10) sixth (for buildings)
//  11) rallypoint (for buildings) 

library Effects requires optional TimerUtils, optional KT
    
    globals
        //Err, don&#039;t touch this unless you know what you&#039;re doing, lol
        private constant real KT_THRESHOLD = 0.3
    endglobals
    
    //This is the section for AddSpecialEffectTargetTimed(modelName, targetWidget, attachPointName, duration)
    private struct AddEffectTarget_Timed
        effect e
        timer t
        
        static method EndTU takes nothing returns nothing
            local thistype this

            static if LIBRARY_TimerUtils then
                set this = GetTimerData(GetExpiredTimer())
                call ReleaseTimer(t)
                set t = null
            endif
            call this.destroy()
        endmethod
        
        static method EndKT takes nothing returns boolean
            local thistype this
            
            static if LIBRARY_KT then
                set this = KT_GetData()
            endif
            call this.destroy()
            return true
        endmethod
        
        static method Start takes string modelName, widget targetWidget, string attachPointName, real duration returns nothing
            local thistype this = thistype.allocate()
            
            set e = AddSpecialEffectTarget(modelName, targetWidget, attachPointName)
            
            if duration &gt;= KT_THRESHOLD then
                static if LIBRARY_TimerUtils then
                    set t = NewTimer()
                    call SetTimerData(t, this)
                    call TimerStart(t, duration, false, function thistype.EndTU)
                elseif LIBRARY_KT then
                    call KT_Add(function thistype.EndKT, this, duration)
                endif
            else
                static if LIBRARY_KT then
                    call KT_Add(function thistype.EndKT, this, duration)
                elseif LIBRARY_TimerUtils then
                    set t = NewTimer()
                    call SetTimerData(t, this)
                    call TimerStart(t, duration, false, function thistype.EndTU)
                endif
            endif

        endmethod
        
        method onDestroy takes nothing returns nothing
            call DestroyEffect(e)
            set e = null
        endmethod
    
    endstruct

    function AddSpecialEffectTargetTimed takes string modelName, widget targetWidget, string attachPointName, real duration returns nothing
        call AddEffectTarget_Timed.Start(modelName, targetWidget, attachPointName, duration)
    endfunction
    
    //This is the section for AddSpecialEffectTimed(modelName, x, y, duration)
    private struct AddEffect_Timed
        effect e
        timer t
        
        static method EndTU takes nothing returns nothing
            local thistype this
            
            static if LIBRARY_TimerUtils then
                set this = GetTimerData(GetExpiredTimer())
                call ReleaseTimer(t)
                set t = null
            endif
            
            call this.destroy()
        endmethod
        
        static method EndKT takes nothing returns boolean
            local thistype this
            
            static if LIBRARY_KT then
                set this = KT_GetData()
            endif
            call this.destroy()
            return true
        endmethod
        
        static method Start takes string modelName, real x, real y, real duration returns nothing
            local thistype this = thistype.allocate()
            
            set e = AddSpecialEffect(modelName, x, y)
            
            if duration &gt;= KT_THRESHOLD then
                static if LIBRARY_TimerUtils then
                    set t = NewTimer()
                    call SetTimerData(t, this)
                    call TimerStart(t, duration, false, function thistype.EndTU)
                elseif LIBRARY_KT then
                    call KT_Add(function thistype.EndKT, this, duration)
                endif
            else
                static if LIBRARY_KT then
                    call KT_Add(function thistype.EndKT, this, duration)
                elseif LIBRARY_TimerUtils then
                    set t = NewTimer()
                    call SetTimerData(t, this)
                    call TimerStart(t, duration, false, function thistype.EndTU)
                endif
            endif
        endmethod
        
        method onDestroy takes nothing returns nothing
            call DestroyEffect(e)
            set e = null
        endmethod
    
    endstruct

    function AddSpecialEffectTimed takes string modelName, real x, real y, real duration returns nothing
        call AddEffect_Timed.Start(modelName, x, y, duration)
    endfunction
    
    //This is the section for AddSpecialEffectLoc(modelName, where, duration)
    function AddSpecialEffectLocTimed takes string modelName, location where, real duration returns nothing
        local real x = GetLocationX(where)
        local real y = GetLocationY(where)
        
        call AddEffect_Timed.Start(modelName, x, y, duration)
    endfunction
endlibrary



[EDIT]
WAIT
Fixed it =)
I made static ifs in the 'End' methods as well xD
But will those extra ifs slow things down? o.0

Also,
If the mapper does not have either TimerUtils or KT, should I make an extra part where it Creates a timer and Destroys?

[EDIT=2]
Edited the first Post and uploaded Version 2!

Thanks kingking, Komaq!
I now know how libraries are made optional.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
If the mapper does not have either TimerUtils or KT, should I make an extra part where it Creates a timer and Destroys?
Gave them a warning message : "TimerUtils and KT are not detected in your map." :)
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
Thanks for the idea xD
I even purposefully put in a TSA call if they didn't have either =x

You can go test the map now if you are free =x
It'll have really funny results if you don't have either TimerUtils or KT xD

(Or, alternatively, look through the updated code on the first post)
 

BlackRose

Forum User
Reaction score
239
Thanks for the idea xD
I even purposefully put in a TSA call if they didn't have either =x

You can go test the map now if you are free =x
It'll have really funny results if you don't have either TimerUtils or KT xD

(Or, alternatively, look through the updated code on the first post)

=.=
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
=)
And I didn't use [lJASS]call this.destroy()[/lJASS]

That should annoy people enough to have to get TimerUtils, KT or both!
(If they use this snippet)
 
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