Distance Between Destructible and Unit

Status
Not open for further replies.
I will write something up quick...
How are the destructables picked? In a region?

EDIT: Here is a vJASS system I wrote up. It checks each destructable in the specified rect (region in GUI). The system code:

JASS:
library DestructableEnum                // by Mr_Bean

    globals
        private destructable closest    // Stores current closest destructable.
        private real distance           // Stores distance of current closest destructable.
        private real unitX              // Stores x co-ordinate of checked unit.
        private real unitY              // Stores y co-ordinate of checked unit.
    endglobals

    private function ClosestDestrEnum takes nothing returns nothing
        local destructable d = GetEnumDestructable()
        local real dx
        local real dy
        local real dist
        
        if (GetWidgetLife(d) > 0.405) then
        
            set dx = GetDestructableX(d) - unitX
            set dy = GetDestructableY(d) - unitY
            set dist = SquareRoot((dx * dx) + (dy * dy))
        
            if (dist < distance) then
                set closest = d
                set distance = dist
            endif
            
        endif
        
        set d = null
    endfunction
    
    function GetClosestDestructable takes unit whichUnit, rect whichRect returns destructable
        set distance = 999999.0
        set closest = null
        set unitX = GetUnitX(whichUnit)
        set unitY = GetUnitY(whichUnit)
        call EnumDestructablesInRect(whichRect, null, function ClosestDestrEnum)
        
        return closest
    endfunction

endlibrary
And example usage:

  • Test Trig
    • Events
      • Player - Player 1 (Red) types a chat message containing -closest as An exact match
    • Conditions
    • Actions
      • Custom script: call BJDebugMsg(GetDestructableName(GetClosestDestructable(udg_hero, bj_mapInitialPlayableArea)))
This prints the name of the closest destructable on the map to the unit stored in the hero variable.
 
Last edited:
Status
Not open for further replies.
Back
Top