Moderator
M
Moderator
16:29, 28th Jun 2011
Maker: Approved. Can be of great use in creating MUI spells and systems.
Maker: Approved. Can be of great use in creating MUI spells and systems.
Hashtable - Save 100 as (Key(Damage)) of (Key(Triggering unit)) in (Last created hashtable)
Set Damage[(Custom value of (Triggering unit))] = 100
Unit - Set custom value of (Triggering unit) to 100
Set Key = (Custom value of (Triggering unit))
Set Damage[Key] = 100
Set Target[Key] = (Target unit of ability being cast)
Set TargetPoint[Key] = (Target point of ability being cast)
Unit Group - Add (Triggering unit) to SpellGroup
Timed Spell

Events


Time - Every 0.03 seconds of game time

Conditions

Actions


Unit Group - Pick every unit in SpellGroup and do (Actions)



Loop - Actions




Set Key = (Custom value of (Picked unit))




Unit - Cause (Picked unit) to damage Target[Key] for Damage[Key] of attack type Chaos and damage type normal
Unit Indexer

Events


Map initialization

Conditions

Actions


Custom script: call ExecuteFunc("InitializeUnitIndexer")


Custom script: endfunction


-------- --------


-------- This is the core function - it provides an index all existing units and for units as they enter the map --------


-------- --------


Custom script: function IndexUnit takes nothing returns boolean


Custom script: local integer pdex = udg_UDex


Custom script: local integer ndex


If (All Conditions are True) then do (Then Actions) else do (Else Actions)



If - Conditions




IsUnitPreplaced[0] Equal to False



Then - Actions




-------- --------




-------- Check for removed units for every (32) new units created --------




-------- --------




Set UDexWasted = (UDexWasted + 1)




If (All Conditions are True) then do (Then Actions) else do (Else Actions)





If - Conditions






UDexWasted Equal to 32





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








Set IsUnitPreplaced[UDex] = False








-------- --------








-------- 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]






Custom script: endloop





Else - Actions



Else - Actions


-------- --------


-------- 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




(Custom value of (Matching unit)) Equal to 0



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]




-------- --------




-------- Link index to unit, unit to index --------




-------- --------




Set UDexUnits[UDex] = (Matching unit)




Unit - Set the custom value of UDexUnits[UDex] to UDex




Set IsUnitPreplaced[UDex] = IsUnitPreplaced[0]




-------- --------




-------- 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



Else - Actions


Custom script: set udg_UDex = pdex


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()


Custom script: local boolexpr b = Filter(function IndexUnit)


Set UnitIndexEvent = -1.00


Set UnitIndexerEnabled = True


Set IsUnitPreplaced[0] = True


Custom script: call RegionAddRect(re, r)


Custom script: call TriggerRegisterEnterRegion(CreateTrigger(), re, b)


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), b)


Custom script: set i = i + 1


Custom script: exitwhen i == bj_MAX_PLAYER_SLOTS


Custom script: endloop


Custom script: set b = null


-------- --------


-------- This is the "Unit Indexer Initialized" event, use it instead of "Map Initialization" for best results --------


-------- --------


Set IsUnitPreplaced[0] = False


Set UnitIndexEvent = 3.00
Unit Indexed Event

Events


Game - UnitIndexEvent becomes Equal to 1.00

Conditions


UDexUnits[UDex] is A Hero Equal To true

Actions


Item - Create 1 Tome of Power and give it to UDexUnits[UDex]
Unit Deindexed Event

Events


Game - UnitIndexEvent becomes Equal to 2.00

Conditions

Actions


Game - Display to (All Players) the text - Unit (UDex) was deindexed!
Unit Indexer Initialized Event

Events


Game - UnitIndexEvent becomes Equal to 3.00

Conditions

Actions


Unit - Create 1 Paladin for (Player 1) at TempPoint facing 0.00 degrees


Item - Create 1 Ankh of Reincarnation and give it to (Last created unit)


Set HeroItem[(Custom value of (Last created unit))] = (Last created item)