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

Finding the closest unit of type?

Status
Not open for further replies.
Level 6
Joined
Apr 23, 2009
Messages
94
Ok so heres what i've got.
  • Player1Order Copy
    • Events
      • Player - Player 1 (Red) Selects a unit
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Fortified Wall
    • Actions
      • Unit Group - Add (Triggering unit) to Dig_Group
      • Set Temp_Group_2 = (Units owned by Player 1 (Red) matching ((Unit-type of (Matching unit)) Equal to Dig))
      • Unit Group - Pick every unit in Temp_Group_2 and do (Actions)
        • Loop - Actions
          • Set Temp_Unit_1 = (Picked unit)
          • Set Temp_Loc_1 = (Position of Temp_Unit_1)
          • Set Temp_Real_1 = 999999.00
          • Unit Group - Pick every unit in Dig_Group and do (Actions)
            • Loop - Actions
              • Game - Display to (All players) the text: (String((Number of units in Dig_Group)))
              • Set Temp_Loc_2 = (Position of (Picked unit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between Temp_Loc_1 and Temp_Loc_2) Less than Temp_Real_1
                • Then - Actions
                  • Set Temp_Unit_2 = (Picked unit)
                  • Game - Display to (All players) the text: (String((Unit-type of Temp_Unit_2)))
                  • Set Temp_Real_1 = (Distance between Temp_Loc_1 and Temp_Loc_2)
                • Else - Actions
              • Custom script: call RemoveLocation(udg_Temp_Loc_2)
          • Set Dig_Position = (Position of Temp_Unit_2)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between Temp_Loc_2 and Dig_Position) Greater than 10.00
            • Then - Actions
              • Unit - Create 1 Dig for Player 1 (Red) at Dig_Position facing Default building facing degrees
            • Else - Actions
              • Unit - Remove Temp_Unit_1 from the game
          • Custom script: call DestroyGroup(udg_Dig_Group)
          • Custom script: call RemoveLocation(udg_Temp_Loc_1)
          • Custom script: call RemoveLocation(udg_Dig_Position)
          • Custom script: call DestroyGroup(udg_Temp_Group_2)
What i'm looking to do is; Make a sort-of target selection thing, where you select "Fortified Wall" and it makes a "Dig" unit appear at that exact spot(Dig unit being a dummy unit with a Ability animation for a model). Kind of like, you're choosing targets to attack.
This was easy, the hard part is, I need to make it so you can cancel any selection by re-clicking on the selected target, removing that "Dig" unit from the game.

So I need to find the closest "Dig" unit, and if he isn't like 10 in Warcraft distance, then it creates a new "Dig" unit on the slected target, and if he is within the 10 mark, then it removes him.

I hope that was understandable.
 
I don't fully understand your problem, but, I kinda got the concept.
So, you want a Hashtable for that. Once you select the unit, check if that unit is in a group; a unit group that is stored to the player who selects it:
  • Trigger
  • Events
    • Map Initialization
  • Conditions
  • Actions
    • Hashtable - Create a hashtable
    • Set Hashtable = (Last created hashtable)
    • For each (IntegerA) from 1 to 12, do (Actions) //This supports many players at the same time
      • Loop - Actions
        • Hashtable - Save DigGroup as (Key(group)) of (Key(Player(IntegerA))) in Hashtable
        • Trigger - Add to Trigger2 <gen> the event (Player - Player(IntegerA) selects a unit)
  • Trigger2
  • Events
  • Conditions
  • Actions
    • Set TempGroupLoad = (Load (Key(group)) of (Key(Triggering player)) from Hashtable)
    • If (All conditions are true) then do (Actions) else do (Actions)
      • If - Conditions
        • ((Triggering unit) is in TempGroupLoad) Equal to False
      • Then - Actions
        • If (All conditions are true) then do (Actions) else do (Actions)
          • If - Conditions
            • (Unit-type of (Triggering unit)) Equal to Fortified Wall
          • Then - Actions
            • Unit Group - Add (Triggering unit) to TempGroupLoad
            • //Do the actions of GetClosestUnit() here.
          • Else - Actions
      • Else - Actions
        • Unit Group - Remove (Triggering unit) from TempGroupLoad
        • Unit - Kill (Triggering unit)
        • Unit - Remove (Triggering unit) from the game
