• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Condition to check if units are in the same group?

Status
Not open for further replies.
Level 11
Joined
Oct 9, 2015
Messages
721
is there a condition to check if units are in the same group?

example: a unit comes whithin (acquisition range) of another unit -> if units are in the same group order unit 1 to follow unit 2. else -> if units is not in the same group order unit 1 to attack unit 2 and unit 2 to attack unit 1
 
Level 15
Joined
Mar 25, 2016
Messages
1,327
You can check if a unit is in a unit group. If both of them are in unit group A, both are in the same group. Is this what you meant?
 
Level 15
Joined
Mar 25, 2016
Messages
1,327
since a unit can be in multiple unit group there is no "unit group of unit". You would need to check for every unit group you are using. But if in your case every unit is only in one group, you could store for each unit the number of the group it is in.
 
Level 11
Joined
Oct 9, 2015
Messages
721
something like a integer with custom value of unit array?

Integer[Custom value of unit] = 1 (this means it's in group 1)

If Integer[Custom value of unit] not equal to Integer[Custom value of unit2] then order unit 1 to attack unit 2 and unit 2 to attack unit 1
 
Level 15
Joined
Mar 25, 2016
Messages
1,327
The custom value must be unique for every unit (then you can store a value for each unit). The unit-indexer gives each unit a unique custom value.
 
Level 11
Joined
Oct 9, 2015
Messages
721
All right, I've implemented the unit indexer and now custom value works fine.
At the moment I have the following triggers working properly:
In this case we have 3 groups and 2 factions: Group 1 belong to Faction 1 while Group 2 and Group 3 belongs to Faction2. My aim is to make different unit groups interact between them as enemies and allies so we won't have to use a player slot for every faction we want to have in our maps. For example my map has 5 cities, if I needed to use every city as an individual faction we would need to use 5 player slots.

  • Faction Debug New
    • Events
      • Time - Every 0.33 seconds of game time
    • Conditions
    • Actions
      • -------- ADDING UNITS TO GROUPS --------
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • -------- SETTING UNIT GROUP --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Grouped[(Custom value of (Picked unit))] Equal to False
              • (Owner of (Picked unit)) Equal to Neutral Passive
            • Then - Actions
              • Set Grouped[(Custom value of (Picked unit))] = True
              • Unit Group - Pick every unit in (Units in Region 000 <gen>) and do (Actions)
                • Loop - Actions
                  • -------- SETTING GROUP NUMBER --------
                  • Set GroupInteger[(Custom value of (Picked unit))] = 1
                  • -------- -------------------------- --------
                  • -------- ADDING UNIT TO FACTION --------
                  • Unit Group - Add (Picked unit) to Faction1
                  • -------- -------------------------- --------
              • Unit Group - Pick every unit in (Units in Region 001 <gen>) and do (Actions)
                • Loop - Actions
                  • -------- SETTING GROUP NUMBER --------
                  • Unit - Change color of (Picked unit) to Blue
                  • Set GroupInteger[(Custom value of (Picked unit))] = 2
                  • -------- -------------------------- --------
                  • -------- ADDING UNIT TO FACTION --------
                  • Unit Group - Add (Picked unit) to Faction2
                  • -------- -------------------------- --------
              • Unit Group - Pick every unit in (Units in Region 002 <gen>) and do (Actions)
                • Loop - Actions
                  • -------- SETTING GROUP NUMBER --------
                  • Unit - Change color of (Picked unit) to Teal
                  • Set GroupInteger[(Custom value of (Picked unit))] = 3
                  • -------- -------------------------- --------
                  • -------- ADDING UNIT TO FACTION --------
                  • Unit Group - Add (Picked unit) to Faction2
                  • -------- -------------------------- --------
              • -------- ADD THE EVENT UNIT COMES WHITHIN ACQUISITION RANGE OF PICKED UNIT --------
              • Trigger - Add to Faction Actions New <gen> the event (Unit - A unit comes within (Current acquisition range of (Picked unit)) of (Picked unit))
            • Else - Actions
      • -------- -------------------------- --------
      • -------- TARGETING AND ATTACKING --------
      • -------- FACTION 1 --------
      • Unit Group - Pick every unit in Faction1 and do (Actions)
        • Loop - Actions
          • Set Unit1 = (Picked unit)
          • Set Loc1 = (Position of (Picked unit))
          • -------- HERE WE CHECK IF THE UNIT IS STOPPED AND HAS ENEMIES WHITHIN ACQUISITION RANGE --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • IsEngaged[(Custom value of Unit1)] Equal to False
              • (Current order of Unit1) Not equal to (Order(smart))
              • (Current order of Unit1) Not equal to (Order(move))
            • Then - Actions
              • -------- HERE WE PICK ANY UNITS WHITHIN RANGE THAT DO NOT BELONG TO THE UNIT'S FACTION --------
              • Unit Group - Pick every unit in (Units within (Current acquisition range of Unit1) of Loc1 matching ((((Matching unit) is in Faction1) Equal to False) and (((Matching unit) is alive) Equal to True))) and do (Actions)
                • Loop - Actions
                  • Set Unit2 = (Picked unit)
                  • Unit - Order Unit1 to Attack Unit2
                  • -------- WE SET ENGAGED TO TRUE SO IT WONT ORDER ATTACK EVERY 0.33 SECONDS --------
                  • Set IsEngaged[(Custom value of Unit1)] = True
                  • -------- WE DEFINE THE TARGET --------
                  • Set Target[(Custom value of Unit1)] = Unit2
                  • -------- WE ADD THE UNIT1 TO A UNIT GROUP WITH ARRAY OF UNIT2 --------
                  • Unit Group - Add Unit1 to Target_Cleaning[(Custom value of Unit2)]
                  • -------- WE WILL USE THAT GROUP LATER FOR CLEARING TARGET AND ENGAGEMENT STAT OF UNIT1 --------
            • Else - Actions
          • Custom script: call RemoveLocation(udg_Loc1)
      • -------- -------------------------- --------
      • -------- FACTION 2 --------
      • Unit Group - Pick every unit in Faction2 and do (Actions)
        • Loop - Actions
          • Set Unit1 = (Picked unit)
          • Set Loc1 = (Position of (Picked unit))
          • -------- HERE WE CHECK IF THE UNIT IS STOPPED AND HAS ENEMIES WHITHIN ACQUISITION RANGE --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • IsEngaged[(Custom value of Unit1)] Equal to False
              • (Current order of Unit1) Not equal to (Order(smart))
              • (Current order of Unit1) Not equal to (Order(move))
            • Then - Actions
              • -------- HERE WE PICK ANY UNITS WHITHIN RANGE THAT DO NOT BELONG TO THE UNIT'S FACTION --------
              • Unit Group - Pick every unit in (Units within (Current acquisition range of Unit1) of Loc1 matching ((((Matching unit) is in Faction2) Equal to False) and (((Matching unit) is alive) Equal to True))) and do (Actions)
                • Loop - Actions
                  • Set Unit2 = (Picked unit)
                  • Unit - Order Unit1 to Attack Unit2
                  • -------- WE SET ENGAGED TO TRUE SO IT WONT ORDER ATTACK EVERY 0.33 SECONDS --------
                  • Set IsEngaged[(Custom value of Unit1)] = True
                  • -------- WE DEFINE THE TARGET --------
                  • Set Target[(Custom value of Unit1)] = Unit2
                  • -------- WE ADD THE UNIT1 TO A UNIT GROUP WITH ARRAY OF UNIT2 --------
                  • Unit Group - Add Unit1 to Target_Cleaning[(Custom value of Unit2)]
                  • -------- WE WILL USE THAT GROUP LATER FOR CLEARING TARGET AND ENGAGEMENT STAT OF UNIT1 --------
            • Else - Actions
          • Custom script: call RemoveLocation(udg_Loc1)
      • -------- -------------------------- --------
      • -------- -------------------------- --------
  • Faction Actions New
    • Events
    • Conditions
    • Actions
      • -------- THIS TRIGGER IS FIRED WHEN A UNIT COMES WHITHIN ACQUISITION RANGE OF ANOTHER --------
      • Set Unit1 = (Triggering unit)
      • Set Loc1 = (Position of (Picked unit))
      • -------- FACTION 1 --------
      • Unit Group - Pick every unit in Faction1 and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • IsEngaged[(Custom value of Unit1)] Equal to False
            • Then - Actions
              • Unit Group - Pick every unit in (Random 1 units from (Units within (Current acquisition range of (Triggering unit)) of Loc1 matching (((Matching unit) is in Faction1) Equal to False))) and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is alive) Equal to True
                      • (Current order of Unit1) Not equal to (Order(move))
                      • (Current order of Unit1) Not equal to (Order(smart))
                    • Then - Actions
                      • Set Unit2 = (Picked unit)
                      • Unit - Order Unit1 to Attack Unit2
                      • -------- WE SET ENGAGED TO TRUE SO IT WONT ORDER ATTACK EVERY 0.33 SECONDS --------
                      • Set IsEngaged[(Custom value of Unit1)] = True
                      • -------- WE DEFINE THE TARGET --------
                      • Set Target[(Custom value of Unit1)] = Unit2
                      • -------- WE ADD THE UNIT1 TO A UNIT GROUP WITH ARRAY OF UNIT2 --------
                      • Unit Group - Add Unit1 to Target_Cleaning[(Custom value of Unit2)]
                      • -------- WE WILL USE THAT GROUP LATER FOR CLEARING TARGET AND ENGAGEMENT STAT OF UNIT1 --------
                    • Else - Actions
            • Else - Actions
      • -------- ------------------------------ --------
      • -------- FACTION 2 --------
      • Unit Group - Pick every unit in Faction2 and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • IsEngaged[(Custom value of Unit1)] Equal to False
            • Then - Actions
              • Unit Group - Pick every unit in (Random 1 units from (Units within (Current acquisition range of (Triggering unit)) of Loc1 matching (((Matching unit) is in Faction2) Equal to False))) and do (Actions)
                • Loop - Actions
                  • -------- HERE WE CAN CHECK FOR SPECIFIC UNIT GROUP (FOR EXAMPLE YOU WANT OR NOT TO UNITS FROM FACTION 2 TO ATTACK A SPECIFIC GROUP OUTSIDE IT'S FACTION) --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is alive) Equal to True
                      • (Current order of Unit1) Not equal to (Order(move))
                      • (Current order of Unit1) Not equal to (Order(smart))
                    • Then - Actions
                      • Set Unit2 = (Picked unit)
                      • Unit - Order Unit1 to Attack Unit2
                      • -------- WE SET ENGAGED TO TRUE SO IT WONT ORDER ATTACK EVERY 0.33 SECONDS --------
                      • Set IsEngaged[(Custom value of Unit1)] = True
                      • -------- WE DEFINE THE TARGET --------
                      • Set Target[(Custom value of Unit1)] = Unit2
                      • -------- WE ADD THE UNIT1 TO A UNIT GROUP WITH ARRAY OF UNIT2 --------
                      • Unit Group - Add Unit1 to Target_Cleaning[(Custom value of Unit2)]
                      • -------- WE WILL USE THAT GROUP LATER FOR CLEARING TARGET AND ENGAGEMENT STAT OF UNIT1 --------
                    • Else - Actions
            • Else - Actions
      • -------- ------------------------------ --------
      • Custom script: call RemoveLocation(udg_Loc1)
  • Order Check New
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
    • Actions
      • -------- HERE WE CHECK FOR RIGHT CLICK OF A UNIT FROM ONE FACTION TO ANOTHER --------
      • Set Unit1 = (Ordered unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Issued order) Equal to (Order(smart))
        • Then - Actions
          • -------- FACTION AND GROUP CHECK --------
          • Set Unit2 = (Target unit of issued order)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit1 is in Faction1) Equal to True
              • (Unit2 is in Faction1) Equal to False
            • Then - Actions
              • Unit - Order Unit1 to Attack Unit2
              • Set Target[(Custom value of Unit1)] = Unit2
              • Set IsEngaged[(Custom value of Unit1)] = True
              • Unit Group - Add Unit1 to Target_Cleaning[(Custom value of Unit2)]
            • Else - Actions
              • -------- FACTION AND GROUP CHECK --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit1 is in Faction2) Equal to True
                  • (Unit2 is in Faction2) Equal to False
                • Then - Actions
                  • Unit - Order Unit1 to Attack Unit2
                  • Set Target[(Custom value of Unit1)] = Unit2
                  • Set IsEngaged[(Custom value of Unit1)] = True
                  • Unit Group - Add Unit1 to Target_Cleaning[(Custom value of Unit2)]
                • Else - Actions
        • Else - Actions
  • Target Clearing
    • Events
      • Unit - A unit Is issued an order targeting an object
      • Unit - A unit Is issued an order targeting a point
      • Unit - A unit Is issued an order with no target
      • Unit - A unit Dies
    • Conditions
    • Actions
      • -------- CLEANING THROUGHT ORDERS --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Issued order) Equal to (Order(stop))
              • (Issued order) Equal to (Order(smart))
              • (Issued order) Equal to (Order(attack))
        • Then - Actions
          • Set Target[(Custom value of (Ordered unit))] = No unit
          • Set IsEngaged[(Custom value of (Ordered unit))] = False
        • Else - Actions
      • -------- ---------------------------------- --------
      • -------- CLEANING UPON DEATH --------
      • Set Unit1 = (Dying unit)
      • Unit Group - Pick every unit in Target_Cleaning[(Custom value of Unit1)] and do (Actions)
        • Loop - Actions
          • Set Unit2 = (Picked unit)
          • Set Target[(Custom value of Unit2)] = No unit
          • Set IsEngaged[(Custom value of Unit2)] = False
          • Unit Group - Remove all units from Target_Cleaning[(Custom value of Unit1)]
      • -------- ---------------------------------- --------
 
Last edited:
Status
Not open for further replies.
Top