Warcraft III resources & community, 2003–2006 · archived

UnitCircleUnit

not rated
Submitted by AltSubmitterFunctions0 downloads
This function lets you have a unit move in a circle around another unit. It requires the Handle Var API that is also available here at the vault. I haven't tested speeds higher than 100 -- I'm not sure they will be stable. You could use this for all sorts of nifty effects, a flame shield ala WarCraft2 for instance (as Battledome will do).

Also, this stores a boolean on the unit called "stopCircling." Setting this to true will cause the unit to stop. You can also change the unit boolean "clockwise" while the unit is rotating and it will switch directions.

Source

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

Comments

1
I am having trouble using this script, could some1 help me, i have the H2I and H2U and the API function thing, but it gives me many, many errors... (23 to be exact) all of them are the kind that are like:

    Line xxx: Expected a name
    Line xxx: Expected expression
    Line xxx: Expected a code statement
    Line xxx: Expected a function name

:? I need help... (and not mental help)