TempGroupLoad & DigGroup are Unit Group variables.

In case this is not what you need, let me know, but be more clear.


To be more specific, the trigger I gave you removes the unit from the game once selected twice. It gives actually the concept of how to detect that (you can also use increasing integers, which, once they get to value 2, the unit will be removed, but you can also use the one I explained above).
The thing is your thread's title doesn't really respond to what you are asking, unless I really misunderstood you, so I do need a better explanation of the problem.
 
Level 6
Joined
Apr 23, 2009
Messages
94
Ok sorry, I was a really hard thing to describe. And for some reason I have a funny way of not being able to figure my own problem out until I post it on here..
Anywho, I've got it down:
  • Untitled Trigger 002
    • Events
      • Player - Player 1 (Red) Selects a unit
    • Conditions
      • ((Unit-type of (Triggering unit)) Equal to Fortified Wall) or ((Unit-type of (Triggering unit)) Equal to Rock)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is in Dig_Group) Equal to True
        • Then - Actions
          • Set P1SelectGroup = (Units of type Dig)
          • Set loc1 = (Position of (Triggering unit))
          • Unit Group - Pick every unit in P1SelectGroup and do (Actions)
            • Loop - Actions
              • Set loc2 = (Position of (Picked unit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between loc1 and loc2) Less than 10.00
                • Then - Actions
                  • Unit - Remove (Picked unit) from the game
                • Else - Actions
              • Custom script: call RemoveLocation(udg_loc2)
          • Custom script: call RemoveLocation(udg_loc1)
          • Custom script: call DestroyGroup(udg_P1SelectGroup)
          • Unit Group - Remove (Triggering unit) from Dig_Group
        • Else - Actions
          • Unit - Create 1 Dig for Player 1 (Red) at (Position of (Triggering unit)) facing Default building facing degrees
          • Unit Group - Add (Triggering unit) to Dig_Group
  • Untitled Trigger 004
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Dying unit) is in Dig_Group) Equal to True
        • Then - Actions
          • Set P1SelectGroup = (Units of type Dig)
          • Set loc1 = (Position of (Dying unit))
          • Unit Group - Pick every unit in P1SelectGroup and do (Actions)
            • Loop - Actions
              • Set loc2 = (Position of (Picked unit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between loc1 and loc2) Less than 10.00
                • Then - Actions
                  • Unit - Remove (Picked unit) from the game
                • Else - Actions
              • Custom script: call RemoveLocation(udg_loc2)
          • Unit Group - Remove (Dying unit) from Dig_Group
          • Custom script: call RemoveLocation(udg_loc1)
          • Custom script: call DestroyGroup(udg_P1SelectGroup)
        • Else - Actions
Thank you for the help.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Maybe like this. You select a unit, another one is created. You select the unit again, the created unit dies. And so on.


  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Dig_Hash = (Last created hashtable)
  • System
    • Events
      • Player - Player 1 (Red) Selects a unit
      • Player - Player 2 (Blue) Selects a unit
      • Player - Player 3 (Teal) Selects a unit
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Paladin
          • (Unit-type of (Triggering unit)) Equal to Blood Mage
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Key digger) is stored as a Handle of (Key (Triggering unit)) in Dig_Hash) Equal to True
        • Then - Actions
          • Unit - Kill (Load (Key digger) of (Key (Triggering unit)) in Dig_Hash)
          • Hashtable - Clear all child hashtables of child (Key (Triggering unit)) in Dig_Hash
        • Else - Actions
          • Set Temp_Loc_1 = (Position of (Triggering Unit))
          • Unit - Create 1 Peasant for (Triggering player) at Temp_Loc_1 facing Default building facing degrees
          • Hashtable - Save Handle Of(Last created unit) as (Key digger) of (Key (Triggering unit)) in Dig_Hash
          • Custom script: call RemoveLocation(udg_Temp_Loc_1)
 

Attachments

  • Bind_Units.w3x
    17.2 KB · Views: 46
Status
Not open for further replies.
Top