- Joined
- May 12, 2018
- Messages
- 122
I want to amplify the taking damage of Target Unit As it stands far from Spirit Tower.
I learned that the computation speed of the Locations are slow, so I tried to solve this with x/y coordinate values, but I'm not sure about the exact calculation formula.
here's my test code.
I wrote create and kill unit for checking distances but this is not working.
I learned that the computation speed of the Locations are slow, so I tried to solve this with x/y coordinate values, but I'm not sure about the exact calculation formula.
here's my test code.
JASS:
scope UAScourgeBaseDefensiveA initializer init
private function Act takes nothing returns nothing
local unit source = udg_DamageEventSource
local unit target = udg_DamageEventTarget
local unit locust
local real x0 = GetUnitX(source)
local real y0 = GetUnitY(source)
local real x1 = GetUnitX(target)
local real y1 = GetUnitY(target)
local real angle = Atan2(y1 - y0, x1 - x0)
local real xOffset = x0 + (x1 - x0) * Cos(angle)
local real yOffset = y0 + (y1 - y0) * Sin(angle)
local real dx = xOffset - x0
local real dy = yOffset - y0
local real tx = 0
local real ty = 0
set tx = x0 + dx
set ty = y0 + dy
if tx >= 100 and tx < 200 then
set locust = CreateUnit(Player(0), 'hfoo', x1,y1,1)
elseif ty >= 100 and ty < 200 then
set locust = CreateUnit(Player(0), 'hfoo', x1,y1,1)
elseif tx >= 200 and tx < 300 then
set locust = CreateUnit(Player(0), 'hrfl', x1,y1,1)
elseif ty >= 200 and ty < 300 then
set locust = CreateUnit(Player(0), 'hrfl', x1,y1,1)
endif
call KillUnit(locust)
set locust = null
set source = null
set target = null
endfunction
private function Cond takes nothing returns boolean
return GetUnitTypeId(udg_DamageEventSource) == 'uzg1' and GetPlayerTechCount(GetOwningPlayer(udg_DamageEventSource), T_SCOURGEBASE_DEFENSIVE_A, true) > 0 and not IsUnitIllusion(udg_DamageEventSource)
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterVariableEvent( t, "udg_PreDamageEvent", LESS_THAN, 0 )
call TriggerAddCondition( t, Condition( function Cond ) )
call TriggerAddAction( t, function Act )
set t = null
endfunction
endscope