• 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] Help needed with a triggered spell.

Status
Not open for further replies.
Level 5
Joined
Jan 6, 2006
Messages
106
Here is the JASS code of a "shockwave" type spell which heals allied units and damages enemy units in a line.

However, every time I cast the spell, it will result it severe framerate drops. And it gets cumulatively worse.

I've followed the JASS guide and closed all leaks as instructed. But it doesn't help. Even increasing the interval between each run of the trigger doesn't. Please help me to find out what is wrong. Thanks.


Oh, and 1 more thing. If I make this spell to be targeted at specific units, this kind of thing does not happen. Can someone please tell me why?

------------------------------------------------------------------------------------

function Trig_Nullifying_Bolt_Conditions takes nothing returns boolean
if ( not ( GetSpellAbilityId() == 'A0LL' ) ) then
return false
endif
return true
endfunction

function NullifyingBoltEffect takes nothing returns nothing
local trigger trg = GetTriggeringTrigger()
local group k = GetHandleGroup(trg,"k")
local unit u = GetHandleUnit(trg,"u")
local location p = GetHandleLocation(trg,"p")
local unit h = GetEnumUnit()
local location l = GetUnitLoc(h)
if ( IsUnitType(h, UNIT_TYPE_STRUCTURE) == false ) then
if ( IsUnitType(h, UNIT_TYPE_MECHANICAL) == false ) then
if ( IsUnitAliveBJ(h) == true ) then
if ( GetUnitAbilityLevelSwapped('Avul', h) == 0 ) then
if ( IsUnitInGroup(h, k) == false ) then
if ( IsUnitType(h, UNIT_TYPE_MAGIC_IMMUNE) == false ) then
if ( h != u ) then
call GroupAddUnitSimple( h, k )
if ( IsUnitEnemy(h, GetOwningPlayer(u)) == true ) then
call UnitDamageTargetBJ( u, h, ( 00.00 + ( 65.00 * I2R(GetUnitAbilityLevelSwapped('A0LL', u)) ) ), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_FIRE )
else
call SetUnitLifeBJ( h, ( GetUnitStateSwap(UNIT_STATE_LIFE, h) + ( 0.00 + ( 50.00 * I2R(GetUnitAbilityLevelSwapped('A0LL', u)) ) ) ) )
endif
call AddSpecialEffectTargetUnitBJ( "overhead", h, "Abilities\\Spells\\Undead\\ReplenishHealth\\ReplenishHealthCaster.mdl" )
call TriggerExecute( gg_trg_DestroySFX )
endif
endif
endif
endif
endif
endif
endif
call RemoveLocation(l)
set l = null
set u = null
set p = null
set h = null
set k = null
set trg = null
endfunction

function NullifyingBolt takes nothing returns nothing
local trigger trg = GetTriggeringTrigger()
local group k = GetHandleGroup(trg,"k")
local unit u = GetHandleUnit(trg,"u")
local location p = GetHandleLocation(trg,"p")
local unit e = GetHandleUnit(trg,"e")
local location l = GetUnitLoc(e)
local location m = PolarProjectionBJ(l, 20.00, AngleBetweenPoints(l, p))
local group x = GetUnitsInRangeOfLocAll(200.00, l)
local group y = GetUnitsInRangeOfLocAll(18.00, p)
call ForGroupBJ( x, function NullifyingBoltEffect )
if ( RectContainsLoc(udg_EntireMap, p) == false ) then
call KillUnit(e)
call GroupClear(k)
call RemoveUnit(e)
call DestroyGroup(k)
call DestroyGroup(x)
call DestroyGroup(y)
call RemoveLocation(l)
call RemoveLocation(m)
call RemoveLocation(p)
call DisableTrigger(trg)
call FlushHandleLocals(trg)
call DestroyTrigger(trg)
set u = null
set p = null
set e = null
set k = null
set x = null
set y = null
set l = null
set m = null
set trg = null
return
endif
call SetUnitPositionLocFacingBJ( e, m, AngleBetweenPoints(l, p) )
if IsUnitInGroup(e, y) then
call KillUnit(e)
call GroupClear(k)
call RemoveUnit(e)
call DestroyGroup(k)
call DestroyGroup(x)
call DestroyGroup(y)
call RemoveLocation(l)
call RemoveLocation(m)
call RemoveLocation(p)
call DisableTrigger(trg)
call FlushHandleLocals(trg)
call DestroyTrigger(trg)
set u = null
set p = null
set e = null
set k = null
set x = null
set y = null
set l = null
set m = null
set trg = null
endif
call DestroyGroup(x)
call DestroyGroup(y)
call RemoveLocation(l)
call RemoveLocation(m)
set u = null
set p = null
set e = null
set k = null
set x = null
set y = null
set l = null
set m = null
set trg = null
endfunction

