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

[Solved] Get closest structure to point

Status
Not open for further replies.
Man I cannot give u triggers, I can only say how to do it and it works for me.
First set ur point from what u want to pick unit. Next pick every unit in for excample 700 range mathing unit is building and owner of mathching unit is player 1. Next what u should do is to pick that units. Set some variable to picked units. DO THIS (dont ask why) set one real variable to 1000000. Next what u should do is to create another real variable. Set value of that real to distance beetwin ur point and point of picked unit. Okey next step is not make if then else. Condition should go like this. If real (distance of point and building is lesser than (variable with value of 100000) then do set variable 1000000 equal to variable distance
and set building unit variable to picked unit. U are done, maye something of this sound confusil, but read it step by step and it will work. If u do not understand something just say. And will explain
 

Wrda

Spell Reviewer
Level 26
Joined
Nov 18, 2012
Messages
1,891
  • The point
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Point1 = (Center of Region 000 <gen>)
  • Get the closest building from a point
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • BuildingFound Equal to False
        • Then - Actions
          • Set Distance = (Distance + 5.00)
          • Set Point2 = (Point1 offset by Distance towards 0.00 degrees)
          • Set Group = (Units within (Distance between Point1 and Point2) of Point1 matching (((Matching unit) is A structure) Equal to True))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Group is empty) Equal to False
            • Then - Actions
              • Set BuildingFound = True
              • Unit Group - Pick every unit in Group and do (Actions)
                • Loop - Actions
                  • Set AntiBugInt = (AntiBugInt + 1)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • AntiBugInt Equal to 1
                    • Then - Actions
                      • Set BuildingLoc = (Position of (Picked unit))
                      • Cinematic - Ping minimap for (All players) at BuildingLoc for 5.00 seconds
                      • Game - Display to (All players) the text: Building found.
                      • Custom script: call RemoveLocation(udg_Point1)
                      • Custom script: call RemoveLocation(udg_Point2)
                      • Custom script: call RemoveLocation(udg_BuildingLoc)
                      • Custom script: call DestroyGroup(udg_Group)
                      • Set Distance = 0.00
                      • Trigger - Turn off (This trigger)
                    • Else - Actions
              • Set AntiBugInt = 0
            • Else - Actions
        • Else - Actions
This works.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Wrda: that could loop way too many times. Also, Point2 seems obsolete and leaks.

Hammerfist's method is preferable.
  • Actions
    • Set TempLoc1 = (Player 1 (Red) start location)
    • Set TempReal1 = 10000.00
    • Custom script: set bj_wantDestroyGroup = true
    • Unit Group - Pick every unit in (Units within 2000.00 of TempLoc1) and do (Actions)
      • Loop - Actions
        • Set TempLoc2 = (Position of (Picked unit))
        • Set TempReal2 = (Distance between TempLoc1 and TempLoc2)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • ((Picked unit) is A structure) Equal to True
            • TempReal2 Less than TempReal1
          • Then - Actions
            • Set TempUnit1 = (Picked unit)
            • Set TempReal1 = TempReal2
          • Else - Actions
        • Custom script: call RemoveLocation(udg_TempLoc2)
    • Custom script: call RemoveLocation(udg_TempLoc1)
    • -------- Closest structure to TempLoc1 = TempUnit1 --------
Any conditions (like "Player 1 only") go inside the only ITE there is.
 
Level 16
Joined
Jul 31, 2012
Messages
2,217
HAmmerfist's trigger works perfectly but one last question
  • Boots of Travel Teleport
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Boots of Travel Teleport
      • Or - Any (Conditions) are true
        • Conditions
          • (Owner of (Triggering unit)) Equal to Player 2 (Blue)
          • (Owner of (Triggering unit)) Equal to Player 3 (Teal)
          • (Owner of (Triggering unit)) Equal to Player 4 (Purple)
          • (Owner of (Triggering unit)) Equal to Player 5 (Yellow)
          • (Owner of (Triggering unit)) Equal to Player 6 (Orange)
    • Actions
      • Game - Display to (All players) the text: debug msg
      • Custom script: local location udg_temp_location
      • Custom script: local location udg_temp_location1
      • Custom script: local real udg_y
      • Custom script: local real udg_y_y
      • Custom script: local real udg_yy
      • Custom script: local unit udg_temp_Unit
      • Custom script: local unit udg_temp_Unit1
      • Custom script: local effect udg_temp_Effect
      • Custom script: local effect udg_temp_Effect1
      • Set temp_location = (Target point of ability being cast)
      • Set temp_location2 = (Position of (Triggering unit))
      • Set temp_Unit1 = (Triggering unit)
      • Set y = 10000.00
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units within 1500.00 of temp_location matching ((((Matching unit) is A structure) Equal to True) and ((Owner of (Matching unit)) Equal to Player 1 (Red)))) and do (Actions)
        • Loop - Actions
          • Set temp_location1 = (Position of (Picked unit))
          • Set y_y = (Distance between temp_location and temp_location1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • y_y Less than y
            • Then - Actions
              • Set temp_Unit = (Picked unit)
              • Set y = y_y
            • Else - Actions
          • Custom script: call RemoveLocation(udg_temp_location1)
      • Custom script: call RemoveLocation(udg_temp_location)
      • Special Effect - Create a special effect attached to the origin of temp_Unit using Abilities\Spells\Human\MassTeleport\MassTeleportTo.mdl
      • Special Effect - Create a special effect attached to the origin of temp_Unit1 using Abilities\Spells\Human\MassTeleport\MassTeleportTo.mdl
      • Set yy = ((Distance between temp_location2 and (Position of temp_Unit)) / 2400.00)
      • Wait yy seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Current order of temp_Unit1) Equal to (Order(charm))
        • Then - Actions
          • Unit - Move temp_Unit1 instantly to (Position of temp_Unit)
          • Special Effect - Destroy temp_Effect
          • Special Effect - Destroy temp_Effect1
          • Special Effect - Create a special effect attached to the origin of temp_Unit using Abilities\Spells\Human\MassTeleport\MassTeleportTarget.mdl
          • Special Effect - Create a special effect attached to the origin of temp_Unit1 using Abilities\Spells\Human\MassTeleport\MassTeleportTarget.mdl
        • Else - Actions
