• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Spell ending a lot of times

Status
Not open for further replies.
Level 5
Joined
Sep 16, 2008
Messages
47
Hi, i got a problem. Here is vjass spells model:

JASS:
scope Spell

    native UnitAlive takes unit u returns boolean

    globals
    
        private constant integer SPELL_ID           = 'A000'
        private constant real TIMEOUT               = 0.031250
    
    endglobals
    
    private struct Spell
    
        private thistype next
        private thistype prev
    
        private static integer count = 0
        private static timer TIMER = CreateTimer()
        
        static Table dummy
    
        private method destroy takes nothing returns nothing
            
            call this.deallocate()
            
            set this.next.prev = this.prev
            set this.prev.next = this.next
            set count = count - 1
            
            call BJDebugMsg("end2")

            if count == 0 then
                call PauseTimer(TIMER)
            endif
            
        endmethod
    
        private static method SpellLoop takes nothing returns nothing
        
            local thistype this = thistype(0).next
            
            local integer index = 0
            local unit u
            
            loop
            
                exitwhen this == 0
           
                if 0 == 0 then
                
                    call this.destroy()
                    
                else
                
                set this = this.next
                
                endif
            
            endloop
            
            set u = null
        
        endmethod
    
        private static method SpellCast takes nothing returns nothing
        
            local thistype this
            
            set this = thistype.allocate()
            set this.next = 0
            set this.prev = thistype(0).prev
            set thistype(0).prev.next = this
            set thistype(0).prev = this
            set count = count + 1
               
            if count == 1 then
                call TimerStart(TIMER, TIMEOUT, true, function thistype.SpellLoop)
            endif
        
        endmethod    
        
        static if not LIBRARY_SpellEffectEvent then
            private static method cond takes nothing returns boolean
                return (GetSpellAbilityId() == SPELL_ID and thistype.SpellCast() )
            endmethod
        endif
        
        private static method onInit takes nothing returns nothing
        
            static if LIBRARY_SpellEffectEvent then
                call RegisterSpellEffectEvent(SPELL_ID, function thistype.SpellCast)
            else
                local trigger t = CreateTrigger()
                call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
                call TriggerAddCondition(t, Condition(function thistype.cond))
                set t = null
            endif
            
        endmethod
    
    endstruct

endscope

The problem is when i am checking how it works with message it is displayed so many times so if i put effect, create unit etc it will happen X times.
 
Status
Not open for further replies.
Top