I HAVE EDITED MY EXAMPLE WITH A NEW ONE, AS THE OLD EXAMPLE WAS NOT REALISTIC
(I will use a spell that I made on a map, while learning how to use triggers.)
Ever had to make a custom MUI ability, that has several levels and uses Unit Groups? If yes, then it most likely looked something like this:
Well, that's quite annoying, isn't it?
Instead you can just do:
VERSION 1:
VERSION 2:
Much simpler! Imagine if you had to make 10 unit groups for just one skill. This will save you tons of writing, and you will have less variables to deal with!
NOTES:
1) This technique can be used for Units and for Items too, it's not limited to Unit Groups.
2) Using the "normal way" takes many variables with 13 levels (or 12 if you are writing -1), while this method takes 12*(groups needed per player)+1. Don't forget to make your arrays big enough.
3) The number "*3" in this example varries, based on how many levels the ability has, if it has 9 levels, it should be changed to 9.
EDIT:
Wietlol reminded me that I didn't EXPLAIN what I was doing, and I just showed what to do, therefore I will add this to the Original post
(I will use a spell that I made on a map, while learning how to use triggers.)
Ever had to make a custom MUI ability, that has several levels and uses Unit Groups? If yes, then it most likely looked something like this:
-
Mana Flare
-
Events
-
Unit - A unit Starts the effect of an ability
-
-
Conditions
-
(Ability being cast) Equal to Mana Flare Hero
-
-
Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Level of Mana Flare Hero for (Triggering unit)) Equal to 1
-
-
Then - Actions
-
Unit Group - Add (Target unit of ability being cast) to ManaFlare1Group[(Player number of (Owner of (Triggering unit)))]
-
-
Else - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Level of Mana Flare Hero for (Triggering unit)) Equal to 2
-
-
Then - Actions
-
Unit Group - Add (Target unit of ability being cast) to ManaFlare2Group[(Player number of (Owner of (Triggering unit)))]
-
-
Else - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Level of Mana Flare Hero for (Triggering unit)) Equal to 3
-
-
Then - Actions
-
Unit Group - Add (Target unit of ability being cast) to ManaFlare3Group[(Player number of (Owner of (Triggering unit)))]
-
-
Else - Actions
-
-
-
-
-
-
-
-
Mana Flare Effect
-
Events
-
Unit - A unit Starts the effect of an ability
-
-
Conditions
-
((Triggering unit) has buff Mana Flare (Extra)) Equal to True
-
-
Actions
-
For each (Integer FlareLoop2) from 1 to 12, do (Actions)
-
Loop - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
((Triggering unit) is in ManaFlare1Group[FlareLoop2]) Equal to True
-
-
Then - Actions
-
Unit - Create 1 Dummy for (Player(FlareLoop2)) at (Position of (Triggering unit)) facing Default building facing degrees
-
Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
-
Unit - Cause (Last created unit) to damage (Triggering unit), dealing 15.00 damage of attack type Spells and damage type Cold
-
-
Else - Actions
-
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
((Triggering unit) is in ManaFlare2Group[FlareLoop2]) Equal to True
-
-
Then - Actions
-
Unit - Create 1 Dummy for (Player(FlareLoop2)) at (Position of (Triggering unit)) facing Default building facing degrees
-
Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
-
Unit - Cause (Last created unit) to damage (Triggering unit), dealing 30.00 damage of attack type Spells and damage type Cold
-
-
Else - Actions
-
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
((Triggering unit) is in ManaFlare3Group[FlareLoop2]) Equal to True
-
-
Then - Actions
-
Unit - Create 1 Dummy for (Player(FlareLoop2)) at (Position of (Triggering unit)) facing Default building facing degrees
-
Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
-
Unit - Cause (Last created unit) to damage (Triggering unit), dealing 45.00 damage of attack type Spells and damage type Cold
-
-
Else - Actions
-
-
-
-
-
Instead you can just do:
VERSION 1:
-
Mana Flare
-
Events
-
Unit - A unit Starts the effect of an ability
-
-
Conditions
-
(Ability being cast) Equal to Mana Flare Hero
-
-
Actions
-
For each (Integer FlareLoop1) from 1 to 3, do (Actions)
-
Loop - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Level of Mana Flare Hero for (Triggering unit)) Equal to FlareLoop1
-
-
Then - Actions
-
Unit Group - Add (Target unit of ability being cast) to ManaFlareGroup[((((Player number of (Owner of (Triggering unit))) - 1) x 3) + FlareLoop1)]
-
-
Else - Actions
-
-
-
-
-
-
Mana Flare Effect
-
Events
-
Unit - A unit Starts the effect of an ability
-
-
Conditions
-
((Triggering unit) has buff Mana Flare (Extra)) Equal to True
-
-
Actions
-
For each (Integer FlareLoop2) from 1 to 12, do (Actions)
-
Loop - Actions
-
For each (Integer FlareLoop3) from 1 to 3, do (Actions)
-
Loop - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
((Triggering unit) is in ManaFlareGroup[(((FlareLoop2 - 1) x 3) + FlareLoop3)]) Equal to True
-
-
Then - Actions
-
Unit - Create 1 Dummy for (Player(FlareLoop2)) at (Position of (Triggering unit)) facing Default building facing degrees
-
Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
-
Unit - Cause (Last created unit) to damage (Triggering unit), dealing (15.00 x (Real(FlareLoop3))) damage of attack type Spells and damage type Cold
-
-
Else - Actions
-
-
-
-
-
-
-
-
Mana Flare
-
Events
-
Unit - A unit Starts the effect of an ability
-
-
Conditions
-
(Ability being cast) Equal to Mana Flare Hero
-
-
Actions
-
For each (Integer FlareLoop1) from 1 to 3, do (Actions)
-
Loop - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Level of Mana Flare Hero for (Triggering unit)) Equal to FlareLoop1
-
-
Then - Actions
-
Unit Group - Add (Target unit of ability being cast) to ManaFlareGroup[(((FlareLoop1 - 1) x 12) + (Player number of (Owner of (Triggering unit))))]
-
-
Else - Actions
-
-
-
-
-
-
Mana Flare Effect
-
Events
-
Unit - A unit Starts the effect of an ability
-
-
Conditions
-
((Triggering unit) has buff Mana Flare (Extra)) Equal to True
-
-
Actions
-
For each (Integer FlareLoop2) from 1 to 12, do (Actions)
-
Loop - Actions
-
For each (Integer FlareLoop3) from 1 to 3, do (Actions)
-
Loop - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
((Triggering unit) is in ManaFlareGroup[(((FlareLoop3 - 1) x 12) + FlareLoop2)]) Equal to True
-
-
Then - Actions
-
Unit - Create 1 Dummy for (Player(FlareLoop2)) at (Position of (Triggering unit)) facing Default building facing degrees
-
Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
-
Unit - Cause (Last created unit) to damage (Triggering unit), dealing (15.00 x (Real(FlareLoop3))) damage of attack type Spells and damage type Cold
-
-
Else - Actions
-
-
-
-
-
-
-
NOTES:
1) This technique can be used for Units and for Items too, it's not limited to Unit Groups.
2) Using the "normal way" takes many variables with 13 levels (or 12 if you are writing -1), while this method takes 12*(groups needed per player)+1. Don't forget to make your arrays big enough.
3) The number "*3" in this example varries, based on how many levels the ability has, if it has 9 levels, it should be changed to 9.
EDIT:
Wietlol reminded me that I didn't EXPLAIN what I was doing, and I just showed what to do, therefore I will add this to the Original post
If you want to use multiple dimensional arrays (you do have a reason for it otherwise you wouldnt be here), then you can make one array and calculate the total length of one of the dimensions.
For example, you want to store 5 variables per player.
Then you have a max of either 5 (5 variables) or 16 (16 players).
Visualizing the data would make a table of 5x16:
x Player 1 Player 2 Player 3 Player 4 Player 5 Player 6 Player 7 Player 8 Player 9 Player 10 Player 11 Player 12 Player 13 Player 14 Player 15 Player 16
Variable 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15Variable 2 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31Variable 3 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47Variable 4 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63Variable 5 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
Any cell can be accessed by the formula (x + y*XMAX).
XMAX is a constant defining the maximum length of a row (16).
x and y are the coordinates in their axis.
So variable 2 of player 9 will be
x = 8 (because player 1 is the 0th index)
y = 1 (because variable 1 is the 0th index)
XMAX = 16
x + y*XMAX = 8 + 1*16 = 24.
Now you count the slots in the table and find out that counting from left to right, from top to bottom, starting at 0, 24 will be the second variable of player 9.
Optionally, you can do the same formula backwards:
Index = (x + y*XMAX)
y = Index / XMAX (Because it is an integer, it will be rounded down to the nearest round number.)
x = ModuloInteger(Index, XMAX) < Modulo is a function in WE (But also everywhere else)
Now, you can make one array that will contain all your pretty data for every player.
Last edited: