function UnitCircleUnit_Child takes nothing returns nothing
local timer this = GetExpiredTimer()
local unit whichUnit = H2U(GetHandleHandle(this, "whichUnit"))
local unit focusUnit = H2U(GetHandleHandle(this, "focusUnit"))
local location where = GetUnitLoc(focusUnit)
local real radius = GetHandleReal(this, "radius")
local real currentAngle = GetHandleReal(this, "currentAngle")
local boolean clockwise = GetHandleBoolean(whichUnit, "clockwise")
local location tempLoc = null
local boolean stopCircling = GetHandleBoolean(whichUnit, "stopCircling")
if(stopCircling) then
call PauseTimer(this)
call FlushHandleVars(this)
call DestroyTimer(this)
call RemoveLocation(where)
return
endif
if(clockwise) then
set currentAngle = currentAngle - 1
else
set currentAngle = currentAngle + 1
endif
set tempLoc = PolarProjectionBJ(where, radius, currentAngle)
call SetUnitPositionLoc(whichUnit, tempLoc)
call RemoveLocation(tempLoc)
call RemoveLocation(where)
call SetHandleReal(this, "currentAngle", currentAngle)
endfunction
//Make a stop function that changes a gamecache value
//Store clockwise boolean on unit so direction can be reversed
function UnitCircleUnit takes unit whichUnit, unit focusUnit, real radius, real speed, boolean clockwise returns nothing
local timer t = CreateTimer()
call SetHandleHandle(t, "whichUnit", whichUnit)
call SetHandleHandle(t, "focusUnit", focusUnit)
call SetHandleReal(t, "radius", radius)
call SetHandleReal(t, "currentAngle", GetRandomReal(0,360))
call SetHandleBoolean(whichUnit, "clockwise", clockwise)
call SetHandleBoolean(whichUnit, "stopCircling", false)
call TimerStart(t, 1/speed, true, function UnitCircleUnit_Child)
endfunction