Original:
function Trig_Boomerang_Axes_Actions takes nothing returns nothing
local unit u = GetSpellAbilityUnit()
local location pos = GetUnitLoc(u)
local timer t1 = CreateTimer()
local timer t2 = CreateTimer()
local trigger tr1 = CreateTrigger()
local trigger tr2 = CreateTrigger()
local gamecache g = GetBoomerangAxesGameCache()
local integer i = 1
local unit array b
local location array l
set l[1] = PolarProjectionBJ(pos, 80.00, GetUnitFacing(u)-35)
set l[2] = PolarProjectionBJ(pos, 80.00, GetUnitFacing(u)+35)
set l[3] = PolarProjectionBJ(pos, BoomerangAxesDistance(), GetUnitFacing(u)-BoomerangAxesAngle())
set l[4] = PolarProjectionBJ(pos, BoomerangAxesDistance(), GetUnitFacing(u)+BoomerangAxesAngle())
set l[5] = PolarProjectionBJ(l[3], BoomerangAxesRadius(), GetUnitFacing(u)-90)
set l[6] = PolarProjectionBJ(l[3], BoomerangAxesRadius(), GetUnitFacing(u)+90)
set l[7] = PolarProjectionBJ(l[4], BoomerangAxesRadius(), GetUnitFacing(u)-90)
set l[8] = PolarProjectionBJ(l[4], BoomerangAxesRadius(), GetUnitFacing(u)+90)
set l[9] = PolarProjectionBJ(l[3], BoomerangAxesRadius(), GetUnitFacing(u)-90-(AngleBetweenPoints(pos, l[3]) - AngleBetweenPoints(pos, l[5])))
set l[10] = PolarProjectionBJ(l[3], BoomerangAxesRadius(), GetUnitFacing(u)+90+(AngleBetweenPoints(pos, l[3]) - AngleBetweenPoints(pos, l[5])))
set l[11] = PolarProjectionBJ(l[4], BoomerangAxesRadius(), GetUnitFacing(u)-90-(AngleBetweenPoints(pos, l[3]) - AngleBetweenPoints(pos, l[5])))
set l[12] = PolarProjectionBJ(l[4], BoomerangAxesRadius(), GetUnitFacing(u)+90+(AngleBetweenPoints(pos, l[3]) - AngleBetweenPoints(pos, l[5])))
set b[1] = CreateUnitAtLoc(GetOwningPlayer(u), 'e000', l[1], 0)
set b[2] = CreateUnitAtLoc(GetOwningPlayer(u), 'e001', l[2], 0)
call TriggerRegisterTimerExpireEventBJ( tr1, t1 )
call TriggerRegisterTimerExpireEventBJ( tr2, t2 )
call TriggerAddAction( tr1, function BoomerangAxesTimer )
call TriggerAddAction( tr2, function BoomerangAxesTimer )
call StoreIntegerBJ( 1, I2S(BoomerangH2I(tr1)), "direction", g )
call StoreIntegerBJ( 0, I2S(BoomerangH2I(tr2)), "direction", g )
call StoreIntegerBJ( BoomerangH2I(b[1]), I2S(BoomerangH2I(tr1)), "unit", g )
call StoreIntegerBJ( BoomerangH2I(b[2]), I2S(BoomerangH2I(tr2)), "unit", g )
call StoreIntegerBJ( BoomerangH2I(u), I2S(BoomerangH2I(tr1)), "ounit", g )
call StoreIntegerBJ( BoomerangH2I(u), I2S(BoomerangH2I(tr2)), "ounit", g )
call StoreIntegerBJ( BoomerangH2I(CreateGroup()), I2S(BoomerangH2I(tr1)), "group", g )
call StoreIntegerBJ( BoomerangH2I(CreateGroup()), I2S(BoomerangH2I(tr2)), "group", g )
call StoreIntegerBJ( 1, I2S(BoomerangH2I(tr1)), "mode", g )
call StoreIntegerBJ( 1, I2S(BoomerangH2I(tr2)), "mode", g )
call StoreStringBJ( I2S(BoomerangH2I(tr2)), I2S(BoomerangH2I(tr1)), "other", g )
call StoreStringBJ( I2S(BoomerangH2I(tr1)), I2S(BoomerangH2I(tr2)), "other", g )
call StoreBoomerangAxePoint(I2S(BoomerangH2I(tr1)),"s",pos)
call StoreBoomerangAxePoint(I2S(BoomerangH2I(tr2)),"s",pos)
call StoreBoomerangAxePoint(I2S(BoomerangH2I(tr1)),"o",l[2])
call StoreBoomerangAxePoint(I2S(BoomerangH2I(tr2)),"o",l[1])
call StoreBoomerangAxePoint(I2S(BoomerangH2I(tr1)),"",l[3])
call StoreBoomerangAxePoint(I2S(BoomerangH2I(tr2)),"",l[4])
call StoreBoomerangAxePoint(I2S(BoomerangH2I(tr1)),"t1",l[9])
call StoreBoomerangAxePoint(I2S(BoomerangH2I(tr2)),"t2",l[11])
call StoreBoomerangAxePoint(I2S(BoomerangH2I(tr1)),"t2",l[10])
call StoreBoomerangAxePoint(I2S(BoomerangH2I(tr2)),"t1",l[12])
call StartTimerBJ( t1, true, 0.03 )
call StartTimerBJ( t2, true, 0.03 )
call RemoveLocation(pos)
loop
exitwhen i > 12
call RemoveLocation(l[i])
set i = i + 1
endloop
call TriggerSleepAction( 0.00 )
call PauseUnitBJ( true, u )
endfunction
Fixed:
function GoldenAxes_Actions takes nothing returns nothing
local unit u = GetSpellAbilityUnit()
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local location l = GetSpellTargetLoc()
local real x2
local real y2
local real a = AngleBetweenCoordinates(x, y, GetLocationX(l), GetLocationY(l))
local real a2
local player p = GetOwningPlayer(u)
local timer t1 = CreateTimer()
local timer t2 = CreateTimer()
local string st1 = I2S(H2I(t1))
local string st2 = I2S(H2I(t2))
local group grp = CreateGroup()
call RemoveLocation(l)
set l = null
call AttachInt(st1, "direction", 1)
call AttachInt(st2, "direction", 0)
call AttachInt(st1, "mode", 1)
call AttachInt(st2, "mode", 1)
call AttachObject(st1, "ounit", u)
call AttachObject(st2, "ounit", u)
call AttachObject(st1, "group", grp)
call AttachObject(st2, "group", grp)
call AttachString(st1, "other", st2)
call AttachString(st2, "other", st1)
call AttachObject(st1, "unit", CreateUnit(p, 'u008', ProjectX(x, 80, a-60), ProjectY(y, 80, a-60), 0))
call AttachObject(st2, "unit", CreateUnit(p, 'u008', ProjectX(x, 80, a+60), ProjectY(y, 80, a+60), 0))
set x2 = ProjectX(x, 400, a-18)
set y2 = ProjectY(y, 400, a-18)
call AttachPoint(st1, "", x2, y2)
set a2 = AngleBetweenCoordinates(x, y, x2, y2) - AngleBetweenCoordinates(x, y, ProjectX(x2, 200, a-90), ProjectY(y2, 200, a-90))
call AttachPoint(st1, "t1", ProjectX(x2, 200, a-90-a2), ProjectY(y2, 200, a-90-a2))
call AttachPoint(st1, "t2", ProjectX(x2, 200, a+90+a2), ProjectY(y2, 200, a+90+a2))
set x2 = ProjectX(x, 400, a+18)
set y2 = ProjectY(y, 400, a+18)
call AttachPoint(st2, "", x2, y2)
call AttachPoint(st2, "t2", ProjectX(x2, 200, a-90-a2), ProjectY(y2, 200, a-90-a2))
call AttachPoint(st2, "t1", ProjectX(x2, 200, a+90+a2), ProjectY(y2, 200, a+90+a2))
call TimerStart(t1, .03, true, function GoldenAxes_Handler)
call TimerStart(t2, .03, true, function GoldenAxes_Handler)
endfunction
You are storing all kinds of data that you don't even need, recalculating a ton of data you could simply derive once and store in a variable, using a bunch of locations for no reason, leaking in several places, etc. You did a great job with the math, but the rest of it is horrible.