function Trig_Nullifying_Bolt_Actions takes nothing returns nothing
local unit u = GetSpellAbilityUnit()
local location l = GetUnitLoc(u)
local location m = GetSpellTargetLoc()
local location p = PolarProjectionBJ(l, 800.00, AngleBetweenPoints(l, m))
local unit e = CreateUnit(GetOwningPlayer(u),'h02O',GetLocationX(l),GetLocationY(l),AngleBetweenPoints(l, m))
local trigger trg = CreateTrigger()
local group k = CreateGroup()
call SetHandleHandle(trg,"u",u)
call SetHandleHandle(trg,"p",p)
call SetHandleHandle(trg,"e",e)
call SetHandleHandle(trg,"k",k)
call TriggerRegisterTimerEventPeriodic(trg,0.02)
call TriggerAddAction(trg,function NullifyingBolt)
call RemoveLocation(l)
call RemoveLocation(m)
set u = null
set p = null
set e = null
set k = null
set l = null
set m = null
set trg = null
endfunction

//===========================================================================
function InitTrig_Nullifying_Bolt takes nothing returns nothing
set gg_trg_Nullifying_Bolt = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Nullifying_Bolt, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Nullifying_Bolt, Condition( function Trig_Nullifying_Bolt_Conditions ) )
call TriggerAddAction( gg_trg_Nullifying_Bolt, function Trig_Nullifying_Bolt_Actions )
endfunction
 
Level 16
Joined
Feb 22, 2006
Messages
960
the first thing i see is... wtf like 1000 if constructions in another if construction... try to use if x and y and z then

for the usage of the forum please use the
JASS:
 tag for a better read... then if you use handlevar system, why you create a new trigger in this trigger you could do it with a timer would shorten the code rapidly
 
Level 5
Joined
Jan 6, 2006
Messages
106
Sorry but I'm not that good with timers XD

Well, I used a similar script for all my targeted spells. What puzzles me is that those on targeted spells works out perfectly. Those in point target spells, however, makes it laggier with every cast of the spell.

Can you help me take a look please?

-------------------------------------------------------------------------------------------------------------------------

Sorry for the double posting, but I've just found out something really stupid.


Take a look at this, I've just found it out from my previously built spells.

Skill: Mana Bomb
JASS:
function Trig_Mana_Bomb_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A0KX' ) ) then
        return false
    endif
    return true
endfunction

function ManaBombEffect takes nothing returns nothing
    local trigger trg = GetTriggeringTrigger()
    local group k = GetHandleGroup(trg,"k")
    local unit u = GetHandleUnit(trg,"u")
    local unit e = GetHandleUnit(trg,"e")
    local location p = GetHandleLocation(trg,"p")
    local unit h = GetEnumUnit()
    local real r = ( I2R(GetUnitUserData(e)) * ( 0.80 + ( 0.20 * I2R(GetUnitAbilityLevelSwapped('A0KX', u)) ) ) )
    if ( IsUnitType(h, UNIT_TYPE_STRUCTURE) == false ) then
        if ( IsUnitType(h, UNIT_TYPE_MECHANICAL) == false ) then
            if ( IsUnitAliveBJ(h) == true ) then
                if ( GetUnitAbilityLevelSwapped('Avul', h) == 0 ) then
                    if ( IsUnitEnemy(h, GetOwningPlayer(u)) == true ) then
                        if ( IsUnitInGroup(h, k) == false ) then
                            if ( IsUnitType(h, UNIT_TYPE_MAGIC_IMMUNE) == false ) then
                                call GroupAddUnitSimple( h, k )
                                call UnitDamageTargetBJ( e, h, r, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_FIRE )
                                call CreateTextTagUnitBJ( I2S(R2I(r)), h, 0, 10, 0.00, 100.00, 0.00, 0 )
                                call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false )
                                call SetTextTagVelocityBJ( GetLastCreatedTextTag(), 64, 90 )
                                call SetTextTagLifespanBJ( GetLastCreatedTextTag(), 2.00 )
                                call SetTextTagFadepointBJ( GetLastCreatedTextTag(), 2.00 )
                                call TriggerExecute( gg_trg_DestroyTextTag )
                            endif
                        endif
                    endif
                endif
            endif
        endif
    endif
    set u = null
    set e = null
    set p = null
    set h = null
    set k = null
    set trg = null
