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

[GUI] Limit Attackers System 1.02

Limit Attackers System

Description
Limits the number of units that can attack a given unit type at the same time.
Made by request for shermellow: Limit Number of Attackers
(for a farm-type unit that is attacked for resources)

Probably useful for Tower Defense maps.

Does not work for attack ground, and probably not for Frost Arrow-type ability target casting.

Fires an event (LAS_Event == 1.00) when a unit is prevented from attacking, saving the attacking and attacked units to variables.

Installation
Pre-requisite: Bribe's Unit Indexer (included)

Installation:
1. If your map doesn't have a unit indexing system, copy Bribe's Unit Indexer (included) to your map
2. Copy the trigger category "Limit Attackers System" into your map (make sure "Automatically create unknown variables" is enabled in editor preferences)
3. Configure your units in the LAS Config trigger
4. Set the array size of LAS_Group to 8000.

Triggers

  • LAS Config
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set LAS_Table = (Last created hashtable)
      • -------- ------------------------------ --------
      • -------- Set how frequently the cooldown trigger is fired - higher for better accuracy --------
      • Set LAS_PeriodicTimer = 0.25
      • -------- ------------------------------ --------
      • -------- CONFIGURATION --------
      • -------- ------------------------------ --------
      • Set LAS_Limit = 1
      • Set LAS_SetCooldown = 3.00
      • Set LAS_UnitType = Farm
      • Trigger - Run LAS Table Save <gen> (ignoring conditions)
      • -------- ------ --------
      • Set LAS_Limit = 3
      • Set LAS_SetCooldown = 3.00
      • Set LAS_UnitType = Barracks
      • Trigger - Run LAS Table Save <gen> (ignoring conditions)
      • -------- ------ --------
      • Set LAS_Limit = 0
      • Set LAS_SetCooldown = 3.00
      • Set LAS_UnitType = Lumber Mill
      • Trigger - Run LAS Table Save <gen> (ignoring conditions)
      • -------- ------------------------- --------
      • -------- Don't edit below --------
      • -------- ------------------------- --------
      • Trigger - Add to LAS Attacker Cooldown <gen> the event (Time - Every LAS_PeriodicTimer seconds of game time)
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • -------- Load values from table --------
          • Set LAS_UnitType = (Unit-type of (Picked unit))
          • Trigger - Run LAS Table Load <gen> (ignoring conditions)
          • -------- Check if unit uses the system --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • LAS_Check Equal to True
            • Then - Actions
              • Unit Group - Add (Picked unit) to LAS_FarmGroup
            • Else - Actions
  • LAS Table Save
    • Events
    • Conditions
    • Actions
      • Custom script: set udg_LAS_UnitTypeId = udg_LAS_UnitType
      • Hashtable - Save LAS_Limit as 0 of LAS_UnitTypeId in LAS_Table
      • Hashtable - Save LAS_SetCooldown as 1 of LAS_UnitTypeId in LAS_Table
      • Hashtable - Save True as 2 of LAS_UnitTypeId in LAS_Table
  • LAS Table Load
    • Events
    • Conditions
    • Actions
      • Custom script: set udg_LAS_UnitTypeId = udg_LAS_UnitType
      • Set LAS_Limit = (Load 0 of LAS_UnitTypeId from LAS_Table)
      • Set LAS_SetCooldown = (Load 1 of LAS_UnitTypeId from LAS_Table)
      • Set LAS_Check = (Load 2 of LAS_UnitTypeId from LAS_Table)
  • LAS Add to Group
    • Events
      • Game - UnitIndexEvent becomes Equal to 1.00
    • Conditions
    • Actions
      • -------- Load values from table --------
      • Set LAS_UnitType = (Unit-type of UDexUnits[UDex])
      • Trigger - Run LAS Table Load <gen> (ignoring conditions)
      • -------- Check if unit uses the system --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • LAS_Check Equal to True
        • Then - Actions
          • Unit Group - Add UDexUnits[UDex] to LAS_FarmGroup
        • Else - Actions
  • LAS Attack Trigger
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Triggering unit) is in LAS_FarmGroup) Equal to True
    • Actions
      • -------- Load values from table --------
      • Set LAS_UnitType = (Unit-type of (Triggering unit))
      • Trigger - Run LAS Table Load <gen> (ignoring conditions)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • LAS_Check Equal to True
        • Then - Actions
          • Set LAS_tempId = (Custom value of (Triggering unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Attacking unit) is in LAS_Group[LAS_tempId]) Equal to True
            • Then - Actions
              • -------- Start cooldown --------
              • Set LAS_tempIdOfAttacker = (Custom value of (Attacking unit))
              • Set LAS_Cooldown[LAS_tempIdOfAttacker] = LAS_SetCooldown
              • Set LAS_TargetId[LAS_tempIdOfAttacker] = LAS_tempId
              • Unit Group - Add (Attacking unit) to LAS_AttackerGroup
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • LAS_Limit Equal to 0
                • Then - Actions
                  • Unit - Order (Attacking unit) to Stop
                  • -------- Fire event --------
                  • Set LAS_EventAttacked = (Triggering unit)
                  • Set LAS_EventAttacker = (Attacking unit)
                  • Set LAS_Event = 0.00
                  • Set LAS_Event = 1.00
                  • Set LAS_Event = 0.00
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Number of units in LAS_Group[LAS_tempId]) Less than LAS_Limit
                    • Then - Actions
                      • Unit Group - Add (Attacking unit) to LAS_Group[LAS_tempId]
                      • -------- Start cooldown --------
                      • Set LAS_tempIdOfAttacker = (Custom value of (Attacking unit))
                      • Set LAS_Cooldown[LAS_tempIdOfAttacker] = LAS_SetCooldown
                      • Set LAS_TargetId[LAS_tempIdOfAttacker] = LAS_tempId
                      • Unit Group - Add (Attacking unit) to LAS_AttackerGroup
                    • Else - Actions
                      • Unit - Order (Attacking unit) to Stop
                      • -------- Fire event --------
                      • Set LAS_EventAttacked = (Triggering unit)
                      • Set LAS_EventAttacker = (Attacking unit)
                      • Set LAS_Event = 0.00
                      • Set LAS_Event = 1.00
                      • Set LAS_Event = 0.00
        • Else - Actions
  • LAS Attacker Cooldown
    • Events
    • Conditions
    • Actions
      • Unit Group - Pick every unit in LAS_AttackerGroup and do (Actions)
        • Loop - Actions
          • Set LAS_tempId = (Custom value of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • LAS_Cooldown[LAS_tempId] Greater than 0.00
            • Then - Actions
              • Set LAS_Cooldown[LAS_tempId] = (LAS_Cooldown[LAS_tempId] - LAS_PeriodicTimer)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • LAS_Cooldown[LAS_tempId] Less than or equal to 0.00
                • Then - Actions
                  • Unit Group - Remove (Picked unit) from LAS_AttackerGroup
                  • Unit Group - Remove (Picked unit) from LAS_Group[LAS_TargetId[LAS_tempId]]
                • Else - Actions
            • Else - Actions


Changelog
1.02
  • Cooldown period is now configurable
  • A limit of 0 now means the unit cannot be attacked
1.01
  • Added event
  • Removed redundant cooldown loop

Credits
Bribe - Unit Indexer.
shermellow - Idea.

Keywords:
limit attackers, limit, attacker, attackers, stop attackers,
Contents

Limit Attackers System 1.02 (Map)

Reviews
01:20, 27th Nov 2012 Magtheridon96: Approved. This is a useful system. The code's good, and the configuration is splendid.

Moderator

M

Moderator

01:20, 27th Nov 2012
Magtheridon96: Approved.
This is a useful system. The code's good, and the configuration is splendid.
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
Perhaps you could create a separate verison of this that is a "anti-hero target" system for maps like Lordaeron Tactics / BFME / Second Age, War of the Ring e.t.c. e.t.c. , the system would allow only X amount of units to target heroes and if more are ordered the lesser units are replaced by stronger units. And those that are not allowed to attack gets a attack ground order? =)
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Perhaps you could create a separate verison of this that is a "anti-hero target" system for maps like Lordaeron Tactics / BFME / Second Age, War of the Ring e.t.c. e.t.c. , the system would allow only X amount of units to target heroes and if more are ordered the lesser units are replaced by stronger units. And those that are not allowed to attack gets a attack ground order? =)

Great idea!
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
Too bad this doesn't work for auto-acquired targets nor does it make those who can't attack look for nearby targets. ;(

I was thinking if u made a resource unit have a rare classification, you could order workers to attack that area and bring back the food. Sure, one could trigger that without or with this. Perhaps re-wrap this into a "Age of Empires resource system?"
 
Top