| 10-30-2006, 01:51 PM | #1 |
Hello i'm making a spell with a casting time has need a chaneling, when the time is reached, the spell is casting in an area in front the caster, killing trees and units in front. But when the caster launch the bolt, leak the game, so here my code: JASS:function Trig_slave_Conditions takes nothing returns boolean return ( GetSpellAbilityId() == 'A0AE' ) endfunction function mataarbol takes nothing returns nothing if ( GetDestructableLife(GetEnumDestructable())> 0 ) then call KillDestructable(GetEnumDestructable() ) else endif endfunction function Trig_slave_Actions takes nothing returns nothing local unit u = GetTriggerUnit() local unit d1 local unit d2 local unit array d3 local group g1 local group g2 local unit j local real x1 = GetUnitX(u) local real y1 = GetUnitY(u) local integer l = GetUnitAbilityLevel(u,'A0AE') local real dmg1 = -100 local real dmgprogre = 500 local real x2 = GetHandleReal(u,"x2") local real y2 = GetHandleReal(u,"y2") local real ang = GetAngleBetweenPoints(x1,y1,x2,y2) local real x3 = PolarProjectionX(x1,150,ang) local real y3 = PolarProjectionY(y1,150,ang) local location loc3 local player p = GetOwningPlayer(u) local effect e local integer i local terraindeformation terra local real dirX local real dirY set e = AddSpecialEffect("Objects\\Spawnmodels\\NightElf\\NEDeathSmall\\NEDeathSmall.mdl",x3,y3) call DestroyEffect(e) set e = AddSpecialEffect("Objects\\Spawnmodels\\Other\\NeutralBuildingExplosion\\NeutralBuildingExplosion.mdl",x3,y3) call DestroyEffect(e) //Unit bolt effect set d1 = CreateUnit(p,'h00L',x3,y3,ang) call SetUnitScalePercent(d1,250+(l*10),250+(l*10),250+(l*10)) //Unit explotion effect. set d2 = CreateUnit(p,'h00M',x3,y3,ang) call SetUnitScalePercent(d2,350+(l*10),350+(l*10),350+(l*10)) call SetUnitTimeScale(d2,0.15) call KillUnit(d2) set g2 = CreateGroup() set i = 0 loop exitwhen i > 5 set x3 = PolarProjectionX(x1,200*i,ang) set y3 = PolarProjectionY(y1,200*i,ang) set loc3 = Location(x3,y3) call SetTerrainType(x3,y3, 'Kdtr', -1, 2, 0 ) call SetTerrainType(x3,y3, 'Jdtr', -1, 1, 0 ) //Some effect too set d3[i] = CreateUnit(p,'h004',x3,y3,0 ) set g1 = GetUnitsInRangeOfLocMatching(200,loc3,null) set j = FirstOfGroup(g1) loop exitwhen j == null set j = FirstOfGroup(g1) call GroupRemoveUnit(g1,j) call GroupAddUnit(g2,j) endloop call EnumDestructablesInCircleBJ(200,loc3, function mataarbol) set i = i+1 call RemoveLocation(loc3) call DestroyGroup(g1) endloop set j = FirstOfGroup(g2) loop exitwhen j == null set j = FirstOfGroup(g2) call GroupRemoveUnit(g2,j) if(IsUnitEnemy(j,p)==true)then call UnitDamageTarget(u,j,dmg1+dmgprogre*l,true,false,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_MAGIC,null) endif endloop set x3 = PolarProjectionX(x1,900*4,ang) set y3 = PolarProjectionY(y1,900*4,ang) set dirX = (x3 - x1) / GetDistanceBetweenPoints(x1,y1,x3,y3) set dirY = (y3 - y1) / GetDistanceBetweenPoints(x1,y1,x3,y3) set terra = TerrainDeformWave(x1,y1,dirX, dirY,GetDistanceBetweenPoints(x1,y1,x3,y3),GetDistanceBetweenPoints(x1,y1,x3,y3)/3,400,128,1000, 1) call TriggerSleepAction(3) set i = 0 loop exitwhen i > 5 call RemoveUnit(d3[i]) set d3[i] = null set i = i+1 endloop call RemoveLocation(loc3) call DestroyGroup(g2) call DestroyGroup(g1) set loc3=null set u = null set p = null call RemoveUnit(d1) call RemoveUnit(d2) set d1 = null set d2 = null set g1 = null set g2 = null set j = null call DestroyEffect(e) set e = null set terra = null endfunction function Trig_slave1_Conditions takes nothing returns boolean return ( GetSpellAbilityId() == 'A0AE' ) endfunction function Trig_slave1_Actions takes nothing returns nothing local unit u = GetTriggerUnit() local unit d local real x = GetUnitX(u) local real y = GetUnitY(u) local location loc = GetSpellTargetLoc() local real x2 = GetLocationX(loc) local real y2 = GetLocationY(loc) local real xaux local real yaux local lightning array rayo local real ang = 30 local integer i = 0 local trigger t =CreateTrigger() local event evento1 if(x2==0)then set x2=1 endif if(y2==0)then set y2=1 endif call SetHandleReal(u,"x2",x2) call SetHandleReal(u,"y2",y2) set evento1 = TriggerRegisterUnitEvent(t,u,EVENT_UNIT_SPELL_FINISH ) call TriggerAddCondition(t, Condition( function Trig_slave1_Conditions ) ) call TriggerAddAction(t, function Trig_slave_Actions) loop exitwhen ang > 300 set xaux = PolarProjectionX(x,100,ang) set yaux = PolarProjectionY(y,100,ang) set d = CreateUnit(GetOwningPlayer(u),'hfoo',xaux,yaux,0) call UnitApplyTimedLife(d,'BTLF', 4) set rayo[i] = AddLightning("AFOD",true,x,y,xaux,yaux) set ang = ang + 90 set i = i+1 endloop call TriggerSleepAction(4.1) set i=0 loop exitwhen i>4 call DestroyLightning(rayo[i]) set rayo[i]=null set i = i+1 endloop call FlushHandleLocals(u) call DestroyTrigger(t) call RemoveLocation(loc) set loc = null set t = null set d = null set u = null set evento1 = null endfunction //=========================================================================== function InitTrig_slave1 takes nothing returns nothing local trigger gg_trg_slave1 = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_slave1, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddCondition( gg_trg_slave1, Condition( function Trig_slave1_Conditions ) ) call TriggerAddAction( gg_trg_slave1, function Trig_slave1_Actions ) endfunction what's wrong? why is leaking? |
| 10-30-2006, 02:07 PM | #2 |
You are not leaking a group, you are leaking plenty of things JASS:function Trig_slave_Conditions takes nothing returns boolean return ( GetSpellAbilityId() == 'A0AE' ) endfunction function mataarbol takes nothing returns nothing if ( GetDestructableLife(GetEnumDestructable())> 0 ) then call KillDestructable(GetEnumDestructable() ) else endif endfunction function Trig_slave_Actions takes nothing returns nothing local unit u = GetTriggerUnit() local unit d1 local unit d2 local unit array d3 local group g1 local group g2 local unit j local real x1 = GetUnitX(u) local real y1 = GetUnitY(u) local integer l = GetUnitAbilityLevel(u,'A0AE') local real dmg1 = -100 local real dmgprogre = 500 local real x2 = GetHandleReal(u,"x2") local real y2 = GetHandleReal(u,"y2") local real ang = GetAngleBetweenPoints(x1,y1,x2,y2) local real x3 = PolarProjectionX(x1,150,ang) local real y3 = PolarProjectionY(y1,150,ang) local location loc3 local player p = GetOwningPlayer(u) local effect e local integer i local terraindeformation terra local real dirX local real dirY set e = AddSpecialEffect("Objects\\Spawnmodels\\NightElf\\NEDeathSmall\\NEDeathSmall.mdl",x3,y3) call DestroyEffect(e) set e = AddSpecialEffect("Objects\\Spawnmodels\\Other\\NeutralBuildingExplosion\\NeutralBuildingExplosion.mdl",x3,y3) call DestroyEffect(e) //Unit bolt effect set d1 = CreateUnit(p,'h00L',x3,y3,ang) call SetUnitScalePercent(d1,250+(l*10),250+(l*10),250+(l*10)) //Unit explotion effect. set d2 = CreateUnit(p,'h00M',x3,y3,ang) call SetUnitScalePercent(d2,350+(l*10),350+(l*10),350+(l*10)) call SetUnitTimeScale(d2,0.15) call KillUnit(d2) set g2 = CreateGroup() set i = 0 loop exitwhen i > 5 set x3 = PolarProjectionX(x1,200*i,ang) set y3 = PolarProjectionY(y1,200*i,ang) set loc3 = Location(x3,y3) call SetTerrainType(x3,y3, 'Kdtr', -1, 2, 0 ) call SetTerrainType(x3,y3, 'Jdtr', -1, 1, 0 ) //Some effect too set d3[i] = CreateUnit(p,'h004',x3,y3,0 ) set g1 = GetUnitsInRangeOfLocMatching(200,loc3,null) //this bj function causes a leak since it is a local not set to null, Use GroupEnumUnitsInRangeOfLoc instead set j = FirstOfGroup(g1) loop exitwhen j == null set j = FirstOfGroup(g1) call GroupRemoveUnit(g1,j) call GroupAddUnit(g2,j) endloop call EnumDestructablesInCircleBJ(200,loc3, function mataarbol) set i = i+1 call RemoveLocation(loc3) call DestroyGroup(g1) endloop set j = FirstOfGroup(g2) loop exitwhen j == null set j = FirstOfGroup(g2) call GroupRemoveUnit(g2,j) if(IsUnitEnemy(j,p)==true)then call UnitDamageTarget(u,j,dmg1+dmgprogre*l,true,false,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_MAGIC,null) endif endloop set x3 = PolarProjectionX(x1,900*4,ang) set y3 = PolarProjectionY(y1,900*4,ang) set dirX = (x3 - x1) / GetDistanceBetweenPoints(x1,y1,x3,y3) set dirY = (y3 - y1) / GetDistanceBetweenPoints(x1,y1,x3,y3) set terra = TerrainDeformWave(x1,y1,dirX, dirY,GetDistanceBetweenPoints(x1,y1,x3,y3),GetDistanceBetweenPoints(x1,y1,x3,y3)/3,400,128,1000, 1) call TriggerSleepAction(3) set i = 0 loop exitwhen i > 5 call RemoveUnit(d3[i]) set d3[i] = null set i = i+1 endloop call RemoveLocation(loc3) call DestroyGroup(g2) call DestroyGroup(g1) set loc3=null set u = null set p = null call RemoveUnit(d1) call RemoveUnit(d2) set d1 = null set d2 = null set g1 = null set g2 = null set j = null call DestroyEffect(e) //This effect has already been destroyed. set e = null set terra = null endfunction function Trig_slave1_Conditions takes nothing returns boolean return ( GetSpellAbilityId() == 'A0AE' ) endfunction function Trig_slave1_Actions takes nothing returns nothing local unit u = GetTriggerUnit() local unit d local real x = GetUnitX(u) local real y = GetUnitY(u) local location loc = GetSpellTargetLoc() local real x2 = GetLocationX(loc) local real y2 = GetLocationY(loc) local real xaux local real yaux local lightning array rayo local real ang = 30 local integer i = 0 local trigger t =CreateTrigger() local event evento1 if(x2==0)then set x2=1 endif if(y2==0)then set y2=1 endif call SetHandleReal(u,"x2",x2) call SetHandleReal(u,"y2",y2) set evento1 = TriggerRegisterUnitEvent(t,u,EVENT_UNIT_SPELL_FINISH ) call TriggerAddCondition(t, Condition( function Trig_slave1_Conditions ) ) call TriggerAddAction(t, function Trig_slave_Actions) loop exitwhen ang > 300 set xaux = PolarProjectionX(x,100,ang) set yaux = PolarProjectionY(y,100,ang) set d = CreateUnit(GetOwningPlayer(u),'hfoo',xaux,yaux,0) call UnitApplyTimedLife(d,'BTLF', 4) set rayo[i] = AddLightning("AFOD",true,x,y,xaux,yaux) set ang = ang + 90 set i = i+1 endloop call TriggerSleepAction(4.1) set i=0 loop exitwhen i>4 call DestroyLightning(rayo[i]) set rayo[i]=null set i = i+1 endloop call FlushHandleLocals(u) call DestroyTrigger(t) call RemoveLocation(loc) set loc = null set t = null set d = null set u = null set evento1 = null endfunction //=========================================================================== function InitTrig_slave1 takes nothing returns nothing local trigger gg_trg_slave1 = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_slave1, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddCondition( gg_trg_slave1, Condition( function Trig_slave1_Conditions ) ) call TriggerAddAction( gg_trg_slave1, function Trig_slave1_Actions ) endfunction |
| 10-30-2006, 02:14 PM | #3 |
Thanks!!! Well.... how avoid the leak in TerrainDeformWave call TriggerAddCondition(t, Condition( function Trig_slave1_Conditions ) ) call TriggerAddAction(t, function Trig_slave_Actions) ??? Thanks in advance |
| 10-30-2006, 02:17 PM | #4 |
TerrainDeformStop, I would say don't use a condition, just add an if then else to the actions then: JASS:local triggeraction ac // ... set ac=TriggerAddAction(t, function Trig_slave_Actions) // ... call TriggerRemoveAction(t, ac) call DestroyTrigger(t) // ... set t=null set ac=null |
| 10-30-2006, 02:22 PM | #5 |
like this? JASS:if( GetSpellAbilityId() == 'A0AE' )then set ac=TriggerAddAction(t, function Trig_slave_Actions) endif |
| 10-30-2006, 02:41 PM | #6 |
hell no. JASS:function Trig_slave_Actions takes nothing returns nothing // ... stuff like locals if (GetSpellAbilityId() != 'A0AE') then return endif //better assign the locals now instead of in declarations, you can also split the function in 2 parts, the condition check and the actions |
| 10-30-2006, 03:34 PM | #7 |
OK But this still leaking: JASS:set terra = TerrainDeformWave(x1,y1,dirX, dirY,GetDistanceBetweenPoints(x1,y1,x3,y3),GetDistanceBetweenPoints(x1,y1,x3,y3)/3,400,128,1000, 1) call TriggerSleepAction(3) call TerrainDeformStop(terra,1) why? |
| 10-30-2006, 03:56 PM | #8 |
GetDistanceBetweenPoints()
im guessing its a version of DistanceBetweenPoints() but with coordinations instead of locations in the parameter? |
| 10-30-2006, 03:58 PM | #9 |
Yep, is a Daelin's function |
