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

Horde System

Status
Not open for further replies.
Level 22
Joined
Jul 25, 2009
Messages
3,091
I've been trying to make a system where every unit in a given unit group (Group A) will attack a unit they deem their target (Group B)... Each unit in Group A has its own unique target in Group B unless of course Group B only contains 1 unit then all units in Group A would have the same target.

Problems...

1. Selection how can I make each individual unit in Group A select the unit closest to them with the highest "Aggro" (The "Aggro" is just a real I created to improve realism in the system) in Group B. Each unit has to select the target individually because some of the units will be in different locations drastically far away from each other.

2. Attacking, I want them to Attack-Move to their target, not Attack the target (Unit from Group B). If they attack the target they will not attack nearby targets that are closer, they will just continue chasing their target.
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
Threat system.

However, if you do not want to use vJass system you can always use indexer, like Bride's one and 'save' target via:
  • Set key = (Custom value of (yourunit))
  • Set Target[key] = <unit you want to be a target for yourunit>
Now in your loop or in any time you want to 'attack' the 'target' use:
  • Set key = (Custom value of (yourunit))
  • Unit - Order <fill which unit you want to manipulate> to attack Target[key]
 
Level 22
Joined
Jul 25, 2009
Messages
3,091
Threat system.

However, if you do not want to use vJass system you can always use indexer, like Bride's one and 'save' target via:
  • Set key = (Custom value of (yourunit))
  • Set Target[key] = <unit you want to be a target for yourunit>
Now in your loop or in any time you want to 'attack' the 'target' use:
  • Set key = (Custom value of (yourunit))
  • Unit - Order <fill which unit you want to manipulate> to attack Target[key]

Already looked into the threat system it won't do for various reasons. Nice avatar btw.

I already have the target indexed using the player number of the owner? I don't think you understood, I need to assign the target to each unit of Group A individually based on Distance and "Aggro"
 
Sorry for not responding. When I get home I might see what the problem is.

EDIT. Time to HELP.
I don't really understand what you want, your questions are confusing. But anyways, heres what I interpret what you want.
  • Unit Group - Pick every unit in GroupA and do (Actions)
    • Loop - Actions
      • Set temp_unit = (Picked unit)
      • Set temp_point[1] = (Position of temp_unit)
      • Unit Group - Pick every unit in GroupB and do (Actions)
        • Loop - Actions
          • Set temp_point[2] = (Position of (Picked unit))
          • Set temp_point[3] = (Position of close_unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • (Distance between temp_point[1] and temp_point[2]) Less than (Distance between temp_point[1] and temp_point[3])
                  • close_unit Equal to No unit
            • Then - Actions
              • Set close_unit = (Picked unit)
            • Else - Actions
          • Custom script: call RemoveLocation(udg_temp_point[2])
          • Custom script: call RemoveLocation(udg_temp_point[3])
      • Set temp_point[3] = (Position of close_unit)
      • Unit - Order temp_unit to Attack-Move To temp_point[3]
      • Custom script: set udg_temp_unit = null
      • Custom script: set udg_close_unit = null
      • Custom script: call RemoveLocation(udg_temp_point[1])
      • Custom script: call RemoveLocation(udg_temp_point[3])
 
Last edited:
Level 22
Joined
Jul 25, 2009
Messages
3,091
Sorry for not responding. When I get home I might see what the problem is.

EDIT. Time to HELP.
I don't really understand what you want, your questions are confusing. But anyways, heres what I interpret what you want.
  • Unit Group - Pick every unit in GroupA and do (Actions)
    • Loop - Actions
      • Set temp_unit = (Picked unit)
      • Set temp_point[1] = (Position of temp_unit)
      • Unit Group - Pick every unit in GroupB and do (Actions)
        • Loop - Actions
          • Set temp_point[2] = (Position of (Picked unit))
          • Set temp_point[3] = (Position of close_unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • (Distance between temp_point[1] and temp_point[2]) Less than (Distance between temp_point[1] and temp_point[3])
                  • close_unit Equal to No unit
            • Then - Actions
              • Set close_unit = (Picked unit)
            • Else - Actions
          • Custom script: call RemoveLocation(udg_temp_point[2])
          • Custom script: call RemoveLocation(udg_temp_point[3])
      • Set temp_point[3] = (Position of close_unit)
      • Unit - Order temp_unit to Attack-Move To temp_point[3]
      • Custom script: set udg_temp_unit = null
      • Custom script: set udg_close_unit = null
      • Custom script: call RemoveLocation(udg_temp_point[1])
      • Custom script: call RemoveLocation(udg_temp_point[3])

Will this work on a short looping trigger?
 
Level 22
Joined
Jul 25, 2009
Messages
3,091
  • Attack Target
    • Events
      • Time - Every 15.00 seconds of game time
    • Conditions
    • Actions
      • Leaderboard - Sort AggroBoard by Value in Descending order
      • Set TargetNumber = (Player number of (Player in position (Random integer number between 1 and ((Number of players in ActivePlayers) + 1)) of AggroBoard))
  • Periodic Attack
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units owned by Player 12 (Brown)) and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Attack-Move To TargetPosition[TargetNumber]

  • Periodic Attack
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units owned by Player 12 (Brown)) and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Attack-Move To TargetPosition[TargetNumber]
The aggro board is my experimental aggro meter. Each time you kill something or fire your weapon without a suppressor your aggro goes up slightly. The players with the highest aggro will always be preferred targets.
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
you are targeting a point so you should specify this >>> TargetPosition[TargetNumber]

