HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Best way to Create Effects?

02-17-2009, 03:15 PM#1
youkaiz
I trying to make a function to create special effects on my map.
(Change Angle, Size and Life Time of effect)
I made this function but i don't know if have leaks here, can someone check my code? And, what is the best way to make this code? Is better if i use structs here?

Collapse JASS:
private function DSEffect takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t,"unit")
    local effect e = GetHandleEffect(t,"effect")
    call DestroyEffect(e)
    call RemoveUnit(u)
    call FlushHandleLocals(t)
    call DestroyTimer(t)
    set t = null
    set u = null
    set e = null
endfunction   

function SEffect takes string model,real size, real x, real y, real angle, real duration returns nothing
    local timer t = CreateTimer()
    local unit u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),Dummy,x,y,angle)//Dummy is Dummy unit ID on map.
    local effect e
    call SetUnitScale(u,size,size,size)
    set e = AddSpecialEffectTarget(model,u,"origin")
    call SetHandleHandle(t,"effect",e)
    call SetHandleHandle(t,"unit",u)
    call TimerStart(t,duration,false,function DSEffect)
    set t = null
    set e = null
    set u = null
endfunction
02-17-2009, 03:39 PM#2
akolyt0r
You should really use TimerUtils (vJass) and structs ...those local handle vars are highly deprecated 0o
02-17-2009, 11:32 PM#3
Zerzax
I personally prefer permanent "dummy" abilities to attach to invisible units - they don't discriminate based on animation ( i.e. don't remain until the animation loop finishes, which is a pain in the ass), don't need to be cleaned, can easily be added and removed, and best of all make it easy to reuse the units. I would base the ability off of a passive item ability, such as Item Armor Bonus. After a TimerUtils timer finishes you can then remove the ability from the unit and then add that unit to a stack to be used again.
02-19-2009, 03:48 AM#4
youkaiz
i remake this.
Collapse JASS:
private struct SeData
    unit u
    effect e
endstruct


private function DSEffect takes nothing returns nothing
    local SeData s = GetTimerData( GetExpiredTimer() )
    call DestroyEffect(s.e)
    call RemoveUnit(s.u)
    call ReleaseTimer(GetExpiredTimer())
    call s.destroy()
endfunction   

function SEffect takes string model,real size, real x, real y, real angle, real duration returns nothing
    local timer t = NewTimer()
    local SeData s = SeData.create()
    set s.u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),MCSDummy,x,y,angle)
    call SetUnitScale(s.u,size,size,size)
    set s.e = AddSpecialEffectTarget(model,s.u,"origin")
    call SetTimerData(t, s)
    call TimerStart(t,duration,false,function DSEffect)
endfunction 
this way is better?
02-19-2009, 11:39 AM#5
moyack
Use my timed effects script and make your life happier.

Collapse JASS:
library YourCode requires TimedEffects  

function SEffect takes string model,real size, real x, real y, real angle, real duration returns nothing
    local unit u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),MCSDummy,x,y,angle)
    call SetUnitScale(u,size,size,size)
    call UnitApplyTimedLife(u, 0, duration * 1.1) // just to keep the dummy unit alive for a little longer
    call StartTimedEffect(AddSpecialEffectTarget(model,u,"origin"), duration)
    set u = null
endfunction 

endlibrary
02-19-2009, 03:45 PM#6
xombie
moyack, it wouldn't be too difficult to incorporate a small linked list idea for your timed effects, so that they all operate efficiently on one single timer. You would only need a single list that sorted itself based on the expiration times of the effects, it would be nice.

**edit

Bah, just figured out that you use TimerUtils. Grr.