Warcraft III resources & community, 2003–2006 · archived

UnitGuardUnitAI

not rated
Submitted by AltSubmitterAI0 downloads
This function causes the "summon" unit to guard the "master" unit Diablo2 style, the function continues to run until the summon dies, if the master dies the summon will camp his grave.

It is suggested to add the 'Aloc' ability to units that will be controlled by this function.
Suggested usage:
Guard
Events
Unit - A unit Spawns a summoned unit
Conditions
(Unit-type of (Summoned unit)) Equal to Phoenix
Actions
Custom script: call UnitGuardUnitAI(GetSummonedUnit(),GetSummoningUnit())


NOTE: If the the master dies, the unit will be ordered toward the center of the map. If you don't want this behavior in your map, change the exitwhen line to:

exitwhen IsUnitDeadBJ(summon) or IsUnitDeadBJ(master)

Source

function UnitGuardUnitAI takes unit summon, unit master returns nothing
    local location target
    local real angle
    local real dist
  
    loop
    exitwhen IsUnitDeadBJ(summon)
    if (DistanceBetweenPoints(GetUnitLoc(summon), GetUnitLoc(master)) > 1000.00 ) then
        set target = GetUnitLoc(master)
        call IssuePointOrderLocBJ(summon, "move", target) 
        call RemoveLocation(target)
    else
        set target = GetUnitLoc(master)
        set angle =  GetRandomDirectionDeg()
        set dist = GetRandomReal(100.00, 500.00)
        call MoveLocation(target, GetLocationX(target) + dist * Cos(angle * bj_DEGTORAD), GetLocationY(target) + dist * Sin(angle * bj_DEGTORAD))
        call IssuePointOrderLocBJ(summon, "attack", target)
        call RemoveLocation(target)
    endif
    call TriggerSleepAction( 1.0+GetRandomReal(0.0,1.5))
    endloop
    set target = null
endfunction

Comments

0

No comments.