• 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.

[General] Does "ForGroup" leak?

Status
Not open for further replies.
Level 11
Joined
Oct 11, 2012
Messages
711

Thanks a lot! :) +Rep

May I ask another question so that I do not have to open a new post (I have already been posting too many questions. LOL) :
how to make an effect last for a period of time in a loop?
Such as:

JASS:
loop
        set u = FirstOfGroup(g)        
        exitwhen u == null
        call GroupRemoveUnit(g,u)
        call UnitDamageTarget(gg_unit_H02Y_0001,u,33.,true,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_DEMOLITION,null)
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Other\\Monsoon\\MonsoonBoltTarget.mdl",u,"origin"))
endloop

I would like to make the above effect last for 8 seconds, how should I do that?
 
Last edited:
Level 22
Joined
Sep 24, 2005
Messages
4,821
If you wanted to do it yourself, then you need to create the effect, save it (hashtables, array or anything else you use) and then use some sort of timer or jass timers and then destroy it. If you're good using systems on the site, you can use this.
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
It uses Table by Vexorian but you can use a normal hashtable too :
JASS:
library SpecialEffect requires Table
/* This allow you to create timed effects */

    globals
        private HandleTable tab
    endglobals
    
    private struct SpecialEffect
        effect e
        timer t
        
        //Chobibo wanted conventionnal stuff
        static method create takes nothing returns thistype
            local thistype this = thistype.allocate()
            set this.t = CreateTimer()
            return this
        endmethod

        private static method onInit takes nothing returns nothing
            set tab = HandleTable.create()
        endmethod
    endstruct
    
    private function End takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local SpecialEffect this = tab[t]
        call DestroyEffect(this.e)
        call tab.flush(t)
        call this.destroy()
        call DestroyTimer(t)
        set t = null
    endfunction
    
    function AddSpecialEffectTimed takes string modelName, real x, real y, real time returns nothing
        local SpecialEffect this = SpecialEffect.create()
        set this.e = AddSpecialEffect(modelName, x, y)
        set tab[this.t] = this
        call TimerStart(this.t, time, false, function End)
    endfunction
    
    function AddSpecialEffectTargetTimed takes string modelName, widget target, string attachPointName, real time returns nothing
        local SpecialEffect this = SpecialEffect.create()
        set this.e = AddSpecialEffectTarget(modelName, target, attachPointName)
        set tab[this.t] = this
        call TimerStart(this.t, time, false, function End)
    endfunction
endlibrary
 
Level 11
Joined
Oct 11, 2012
Messages
711
If you wanted to do it yourself, then you need to create the effect, save it (hashtables, array or anything else you use) and then use some sort of timer or jass timers and then destroy it. If you're good using systems on the site, you can use this.
Alrighty, thanks! :)

It uses Table by Vexorian but you can use a normal hashtable too :
JASS:
library SpecialEffect requires Table
/* This allow you to create timed effects */

    globals
        private HandleTable tab
    endglobals
    
    private struct SpecialEffect
        effect e
        timer t = CreateTimer()
        
        private static method onInit takes nothing returns nothing
            set tab = HandleTable.create()
        endmethod
    endstruct
    
    private function End takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local SpecialEffect this = tab[t]
        call DestroyEffect(this.e)
        call tab.flush(t)
        call this.destroy()
        call DestroyTimer(t)
        set t = null
    endfunction
    
    function AddSpecialEffectTimed takes string modelName, real x, real y, real time returns nothing
        local SpecialEffect this = SpecialEffect.create()
        set this.e = AddSpecialEffect(modelName, x, y)
        set tab[this.t] = this
        call TimerStart(this.t, time, false, function End)
    endfunction
    
    function AddSpecialEffectTargetTimed takes string modelName, widget target, string attachPointName, real time returns nothing
        local SpecialEffect this = SpecialEffect.create()
        set this.e = AddSpecialEffectTarget(modelName, target, attachPointName)
        set tab[this.t] = this
        call TimerStart(this.t, time, false, function End)
    endfunction
endlibrary

Thank you, Malhorne!! Digesting your code now. LOL. I cannot add Rep to you now, will do that when I can.
BTW: is this MUI? I don't know much about vJass.
 
Status
Not open for further replies.
Top