- Joined
- Aug 21, 2008
- Messages
- 533
After finishing the first part of my spell i tried the second part. altought it works it profuce heavy lagg and isnt really working...
JASS:
function DeadFilter takes nothing returns boolean
return GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) < 0.5
endfunction
function GetClosestUnit takes unit u2, boolexpr e returns unit
local real md = 200
local group g = CreateGroup()
local unit u
local real d
local location l = GetUnitLoc(u2)
local location l2
local unit u3
call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, e)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if (GetOwningPlayer(u)==GetOwningPlayer(u)) then
else
set l2 = GetUnitLoc(u2)
set d= DistanceBetweenPoints(l,l2)
call RemoveLocation(l)
call RemoveLocation(l2)
if d > 0 then
if d < md then
set md = d
set u = u3
endif
endif
endif
endloop
call DestroyGroup(g)
call DestroyBoolExpr(e)
set g = null
set u = null
set u2 = null
set l = null
set l2 = null
return u3
endfunction
function Fly takes nothing returns nothing
local real r
local real an
local real sp
local unit u = GetEnumUnit()
local real da = LoadReal( udg_hashTable, GetHandleId(u), StringHash("damage"))
local unit u2
local location l
local location l2
local boolexpr f = Condition(function DeadFilter)
set r = LoadRealBJ(StringHash("time"), GetHandleId(u), udg_hashTable )
if (r>0.00) then
set r = r-0.03
call SaveRealBJ(r,StringHash("time"), GetHandleId(u), udg_hashTable )
set an = LoadRealBJ(StringHash("missleangle"), GetHandleId(u), udg_hashTable )
set sp = LoadRealBJ(StringHash("misslespeed"), StringHash(GetUnitName(u)), udg_hashTable)/33
set l = GetUnitLoc(u)
set l = PolarProjectionBJ(l, sp, an)
call SetUnitPositionLoc(u,l)
set u2 = GetClosestUnit(u,f)
call RemoveLocation(l)
call RemoveLocation(l2)
set l = GetUnitLoc(u)
set l2 = GetUnitLoc(u2)
if (DistanceBetweenPoints(l,l2)<50) then
call GroupRemoveUnit(udg_misslegroup,u)
call UnitDamageTargetBJ( u, u2, da*100, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL )
call KillUnit(u)
endif
call RemoveLocation(l)
call RemoveLocation(l2)
else
call GroupRemoveUnit(udg_misslegroup,u)
call KillUnit(u)
endif
set u = null
set l = null
set l2 = null
set u2=null
endfunction
function Trig_Fly_Actions takes nothing returns nothing
call ForGroup(udg_misslegroup, function Fly )
endfunction
//===========================================================================
function InitTrig_Fly takes nothing returns nothing
set gg_trg_Fly = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_Fly, 0.03 )
call TriggerAddAction( gg_trg_Fly, function Trig_Fly_Actions )
endfunction