endfunction

function ManaBomb takes nothing returns nothing
    local trigger trg = GetTriggeringTrigger()
    local group k = GetHandleGroup(trg,"k")
    local unit u = GetHandleUnit(trg,"u")
    local location p = GetHandleLocation(trg,"p")
    local unit e = GetHandleUnit(trg,"e")
    local unit f = null
    local location l = GetUnitLoc(e)
    local location m = PolarProjectionBJ(l, 20.00, AngleBetweenPoints(l, p))
    local group x = GetUnitsInRangeOfLocAll(250.00, l)
    local group y = GetUnitsInRangeOfLocAll(12.00, p)
    call ForGroupBJ( x, function ManaBombEffect )
    if ( RectContainsLoc(udg_EntireMap, p) == false ) then
        call KillUnit(e)
        call GroupClear(k)
        call DestroyGroup(k)
        call DestroyGroup(x)
        call DestroyGroup(y)
        call RemoveLocation(l)
        call RemoveLocation(m)
        call RemoveLocation(p)
        call DisableTrigger(trg)
        call FlushHandleLocals(trg)
        call DestroyTrigger(trg)
        set u = null
        set p = null
        set e = null
        set f = null
        set k = null
        set x = null
        set y = null
        set l = null
        set m = null
        set trg = null
        return
    endif
    call SetUnitPositionLocFacingBJ( e, m, AngleBetweenPoints(l, p) )
    if IsUnitInGroup(e, y) then
        call KillUnit(e)
        call GroupClear(k)
        call DestroyGroup(k)
        call DestroyGroup(x)
        call DestroyGroup(y)
        call RemoveLocation(l)
        call RemoveLocation(m)
        call RemoveLocation(p)
        call DisableTrigger(trg)
        call FlushHandleLocals(trg)
        call DestroyTrigger(trg)
        set u = null
        set p = null
        set e = null
        set f = null
        set k = null
        set x = null
        set y = null
        set l = null
        set m = null
        set trg = null
    endif
    call DestroyGroup(x)
    call DestroyGroup(y)
    call RemoveLocation(l)
    call RemoveLocation(m)
    set u = null
    set p = null
    set e = null
    set f = null
    set k = null
    set x = null
    set y = null
    set l = null
    set m = null
    set trg = null
endfunction

function Trig_Mana_Bomb_Actions takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local location r = GetSpellTargetLoc()
    local location q = GetUnitLoc(u)
    local location p = PolarProjectionBJ(q, 800.00, AngleBetweenPoints(q, r))
    local unit e = CreateUnit(GetOwningPlayer(u),'h02I',GetLocationX(q),GetLocationY(q),0.00)
    local trigger trg = CreateTrigger()
    local group k = CreateGroup()
    local real re = 0.00
    set re = ( GetUnitStateSwap(UNIT_STATE_MANA, u) * 0.60 )
    call SetUnitManaBJ( u, ( GetUnitStateSwap(UNIT_STATE_MANA, u) - re ) )
    call SetUnitUserData( e, R2I(re) )
    call SetHandleHandle(trg,"u",u)
    call SetHandleHandle(trg,"p",p)
    call SetHandleHandle(trg,"e",e)
    call SetHandleHandle(trg,"k",k)
    call TriggerRegisterTimerEventPeriodic(trg,0.02)
    call TriggerAddAction(trg,function ManaBomb)
    call RemoveLocation(q)
    call RemoveLocation(r)
    set u = null
    set p = null
    set q = null
    set e = null
    set k = null
    set r = null
    set re = 0.00
    set trg = null
endfunction

//===========================================================================
function InitTrig_Mana_Bomb takes nothing returns nothing
    set gg_trg_Mana_Bomb = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Mana_Bomb, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Mana_Bomb, Condition( function Trig_Mana_Bomb_Conditions ) )
    call TriggerAddAction( gg_trg_Mana_Bomb, function Trig_Mana_Bomb_Actions )
