Nherwyziant
Be better than you were yesterday :D
- Reaction score
- 96
I got the idea from here. So In my tower, I need to get the nearest unit and my function does not work properly.
Is there something wrong with this?
Is there something wrong with this?
JASS:
//I remove some part of my trigger that does not have something to do with this nearest stuff.
//.r1 will be the X of tower and .r2 is Y of tower
private static method M4 takes nothing returns boolean
local thistype this = thistype.this
local unit u = GetFilterUnit()
local real x = GetUnitX(u)
local real y = GetUnitY(u)
if SquareRoot((x-.r1)*(x-.r1)+(y-.r2)*(y-.r2)) <= .r3 then
set .r3 = SquareRoot((x-.r1)*(x-.r1)+(y-.r2)*(y-.r2))//
set .u2 = u
endif
return false
endmethod
private static method M3 takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
//And is this safe? I will call destroy when the tower is dead, will lag when I have many many towers or cause fatal errors?
if IsUnitType(.u1,UNIT_TYPE_DEAD) == false then
set .r3 = RANGE //700
set thistype.this = this
call GroupEnumUnitsInRange(.g,.r1,.r2,RANGE,Filter(function thistype.M4))
call KillUnit(.u2)//This kill is a test and it does not kill the nearest unit. It kills other units.
else
call .destroy()
endif
endmethod
//I hope you understand. I'm freakin lame at explaining lol.