- Joined
- Jul 31, 2012
- Messages
- 2,217
Like the title says; how can i get the closest structures from a point?
PS: if possible specify the owner of the structure in wich [player 1]
PS: if possible specify the owner of the structure in wich [player 1]
Get closest structure to point
What really it is? Detect the closest structure from a point?Like the title says; how can i get the closest structures from a point?
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.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.
You cannot declare local variables anywhere EXCEPT at the beginning of a function.
Move this line:
Game - Display to (All players) the text: debug msg
below all the local declarations.
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?Hammerfist's method is preferable.
Any conditions (like "Player 1 only") go inside the only ITE there is.
- 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 --------
It doesn't have to start with the closest matching unit, just any random unit in range.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?
I see, makes sense. Thanks for explaining.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).