library ArrowSystem //By maddeem
globals
private integer ID = 'B000' // Arrow Destructable ID
private real Timeout = 0.03125 //How often the timers fire
private real DestroyDistance = 200 //The distance from the target at which the arrow is destroyed
private hashtable h = InitHashtable( )
endglobals
function DestroyArrow takes unit u1 returns nothing //This function will destroy any arrow on any unit at any time
local integer i = GetHandleId( u1 )
local timer t = LoadTimerHandle( h, i, 0 )
local integer ii = GetHandleId( t )
call DestroyTimer( t )
call RemoveDestructable( LoadDestructableHandle( h, ii, 4 ) )
call FlushChildHashtable( h, i )
call FlushChildHashtable( h, ii )
set t = null
endfunction
private function SetArrowU2U takes nothing returns nothing
local timer t = GetExpiredTimer( )
local integer i = GetHandleId( t )
local unit u1 = LoadUnitHandle( h, i, 0 )
local unit u2 = LoadUnitHandle( h, i, 1 )
local real x1 = GetUnitX( u1 )
local real x2 = GetUnitX( u2 )
local real y1 = GetUnitY( u1 )
local real y2 = GetUnitY( u2 )
local real dx = x1 - x2
local real dy = y1 - y2
local real si = LoadReal( h, i, 2 )
local real he = LoadReal( h, i, 3 )
local location l = Location( x1, y1 )
local destructable d
call RemoveDestructable( LoadDestructableHandle( h, i, 4 ) )
if SquareRoot( dx * dx + dy * dy ) < DestroyDistance then
call DestroyTimer( t )
call FlushChildHashtable( h, i )
call FlushChildHashtable( h, GetHandleId( u1 ) )
else
set d = CreateDestructableZ( ID, x1, y1, he + GetUnitFlyHeight( u1 ) + GetLocationZ( l ), 90 + bj_RADTODEG * Atan2( y2 - y1, x2 - x1 ), si, 0 )
call SaveDestructableHandle( h, i, 4, d )
if IsUnitOwnedByPlayer( u1, GetLocalPlayer( ) ) then
call ShowDestructable( d, true )
else
call ShowDestructable( d, false )
endif
endif
call RemoveLocation( l )
set l = null
set u1 = null
set u2 = null
set t = null
set d = null
endfunction
function ArrowUnit2Unit takes unit u1, unit u2, real size, real height returns nothing //Main function of the system
local timer t = CreateTimer( )
local integer i = GetHandleId( t )
call TimerStart( t, Timeout, true, function SetArrowU2U )
call SaveUnitHandle( h, i, 0, u1 )
call SaveUnitHandle( h, i, 1, u2 )
call SaveReal( h, i, 2, size )
call SaveReal( h, i, 3, height )
call SaveTimerHandle( h, GetHandleId( u1 ), 0, t )
set t = null
endfunction
endlibrary
//Code indented using The_Witcher's Script language Aligner
//Download the newest version and report bugs at www.hiveworkshop.com