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

[JASS] This Trigger creates heavy delay

Status
Not open for further replies.
Level 14
Joined
Jul 1, 2008
Messages
1,314
Hello guys,

this trigger is working fine, but it creates giant leaks during its execution.

After 2 executions, the game cant be played anymore!

I have no idea why, so maybe you guys can help me out?

JASS:
function Trig_Morgenstern_Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    if GetUnitAbilityLevel(u,'A009') > 0 then
       if GetUnitTypeId(u) == 'U000' and IsUnitAlly(u,GetOwningPlayer(GetAttacker())) == false and udg_Capricorn_Spin == false then
          set u = null
          return true
       endif
    endif
    set u = null
    return false
endfunction

function CM_GroupEnumTargets takes nothing returns boolean

    local unit u = GetFilterUnit()
    local player p = GetOwningPlayer(udg_HERO_Capricorn)
    
    if IsUnitAlly(u,p) != true and IsUnitDead(u) != true and IsUnitType(u, UNIT_TYPE_STRUCTURE) != true then
       set u = null
       set p = null
       return true
    endif
    set u = null
    set p = null
    return false
    
endfunction

function Trig_Morgenstern_Actions takes nothing returns nothing

    local integer i = 0
    local integer count = 0
    local group g
    local unit u
    local real cx
    local real cy
    local effect array e
    
    // LVL DATA
    local integer SPELL_LVL = GetUnitAbilityLevel(udg_HERO_Capricorn,'A009')
    local integer DMG = 30 + SPELL_LVL * 10
    
    // Percentage chance
    if GetRandomInt(1,10) <= SPELL_LVL + 1 then
       
       set udg_Capricorn_Spin = true
       // Enum targets
       set cx = GetUnitX(udg_HERO_Capricorn)
       set cy = GetUnitY(udg_HERO_Capricorn)
       set g = CreateGroup()
       call GroupEnumUnitsInRange(g,cx,cy,250.00,Condition(function CM_GroupEnumTargets))
    
       loop
           set u = FirstOfGroup(g)
           exitwhen u == null
       
           set e[count] = AddSpecialEffectTarget("Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl",u,"chest")
           set count = count + 1
           // dmg unit
           call UnitDamageTarget( udg_HERO_Capricorn, u, DMG,true,false, ATTACK_TYPE_MELEE, DAMAGE_TYPE_FORCE,WEAPON_TYPE_WHOKNOWS )

       endloop 
    
       // Capricorn Anim
       set e[count] = AddSpecialEffectTarget("war3mapImported\\Flail.mdx",udg_HERO_Capricorn,"overhead")
    
       call TriggerSleepAction(0.60 - I2R(SPELL_LVL / 10))
       
       loop
           exitwhen i > count
           call DestroyEffect(e[i])
           set e[i] = null
           set i = i + 1
       endloop
       
       set udg_Capricorn_Spin = false
       call DestroyGroup(g)
    endif
    
    set g = null
    set u = null
 
endfunction

//===========================================================================
function InitTrig_Morgenstern takes nothing returns nothing
    set gg_trg_Morgenstern = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Morgenstern, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Morgenstern, Condition( function Trig_Morgenstern_Conditions ) )
    call TriggerAddAction( gg_trg_Morgenstern, function Trig_Morgenstern_Actions )
endfunction
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
You have to remove the unit from the group in the loop ;)
JASS:
function Trig_Morgenstern_Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    if GetUnitAbilityLevel(u,'A009') > 0 then
       if GetUnitTypeId(u) == 'U000' and IsUnitAlly(u,GetOwningPlayer(GetAttacker())) == false and udg_Capricorn_Spin == false then
          set u = null
          return true
       endif
    endif
    set u = null
    return false
endfunction

function CM_GroupEnumTargets takes nothing returns boolean

    local unit u = GetFilterUnit()
    local player p = GetOwningPlayer(udg_HERO_Capricorn)

    if IsUnitAlly(u,p) != true and IsUnitDead(u) != true and IsUnitType(u, UNIT_TYPE_STRUCTURE) != true then
       set u = null
       set p = null
       return true
    endif
    set u = null
    set p = null
    return false

endfunction

function Trig_Morgenstern_Actions takes nothing returns nothing

    local integer i = 0
    local integer count = 0
    local group g
    local unit u
    local real cx
    local real cy
    local effect array e

    // LVL DATA
    local integer SPELL_LVL = GetUnitAbilityLevel(udg_HERO_Capricorn,'A009')
    local integer DMG = 30 + SPELL_LVL * 10

    // Percentage chance
    if GetRandomInt(1,10) <= SPELL_LVL + 1 then

       set udg_Capricorn_Spin = true
       // Enum targets
       set cx = GetUnitX(udg_HERO_Capricorn)
       set cy = GetUnitY(udg_HERO_Capricorn)
       set g = CreateGroup()

       call GroupEnumUnitsInRange(g,cx,cy,250.00,Condition(function CM_GroupEnumTargets))

       loop
           set u = FirstOfGroup(g)
           exitwhen u == null

           set e[count] = AddSpecialEffectTarget("Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl",u,"chest")
           set count = count + 1
           // dmg unit
           call UnitDamageTarget( udg_HERO_Capricorn, u, DMG,true,false, ATTACK_TYPE_MELEE, DAMAGE_TYPE_FORCE,WEAPON_TYPE_WHOKNOWS )
           call GroupRemoveUnit(g,u)//This --------------------
       endloop

       // Capricorn Anim
       set e[count] = AddSpecialEffectTarget("war3mapImported\\Flail.mdx",udg_HERO_Capricorn,"overhead")

       call TriggerSleepAction(0.60 - I2R(SPELL_LVL / 10))

       loop
           exitwhen i > count
           call DestroyEffect(e[i])
           set e[i] = null
           set i = i + 1
endloop

       set udg_Capricorn_Spin = false
       call DestroyGroup(g)
    endif

    set g = null
    set u = null

endfunction

//===========================================================================
function InitTrig_Morgenstern takes nothing returns nothing
    set gg_trg_Morgenstern = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Morgenstern, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Morgenstern, Condition( function Trig_Morgenstern_Conditions ) )
    call TriggerAddAction( gg_trg_Morgenstern, function Trig_Morgenstern_Actions )
endfunction

Usually when things start to lag, the problem is a loop. Either a normal loop or trigger firing on itself(or maybe a chain of triggers).
 
Level 14
Joined
Jul 1, 2008
Messages
1,314
oh my god, how could i forget this !

I knew that its the loop, but why didnt i see that GroupRemoveUnit() was missing? oO

Thanks spwin :D

Edit: sh*** cant rep you anymore, but i will, when i added some rep to other ppl, Thanks alot anyways :)
 
Status
Not open for further replies.
Top