• 🏆 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!

[Spell] Trigger to find nearest source of walkable land

Status
Not open for further replies.
Level 7
Joined
Mar 16, 2014
Messages
152
I have a unit with a metamorphosis ability that turns them into a flying hero. When they come out of it and become a land unit again, I want to force them onto the nearest walkable land.

I have a system that checks if land is walkable or not I am using, which works fine. This existing trigger will put the unit onto walkable land when asked, but definitely not the closest land. It just finds arbitrary land that is somewhat closeby. Here's my two triggers.

  • Metamorph Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Metamorphosis
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TempInt Equal to 1
        • Then - Actions
          • Set VariableSet TempInt = 0
          • Set VariableSet HeroWithFlyingTransformation = (Triggering unit)
          • Set VariableSet LandingPoint = (Position of HeroWithFlyingTransformation)
          • Set VariableSet LandingDistance = 50.00
          • Set VariableSet LandingDegrees = 0.00
          • Trigger - Run Find land <gen> (ignoring conditions)
        • Else - Actions
          • Set VariableSet TempInt = 1
  • Find land
    • Events
    • Conditions
    • Actions
      • Set VariableSet CP_Point = LandingPoint
      • Trigger - Run Check Walkability <gen> (ignoring conditions)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CP_PointIsWalkable Equal to True
        • Then - Actions
          • Unit - Move HeroWithFlyingTransformation instantly to LandingPoint
          • Custom script: call RemoveLocation( udg_LandingPoint )
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • LandingDegrees Less than or equal to 360.00
            • Then - Actions
              • Set VariableSet LandingPoint = (LandingPoint offset by LandingDistance towards LandingDegrees degrees.)
              • Set VariableSet LandingDegrees = (LandingDegrees + 25.00)
            • Else - Actions
              • Set VariableSet LandingDegrees = 0.00
              • Set VariableSet LandingDistance = (LandingDistance + 50.00)
          • Trigger - Run (This trigger) (ignoring conditions)
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,553
Upon morphing, create an Item at the position of the unit. The item will be repositioned by Warcraft 3's pathing system if it's pathing is blocked. Then move your unit to the position of the item and remove the item from the game.
  • Item - Create item at position of triggering unit
  • Unit - Move unit instantly to position of last created item
  • Item - Remove last created item
If Items don't work then you can use a non-amphibious/non-flying unit instead.

(I didn't test this, but I'm pretty sure it works)
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
The item will be repositioned by Warcraft 3's pathing system if it's pathing is blocked. Then move your unit to the position of the item and remove the item from the game.
This works for small unpathable areas, but I think it might break with larger ones as I recall WC3's displacement algorithm just giving up and placing the object in an inappropriate location if no appropriate locations are reasonably nearby.
 
Status
Not open for further replies.
Top