endfunction

If you noticed, this spell uses the EXACTLY same scripting as the last one. But it doesn't cause ANY lagness at all.

This is really getting ridiculous. Somebody help please...

-----------------------------------------------------------------------------------------------------------------------
I'm reuploading the Nullifying Bolt script, the one with the lagness problems.
JASS:
function Trig_Nullifying_Bolt_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A0LL' ) ) then
        return false
    endif
    return true
endfunction

function NullifyingBoltEffect takes nothing returns nothing
    local trigger trg = GetTriggeringTrigger()
    local group k = GetHandleGroup(trg,"k")
    local unit u = GetHandleUnit(trg,"u")
    local unit e = GetHandleUnit(trg,"e")
    local location p = GetHandleLocation(trg,"p")
    local unit h = GetEnumUnit()
    if ( IsUnitType(h, UNIT_TYPE_STRUCTURE) == false ) then
        if ( IsUnitType(h, UNIT_TYPE_MECHANICAL) == false ) then
            if ( IsUnitAliveBJ(h) == true ) then
                if ( GetUnitAbilityLevelSwapped('Avul', h) == 0 ) then
                    if ( IsUnitInGroup(h, k) == false ) then
                        if ( IsUnitType(h, UNIT_TYPE_MAGIC_IMMUNE) == false ) then
                            if ( h != u ) then
                                call GroupAddUnitSimple( h, k )
                                if ( IsUnitEnemy(h, GetOwningPlayer(u)) == true ) then
                                    call UnitDamageTargetBJ( u, h, ( 00.00 + ( 65.00 * I2R(GetUnitAbilityLevelSwapped('A0LL', u)) ) ), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_FIRE )
                                else
                                    call SetUnitLifeBJ( h, ( GetUnitStateSwap(UNIT_STATE_LIFE, h) + ( 0.00 + ( 50.00 * I2R(GetUnitAbilityLevelSwapped('A0LL', u)) ) ) ) )
                                endif
                                call AddSpecialEffectTargetUnitBJ( "overhead", h, "Abilities\\Spells\\Undead\\ReplenishHealth\\ReplenishHealthCaster.mdl" )
                                call TriggerExecute( gg_trg_DestroySFX )
                            endif
                        endif
                    endif
                endif
            endif
        endif
    endif
    set u = null
    set e = null
    set p = null
    set h = null
    set k = null
    set trg = null
endfunction

function NullifyingBolt takes nothing returns nothing
    local trigger trg = GetTriggeringTrigger()
    local group k = GetHandleGroup(trg,"k")
    local unit u = GetHandleUnit(trg,"u")
    local location p = GetHandleLocation(trg,"p")
    local unit e = GetHandleUnit(trg,"e")
    local unit f = null
    local location l = GetUnitLoc(e)
    local location m = PolarProjectionBJ(l, 20.00, AngleBetweenPoints(l, p))
    local group x = GetUnitsInRangeOfLocAll(200.00, l)
    local group y = GetUnitsInRangeOfLocAll(12.00, p)
    call ForGroupBJ( x, function NullifyingBoltEffect )
    if ( RectContainsLoc(udg_EntireMap, p) == false ) then
        call KillUnit(e)
        call GroupClear(k)
        call DestroyGroup(k)
        call DestroyGroup(x)
        call DestroyGroup(y)
        call RemoveLocation(l)
        call RemoveLocation(m)
        call RemoveLocation(p)
        call DisableTrigger(trg)
        call FlushHandleLocals(trg)
        call DestroyTrigger(trg)
        set u = null
        set p = null
        set e = null
        set f = null
        set k = null
        set x = null
        set y = null
        set l = null
        set m = null
        set trg = null
        return
    endif
    call SetUnitPositionLocFacingBJ( e, m, AngleBetweenPoints(l, p) )
    if IsUnitInGroup(e, y) then
        call KillUnit(e)
        call GroupClear(k)
        call DestroyGroup(k)
        call DestroyGroup(x)
        call DestroyGroup(y)
        call RemoveLocation(l)
        call RemoveLocation(m)
        call RemoveLocation(p)
        call DisableTrigger(trg)
        call FlushHandleLocals(trg)
        call DestroyTrigger(trg)
        set u = null
        set p = null
        set e = null
        set f = null
        set k = null
        set x = null
        set y = null
        set l = null
        set m = null
        set trg = null
    endif
    call DestroyGroup(x)
    call DestroyGroup(y)
    call RemoveLocation(l)
    call RemoveLocation(m)
    set u = null
    set p = null
    set e = null
    set f = null
    set k = null
    set x = null
    set y = null
    set l = null
    set m = null
    set trg = null
