wewso
New Member
- Reaction score
- 11
Unique Custom Value System
Explanation:
So, I have been having problems lately with some of the spells in my Hero Arena. Most of them work with triggers and so I had to make them MUI (Multi-Unit-Instanceability) which means that they should work propperly on more than one unit at the same time. Then I came up with the idea of giving each unit a unique custom value which can be used in varaible arrays to store information about the unit.
First I made a trigger that gives each unit custom value, equal to the order it was created. I worked a little bit on the system and I came to the conclusion that it wont work that way since there may be enormous amounts of units created, but very little of them are left alive. I would have had a unit with custom value 2 and a unit with 457 and all the units that had custom values between 2 and 457 dead and their values - unused. To fix this I made the trigger to set the custom value of the unit to the lowest positive number that is not used by another unit.
Example:
- I train a Footman and he is the first unit in the map. The lowest unused positive number is 1 so the footy gets Custom Value 1
- Then I train another footman, who is the second trained unit in the map. Analogicaly he gets Custom Value 2
- Now I take Footman 2 and kill Footman 1 with him.
- Then I train another Footman, that is the third trained unit in the map. However he doesnt get Custom Value 3 because the lowest unused number is 1 (Footman 1 died a while ago) His Custom Value is set to 1.
Here are the triggers:
You need only 1 varaible "Loop" - a non-array integer
Main trigger for new units:
Code:
New Unit Custom Value
Events
Unit - A unit enters (Entire map)
Conditions
(Custom value of (Triggering unit)) Equal to 0
Actions
Set Loop = 0
For each (Integer A) from 1 to 8192, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Then - Actions
Unit Group - Pick every unit in (Units in (Entire map)) and do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Custom value of (Picked unit)) Equal to (Integer A)
Then - Actions
Set Loop = (Loop + 1)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Loop Equal to 0
Then - Actions
Unit - Set the custom value of (Triggering unit) to (Integer A)
Skip remaining actions
Else - Actions
Else - Actions
Trigger for pre-placed units:
Code:
Prepalced Unit Custom Value
Events
Map initialization
Conditions
Actions
Set Loop = 0
Unit Group - Pick every unit in (Units in (Entire map)) and do (Actions)
Loop - Actions
Set Loop = (Loop + 1)
Unit - Set the custom value of (Picked unit) to Loop
NOTE 1: Units still exist even after they are killed. They can be manipulated until their corpses dissappear. My system wont consider a Custom Value number free until the unit it was used by is remover from the game or its corpse dissappears. I did this to avoid bugs with reviving Heroes or Animate Dead spell.
NOTE 2: The system can handle no more that 8192 units at a time. You can change this restriction but remember that the maximum Array size is 8192 and you wont be able to store the unit data in the varaible. However strongly reccomend you not to use that many units in your map :shades:.
++Rep if you liked it
VVV The map may help you VVV