something like this...
  • Set temploc = (Position of (Random unit from (Units owned by (Player(TargetNumber)))))
  • Unit Group - Pick every unit in (Units owned by Player 12 (Brown)) and do (Actions)
    • Loop - ACtions
      • Unit - Order (Picked unit) to Attack-Move To temploc
  • Custom script: call RemoveLocation(udg_temploc)
 
Level 15
Joined
Oct 18, 2008
Messages
1,588
I think you should use this:
  • -Settings-
    • Set RangeModifier = 10 (For example)
Then give the attack order every 0.5 seconds, using this formula:
  • Set X = 0
  • For each (Integer A) from 1 to XMax, do
    • Set TempIntArray[Integer A] = 0
  • Set TempGroup = yourunitgroup (IDK your method of selecting them)
  • Unit Group - Pick Every unit in TempGroup
    • Set TempPoint = Position of (Issued order of (Picked Unit))
    • Set TempUnit = Picked Unit
    • Set TargetGroup=Unit within 500 of TempPoint matching (Matching unit belongs to an enemy of (Owner of (Picked Unit)))
    • Unit Group - Pick Every unit in TargetGroup
      • Set X = X+1
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • X is greater than XMax
        • Then - Actions
          • Set XMax = X
        • Else - Actions
      • Set TempUnitArray[X] = Picked Unit
      • Set TempIntArray[X] = (Agro of picked unit(Recommend Hashtable)) - ((Distance between (TempUnit) and (Picked unit))/RangeModifier)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TempIntArray[X] is greater than TempIntArray[X+1]
        • Then - Actions
          • Set Target = TempUnitArray[X]
        • Else - Actions
    • Unit - Order (Picked unit) to Attack (Target)
It'll use the real you used and with a settable static number it calculates a priority value-so it'll balance between range and agro (if set corerctly, but without knowing your agro system and general distances in your fighting system I can't tell how big should that number be

Oh and I was too lazy to type in the leak removing triggers ;)
 
Last edited:
Level 15
Joined
Oct 18, 2008
Messages
1,588
The problem is your loops selects a random unit from agroboard (not just taking AgroBoard[1]) without calculating agroGauge-enemyDistance which is very important


Sorry for not responding. When I get home I might see what the problem is.

EDIT. Time to HELP.
I don't really understand what you want, your questions are confusing. But anyways, heres what I interpret what you want.
  • Unit Group - Pick every unit in GroupA and do (Actions)
    • Loop - Actions
      • Set temp_unit = (Picked unit)
      • Set temp_point[1] = (Position of temp_unit)
      • Unit Group - Pick every unit in GroupB and do (Actions)
        • Loop - Actions
          • Set temp_point[2] = (Position of (Picked unit))
          • Set temp_point[3] = (Position of close_unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • (Distance between temp_point[1] and temp_point[2]) Less than (Distance between temp_point[1] and temp_point[3])
                  • close_unit Equal to No unit
            • Then - Actions
              • Set close_unit = (Picked unit)
            • Else - Actions
          • Custom script: call RemoveLocation(udg_temp_point[2])
          • Custom script: call RemoveLocation(udg_temp_point[3])
      • Set temp_point[3] = (Position of close_unit)
      • Unit - Order temp_unit to Attack-Move To temp_point[3]
      • Custom script: set udg_temp_unit = null
      • Custom script: set udg_close_unit = null
      • Custom script: call RemoveLocation(udg_temp_point[1])
      • Custom script: call RemoveLocation(udg_temp_point[3])

Dude your system is nice but you ignored the fact that he needs Agro calculations too

EDIT: Edited my trigger a bit so it does what it's supposed to :D
 
Status
Not open for further replies.
Top