Destroying Group makes spell unusuable twice.

romanandre

New Member
Reaction score
2
Whenever I use this coded spell twice it doesnt deal damage, but however if I remove the line: DestroyGroup(grp);
It works normaly, how bad are group leaks? and anyone knows how to fix it? (sorry for zinc coding I just cant with vjass)

JASS:
 // CHANGE ANIMATION SCALING VALUE
//! zinc
library FireImpulsion requires DummyCaster
{
    constant integer SPELL_ID = 'A003';
    
    constant string SPELLFX1 = "Abilities\\Spells\\Other\\Doom\\DoomDeath.mdl"; 
    constant string ATTACH = "origin";
    
    constant real DAMAGE = 100;
    constant real RADIUS = 85;
    constant real DISTANCE = 75;
    
    constant attacktype AT = ATTACK_TYPE_NORMAL;
    constant damagetype DT = DAMAGE_TYPE_NORMAL;
    constant weapontype WT = WEAPON_TYPE_WHOKNOWS;
    
    boolexpr b;
    real x2[10][10];
    real y2[10][10];
    location loc[10][10];
    unit u;
    group grp = CreateGroup();
    
    function SpellIdMatch() -> boolean
    {
        return (GetSpellAbilityId() == SPELL_ID);
    }
    function Targets(unit target) -> boolean
    {
        return (GetWidgetLife(target) > 0.405) &&! IsUnitType(target, UNIT_TYPE_STRUCTURE) &&! IsUnitType(target, UNIT_TYPE_FLYING) &&! IsUnitType(target, UNIT_TYPE_MAGIC_IMMUNE) &&! IsUnitType(target, UNIT_TYPE_MECHANICAL) && IsUnitEnemy(target,GetOwningPlayer(u));
    }
    function Pick() -> boolean
    {
        if (Targets(GetFilterUnit()))
        {
            UnitDamageTarget(u, GetFilterUnit(), DAMAGE, true, true, AT, DT, WT);
        }
        return false;
    }
    
    function onSpellCast()
    {
        real x1;
        real y1;
        integer i;
        integer j;
        real facing;
        real x;
        real y;      
        real test;
        real test2;
        u = GetTriggerUnit();
        facing = GetUnitFacing(u)*bj_DEGTORAD;
        x = GetUnitX(u);
        y = GetUnitY(u);
        for(i=1;i<=4;i+=1) {
            x1 = x + DISTANCE*i*Cos(facing);
            y1 = y + DISTANCE*i*Sin(facing);
            AddSpecialEffectTimed(SPELLFX1, x1, y1, 0.03125);
            x2[0]<i> = x1;
            y2[0]<i> = y1;
            loc[0]<i> = Location(x2[0]<i>, y2[0]<i>);
        }
        for(i=-2;i&lt;=2;i+=1) {
            x1 = x  + DISTANCE*5*Cos(facing + 15*i*bj_DEGTORAD);
            y1 = y  + DISTANCE*5*Sin(facing + 15*i*bj_DEGTORAD);
            AddSpecialEffectTimed(SPELLFX1, x1, y1, 0.03125);
            x2[1][i+2] = x1;
            y2[1][i+2] = y1;
            loc[1][i+2] = Location(x2[1][i+2], y2[1][i+2]);
        }
        for(i=-1;i&lt;=1;i+=1) {
            x1 = x + DISTANCE*4*Cos(facing + 30*i*bj_DEGTORAD);
            y1 = y + DISTANCE*4*Sin(facing + 30*i*bj_DEGTORAD);
            AddSpecialEffectTimed(SPELLFX1, x1, y1, 0.03125);
            x2[2][i+1] = x1;
            y2[2][i+1] = y1;
            loc[2][i+1] = Location(x2[2][i+1], y2[2][i+1]);
        }
        for(i=-1;i&lt;=1;i+=1) {
            if (i!=0) {
                x1 = x + DISTANCE*3*Cos(facing + 15*i*bj_DEGTORAD);
                y1 = y + DISTANCE*3*Sin(facing + 15*i*bj_DEGTORAD);
                AddSpecialEffectTimed(SPELLFX1, x1, y1, 0.03125);
                x2[3][i+1] = x1;
                y2[3][i+1] = y1;
                loc[3][i+1] = Location(x2[3][i+1], y2[3][i+1]);
            }
        }
        for(i=0;i&lt;6;i+=1) {
            for(j=0;j&lt;4;j+=1) {
                GroupEnumUnitsInRangeOfLoc(grp, loc[j]<i>, RADIUS, b);
            }
        }
        DestroyGroup(grp);
    }   
    
    function onInit()
    {
        trigger t = CreateTrigger();
        TriggerAddAction(t, function onSpellCast);
        TriggerAddCondition(t, Condition(function SpellIdMatch));
        TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT);
        b = Condition(function Pick);
        u = GetTriggerUnit();
        Preload(SPELLFX1);
    }
}
//! endzinc </i></i></i></i></i></i>
 

Dirac

22710180
Reaction score
147
1. You only initialize the group once, in the globals, so destroying it makes it null. Instead try [ljass]GroupClear(grp)[/ljass]
2. You're using lots of 2d arrays which are terrible
3. You leak lots of locations which are completely useless. (Instead of [ljass]GroupEnumUnitsInRangeOfLoc()[/ljass] use [ljass]GroupEnumUnitsInRange()[/ljass])
4. You should use libraries such as SpellEffectEvent to register spell calls
5. At the init function [ljass]GetTriggerUnit()[/ljass] returns null, since there isnt one.
6. There's no need to store [ljass]Condition(function Pick)[/ljass] inside a varaible
 

romanandre

New Member
Reaction score
2
Why 2d arrays are that bad? they are like 1d array compiled, and using GroupEnumUnitsInRange() makes a lot harder to code the spell, but I will try , Thanks a lot.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top