• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

DelFX - Delayed Effects 1.4.2

Description:
This little library allows the user to schedule effects and destroy them after some time with only one line. There are some more things you can do to delayed effects and I suggest you look at the code to understand this library.

I developed this library for my Phoenix Form spell, which is why the testmap matches the Phoenix Form one. In particular I used DelFX to time the flamestrike effects and simulate the burning effect of immolation.

This library uses Vexorian's TimerUtils library and vJass syntax.

- "-reset": spawns some footmen
- "-level <level>": Set the heros level to the level you specified. Note that you cannot decrease it that way.
- "-handleid": creates a location, displays its handlid-0x100001, and then destroys it.
- "-credits": displays credits
- "-commands": displays this list
- "-clear": removes all messages ingame


01/08/2009 - Version 1.0.0
- initial release

01/21/2009 - Version 1.0.1
- shortened code

01/21/2009 - Version 1.1.0
- Now uses one timer per instance

02/11/2009 - Version 1.1.1
- fixing of a few really small glitches
- better error reporting (when in debug mode)

02/22/2009 - Version 1.2.0
- Added OnSpawn and OnDestroy callbacks, so you can run code when a DELFX struct spawns an effect or is destroyed
- Enabled attaching to DELFX structs

03/14/2009 - Version 1.3.0
- added support for destroying effects (DestroyEffectTimed)
- added support for spawning Delayed Effects with a Z coordinate (CreateDelayedEffectZ)
- added support for changing the spawning location of a Delayed Effect (DELFX.SetSpawnPosition)

04/13/2009 - Version 1.4.0
- removed access to the DELFX struct; the struct is now private to the DelFX library (this breaks backwards compatibility)
- removed unnecessary code, now that the DELFX struct is private.

04/13/2009 - Version 1.4.1
- further reduced code amount, removing features not in the scope of this system
- small optimization behind the scenes

08/07/2009 - Version 1.4.2
- Compatibility with 1.24


JASS:
//  API:
//
//    >>CreateDelayedEffect(whichEffect, X, Y, Delay, Timeout)
//          - whichEffect is of type string and contains the path of the 
//            effect-to-be-spawned
//          - X and Y indicate where the effect should be spawned
//          - Delay is of type real and indicates how long to wait before spawning the
//            effect
//          - Timeout is of type real and indicates how long to wait before destroying
//            the effect after it has been created
//
//    >>CreateDelayedEffectZ(whichEffect, X, Y, Z, Delay, Timeout)
//          - whichEffect: see above
//          - X, Y and Z indicate where to spawn the effect
//          - Delay: see above
//          - Timeout: see above
//
//    >>CreateDelayedEffectTarget(whichEffect, Target, AttachmentPoint, Delay, Timeout)
//          - whichEffect: see above
//          - Target is of type widget and indicates on which widget the effect should
//            be spawned
//          - AttachmentPoint is of type string and holds the attachment point where
//            the effect should be spawned on target widget
//          - Delay: see above
//          - Timeout: see above
//
//  CREDITS:
//      - Vexorian (JassHelper; TimerUtils)
//      - Anitarf (Suggestions)
//      - KaTTaNa (AddSpecialEffectZ function @ wc3jass.com)
//      - PitzerMike (JassNewGenPack)
//      - Pipedream (Grimoire)
//      - SFilip (TESH)

library DelFX uses TimerUtils
    
    private struct DELFX
        private effect fx
        
        private string path
        private boolean target
        private widget tar
        private string attpt
        private real x
        private real y
        private real z
        
        private timer t
        private real timeout
        
        private method onDestroy takes nothing returns nothing
            if .fx!=null then
                call DestroyEffect(.fx)
                set .fx=null
            endif
            set .tar=null
            call ReleaseTimer(.t)
        endmethod
        
        private static method Release takes nothing returns nothing
            call DELFX.destroy(GetTimerData(GetExpiredTimer()))
        endmethod
        
        private static method Callback takes nothing returns nothing
        local DELFX s=GetTimerData(GetExpiredTimer())
        local destructable d
            debug if s.fx==null then
                if s.target then
                    set s.fx=AddSpecialEffectTarget(s.path, s.tar, s.attpt)
                elseif s.z==0 then
                    set s.fx=AddSpecialEffect(s.path, s.x, s.y)
                else
                    set d=CreateDestructableZ('OTip', s.x, s.y, s.z, 0,1.,0)
                    set s.fx=AddSpecialEffect(s.path, s.x, s.y)
                    call RemoveDestructable(d)
                    set d=null
                endif
                call TimerStart(s.t, s.timeout, false, function DELFX.Release)
            debug else
            debug     call BJDebugMsg("DELFX["+I2S(s)+"].Callback: Effect already spawned!")
            debug endif
        endmethod
        
        static method Create takes string path, boolean target, widget tar, string attpt, real x, real y, real z, real delay, real timeout returns DELFX
        local DELFX s=DELFX.allocate()
            set s.t=NewTimer()
            call SetTimerData(s.t, s)
            set s.path=path
            set s.target=target
            set s.tar=tar
            set s.attpt=attpt
            set s.x=x
            set s.y=y
            set s.z=z
            set s.timeout=timeout
            call TimerStart(s.t, delay, false, function DELFX.Callback)
            return s
        endmethod
    endstruct
    
    // The functions below have been explained above.
    
    function CreateDelayedEffect takes string path, real x, real y, real delay, real timeout returns nothing
        call DELFX.Create(path, false, null, "", x, y, 0, delay, timeout)
    endfunction
    
    function CreateDelayedEffectZ takes string path, real x, real y, real z, real delay, real timeout returns nothing
        call DELFX.Create(path, false, null, "", x, y, z, delay, timeout)
    endfunction
    
    function CreateDelayedEffectTarget takes string path, widget target, string attachmentpoint, real delay, real timeout returns nothing
        call DELFX.Create(path, true, target, attachmentpoint, 0, 0, 0, delay, timeout)
    endfunction
    
endlibrary

Keywords:
Delayed, Timed, Effects, Effect, AddSpecialEffectZ
Contents

DelFX 1.4.2 (Map)

Reviews
20:10, 25th Feb 2009 Hanky: Advice: 5 points are the highest rating and 1 point is the lowest rating. Documentation: 2 Visual Effects: - Triggering: 5 Idea: - Total: The code seems to be fine but you could maybe improve abit the...

Moderator

M

Moderator

20:10, 25th Feb 2009
Hanky:
Evaluation

Rating Points
Advice: 5 points are the highest rating and 1 point is the lowest rating.

Documentation: 2
Visual Effects: -
Triggering: 5
Idea: -

Total:
thumbsup.gif
thumbsup.gif
thumbsup.gif
thumbsup.gif
thumbsdn.gif

Rating Comment

The code seems to be fine but you could maybe improve abit the documentation. Also I don't know how the performance differences are between your system and the normal way to destroy special effects delayed. Maybe you could make some performance test's and post them. But well the system work and the code is ok so I see no reason why I shouldn't approve it. The system could be maybe useful for some guys and I just can recommend to use it.

Suggestion:
- add a better manuel
- clear up the code
Advice: If you didn't understood my rating or if you maybe have questions because you don't know how to fix bugs or leaks etc. You can always send a private message to me. I will answer as soon I got time.
 
Level 14
Joined
Nov 18, 2007
Messages
816
to all who think this is too similar to already existing systems:

This allows you to delay the creation of effects, which is a unique feature. However, if you can find a resource on THW, doing the same thing (in a better way) that has been approved before this, i'd like to have a link.
 
Top