• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Get closest tree

Status
Not open for further replies.
Essentially, I want a certain type of unit to turn invisible when standing still close to a tree.

I have this:
[Snippet] GetClosestWidget

And I have Bribe's IsUnitMoving system.

So how does i make the linked jass return the distance to the closest tree? Or if there is a tree within 256 (arbitrary number) distance?

Thanks in advance
 
Level 39
Joined
Feb 27, 2007
Messages
5,016
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