the locals in this triggers don't work can anyonr tell me why :ogre_rage:
 
Well I am totaly begginer in local variables, but I think (dont know), local variables dont use ''udg'', that is for global variables so that is needless, also local variables need to be used with custom scripts. And why u use tham at all, currently they are not that necesery here, u could just use few temp global variables thats all.
 
Level 16
Joined
Jul 31, 2012
Messages
2,217
Well I am totaly begginer in local variables, but I think (dont know), local variables dont use ''udg'', that is for global variables so that is needless, also local variables need to be used with custom scripts. And why u use tham at all, currently they are not that necesery here, u could just use few temp global variables thats all.

The effects and units are needed cuz there are 10 players in my map and the spell is for an item

EDIT: now the locals are working thx all
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Well I am totaly begginer in local variables, but I think (dont know), local variables dont use ''udg'', that is for global variables so that is needless, also local variables need to be used with custom scripts. And why u use tham at all, currently they are not that necesery here, u could just use few temp global variables thats all.
Local variables can use "udg_", it's a trick used in GUI to turn global variables into local ones (so you can use the variables in GUI, yet they're still local variables). There's no problem with that.
But yeah, it's redundant in this case.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Use "udg_" if you wish to 'convert a global variable to a local one', don't use it if you don't want that.
If you don't use "udg_", it won't work with GUI.
In your case, you actually do need "udg_" in front of the variables, because otherwise the GUI-version won't work (only for variables used after the wait, not for the others... remove the local custom script shit for those).
 
Level 25
Joined
Sep 26, 2009
Messages
2,381
Hammerfist's method is preferable.
  • Actions
    • Set TempLoc1 = (Player 1 (Red) start location)
    • Set TempReal1 = 10000.00
    • Custom script: set bj_wantDestroyGroup = true
    • Unit Group - Pick every unit in (Units within 2000.00 of TempLoc1) and do (Actions)
      • Loop - Actions
        • Set TempLoc2 = (Position of (Picked unit))
        • Set TempReal2 = (Distance between TempLoc1 and TempLoc2)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • ((Picked unit) is A structure) Equal to True
            • TempReal2 Less than TempReal1
          • Then - Actions
            • Set TempUnit1 = (Picked unit)
            • Set TempReal1 = TempReal2
          • Else - Actions
        • Custom script: call RemoveLocation(udg_TempLoc2)
    • Custom script: call RemoveLocation(udg_TempLoc1)
    • -------- Closest structure to TempLoc1 = TempUnit1 --------
Any conditions (like "Player 1 only") go inside the only ITE there is.
So if I understood it correctly, then when you "pick every unit in ..." action, the trigger starts always with the closest matching unit? Hence why you set TempReal1 as TempReal2 (= the shortest distance) at the end of the loop?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
So if I understood it correctly, then when you "pick every unit in ..." action, the trigger starts always with the closest matching unit? Hence why you set TempReal1 as TempReal2 (= the shortest distance) at the end of the loop?
It doesn't have to start with the closest matching unit, just any random unit in range.
TempReal1 is the shortest distance, while TempReal2 is the distance between the currently picked unit and the location.
So if TempReal2 (the current distance) is smaller than the shortest distance, then we have found a unit that is even closer to the location (thus you can set TempReal1 to the current distance, which is the shortest, and TempUnit1 to the selected unit).
 
Level 25
Joined
Sep 26, 2009
Messages
2,381
It doesn't have to start with the closest matching unit, just any random unit in range.
TempReal1 is the shortest distance, while TempReal2 is the distance between the currently picked unit and the location.
So if TempReal2 (the current distance) is smaller than the shortest distance, then we have found a unit that is even closer to the location (thus you can set TempReal1 to the current distance, which is the shortest, and TempUnit1 to the selected unit).
I see, makes sense. Thanks for explaining.
 
Status
Not open for further replies.
Top