• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Get closest tree

Status
Not open for further replies.
Level 45
Joined
Feb 27, 2007
Messages
5,578
You need to give it a filterfunction, which you can put in your custom script section to easily use:
JASS:
function YourTreeFilter takes nothing returns boolean
    return GetDestructableTypeId(GetEnumDestructable()) == 'RAWC' //where RAWC is the rawcode of the trees in your map
endfunction

//or this if multiple tree types:
function YourTreeFilter takes nothing returns boolean
    local integer d = GetDestructableTypeId(GetEnumDestructable())
    return d == 'RAWC' or d == 'raw2' or ...
endfunction

//call it like this
set udg_DESTRUCTIBLE_VAR = GetClosestDestructable(GetUnitX(udg_UNIT_VAR), GetUnitY(udg_UNIT_VAR), Filter(function YourTreeFilter))
//then check if it's == no destructible or not
Honestly though you don't actually need the closest, you just need to know if there are any within a small radius, which is a much less computationally taxing problem to solve. You can even do it with GUI:
  • Set TempPoint = (Position of UNIT_VAR)
  • Set COUNT = 0
  • Destructible - Pick every destructible within 256.00 of TempPoint and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Destructible-type of (Picked destructible)) Equal to YOUR_TREE_TYPE
        • Then - Actions
          • Set COUNT = (COUNT + 1)
        • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • COUNT greater than 0
      • Then - Actions
        • -------- it was near a tree, check IsUnitMoving here --------
      • Else - Actions
 
Status
Not open for further replies.
Top