endfunction

function Trig_Nullifying_Bolt_Actions takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local location y = GetSpellTargetLoc()
    local location x = GetUnitLoc(u)
    local location p = PolarProjectionBJ(x, 800.00, AngleBetweenPoints(x, y))
    local unit e = CreateUnit(GetOwningPlayer(u),'h02O',GetLocationX(x),GetLocationY(x),0.00)
    local trigger trg = CreateTrigger()
    local group k = CreateGroup()
    call SetHandleHandle(trg,"u",u)
    call SetHandleHandle(trg,"p",p)
    call SetHandleHandle(trg,"e",e)
    call SetHandleHandle(trg,"k",k)
    call TriggerRegisterTimerEventPeriodic(trg,0.02)
    call TriggerAddAction(trg,function NullifyingBolt)
    call RemoveLocation(y)
    call RemoveLocation(x)
    set u = null
    set y = null
    set x = null
    set e = null
    set k = null
    set p = null
    set trg = null
endfunction

//===========================================================================
function InitTrig_Nullifying_Bolt takes nothing returns nothing
    set gg_trg_Nullifying_Bolt = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Nullifying_Bolt, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Nullifying_Bolt, Condition( function Trig_Nullifying_Bolt_Conditions ) )
    call TriggerAddAction( gg_trg_Nullifying_Bolt, function Trig_Nullifying_Bolt_Actions )
endfunction

As you can see, I remade this skill based entirely on the Mana Bomb skill, I've even tried to switch spell effects for both skills. Unfortunately, Nullifying Bolt still cause lagness. Mana Bomb doesn't.

Maybe this is due to some World Editor problem or something...
 
Last edited:
Level 6
Joined
Sep 13, 2008
Messages
261
Your problem seems to be you're basing it of an unrelated skill.
You should request someone make you a new one or you should from scratch.


there were alot of problems in your script such as
call SetUnitPositionLocFacingBJ( e, m, AngleBetweenPoints(l, p) )
being used after you set the locals involved to null.

You really shouldn't set locals to null until you are done using them.
In the long run it will create more lag to null them and redeclare them repeatedly then it would to wait till the very end of the function.
 
Level 5
Joined
Jan 6, 2006
Messages
106
Your problem seems to be you're basing it of an unrelated skill.
You should request someone make you a new one or you should from scratch.


there were alot of problems in your script such as
call SetUnitPositionLocFacingBJ( e, m, AngleBetweenPoints(l, p) )
being used after you set the locals involved to null.

You really shouldn't set locals to null until you are done using them.
In the long run it will create more lag to null them and redeclare them repeatedly then it would to wait till the very end of the function.

Actually JASS works the other way round.

local variables are limited in a specific function, that is, it won't go anywhere outside of the function. Since the spell effect and the initialization are different functions we'll have to redeclare the local vars again, whether we like it or not. And ALL local variables in triggers must be nullified, as by not doing so will cause the variable to permanently store in the function, resulting in cumulatively severe performance issues as your game progresses.
 
Level 6
Joined
Sep 13, 2008
Messages
261
You nulled it in your if function then used it later in the same function. Thereby if your if triggered then it would refer to a non existent location.


Notice I used the word funtion and not trigger.
 
Level 5
Joined
Jan 6, 2006
Messages
106
Oh, I see. Thanks for the help anyway.

I've just solved my own problem.

Guess what? The problem has NOTHING to do with JASS but with another GUI trigger which runs an illegal looping function every time I cast a spell with the "shockwave" order string.

Mana Bomb is the ONLY "shockwave" type spell that is based on Carrion Swarm, the others are based on Shockwave, including Nullifying Bolt. That's why they all have the same problems.

Unfortunately, the GUI trigger in question is an essential trigger which should not be removed, so I have to remake EVERY spell based on the Shockwave ability (20++ of them). Sigh~~ D:

BTW, thanks for everyone for the suggestions and help in this thread.
+rep to all.
 
Status
Not open for further replies.
Top