- Joined
- Aug 3, 2004
- Messages
- 2,891
I was attempting to add unts to the exemption list and always ended up causing a fatal error, most likely an infinite loop. This is the base system and it has instructions, though I could not get it to work.
How would I add a footman to the list?
How would I add a footman to the list?
-
Unit Indexer
-
Events
- Map initialization
- Conditions
-
Actions
- Custom script: call ExecuteFunc("InitializeUnitIndexer")
- Custom script: endfunction
- -------- --------
- -------- This is the most important function - it provides an index for units as they enter the map --------
- -------- --------
- Custom script: function IndexUnit takes nothing returns boolean
- Custom script: local integer pdex = udg_UDex
- -------- --------
- -------- You can use the boolean UnitIndexerEnabled to protect some of your undesirable units from being indexed --------
- -------- - Example: --------
- -------- -- Set UnitIndexerEnabled = False --------
- -------- -- Unit - Create 1 Dummy for (Triggering player) at TempLoc facing 0.00 degrees --------
- -------- -- Set UnitIndexerEnabled = True --------
- -------- --------
- -------- You can also customize the following block - if conditions are false the (Matching unit) won't be indexed. --------
- -------- --------
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- UnitIndexerEnabled Equal to True
-
Then - Actions
- -------- --------
- -------- Generate a unique integer index for this unit --------
- -------- --------
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- UDexRecycle Equal to 0
-
Then - Actions
- Set UDex = (UDexGen + 1)
- Set UDexGen = UDex
-
Else - Actions
- Set UDex = UDexRecycle
- Set UDexRecycle = UDexNext[UDex]
-
If - Conditions
- -------- --------
- -------- Link index to unit, unit to index --------
- -------- --------
- Set UDexUnits[UDex] = (Matching unit)
- Unit - Set the custom value of UDexUnits[UDex] to UDex
- -------- --------
- -------- Use a doubly-linked list to store all active indexes --------
- -------- --------
- Set UDexPrev[UDexNext[0]] = UDex
- Set UDexNext[UDex] = UDexNext[0]
- Set UDexNext[0] = UDex
- -------- --------
- -------- Fire index event for UDex --------
- -------- --------
- Set UnitIndexEvent = 0.00
- Set UnitIndexEvent = 1.00
- Set UnitIndexEvent = 0.00
- Custom script: set udg_UDex = pdex
- Else - Actions
-
If - Conditions
- Custom script: return false
- Custom script: endfunction
- -------- --------
- -------- The next function is called each time a unit enters the map --------
- -------- --------
- Custom script: function IndexNewUnit takes nothing returns boolean
- Custom script: local integer pdex = udg_UDex
- Custom script: local integer ndex
- -------- --------
- -------- Recycle indices of units no longer in-play every (15) units created --------
- -------- --------
- Set UDexWasted = (UDexWasted + 1)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- UDexWasted Equal to 15
-
Then - Actions
- Set UDexWasted = 0
- Set UDex = UDexNext[0]
- Custom script: loop
- Custom script: exitwhen udg_UDex == 0
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- (Custom value of UDexUnits[UDex]) Equal to 0
-
Then - Actions
- -------- --------
- -------- Remove index from linked list --------
- -------- --------
- Custom script: set ndex = udg_UDexNext[udg_UDex]
- Custom script: set udg_UDexNext[udg_UDexPrev[udg_UDex]] = ndex
- Custom script: set udg_UDexPrev[ndex] = udg_UDexPrev[udg_UDex]
- Set UDexPrev[UDex] = 0
- -------- --------
- -------- Fire deindex event for UDex --------
- -------- --------
- Set UnitIndexEvent = 2.00
- Set UnitIndexEvent = 0.00
- -------- --------
- -------- Recycle the index for later use --------
- -------- --------
- Set UDexUnits[UDex] = No unit
- Set UDexNext[UDex] = UDexRecycle
- Set UDexRecycle = UDex
- Custom script: set udg_UDex = ndex
-
Else - Actions
- Set UDex = UDexNext[UDex]
-
If - Conditions
- Custom script: endloop
- Custom script: set udg_UDex = pdex
- Else - Actions
-
If - Conditions
- -------- --------
- -------- Handle the entering unit (Matching unit) --------
- -------- --------
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- (Custom value of (Matching unit)) Equal to 0
-
Then - Actions
- Custom script: call IndexUnit()
- Else - Actions
-
If - Conditions
- Custom script: return false
- Custom script: endfunction
- -------- --------
- -------- The next function initializes the core of the system --------
- -------- --------
- Custom script: function InitializeUnitIndexer takes nothing returns nothing
- Custom script: local integer i = 0
- Custom script: local region re = CreateRegion()
- Custom script: local rect r = GetWorldBounds()
- Set UnitIndexerEnabled = True
- Custom script: call RegionAddRect(re, r)
- Custom script: call TriggerRegisterEnterRegion(CreateTrigger(), re, Filter(function IndexNewUnit))
- Custom script: call RemoveRect(r)
- Custom script: set re = null
- Custom script: set r = null
- Custom script: loop
- Custom script: call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, Player(i), Filter(function IndexUnit))
- Custom script: set i = i + 1
- Custom script: exitwhen i == 16
- Custom script: endloop
- -------- --------
- -------- This is the "Unit Indexer Initialized" event, use it instead of "Map Initialization" for best results --------
- -------- --------
- Set UnitIndexEvent = 3.00
- Set UnitIndexEvent = 0.00
-
Events