• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] This trigger just won't work!

Status
Not open for further replies.
Level 4
Joined
Jul 31, 2013
Messages
50
I'm making the bases of a management map (maybe I'll even make a whole game on it!), that makes it so that each unit has a Title, Name, Grade, Kill Count, Age, Attack Aptitude, Health Aptitude, Food Cost (not the wc3 food), Gold Cost, Luxury resources Cost, Loyalty and Max Loyalty. Titles and Names are just for display, Grades determine costs and loyalties, and need to be defined with the command:
-define grade_name grade_priority food_cost gold_cost luxury_cost invtry_slots
But when I try to use this, it doesn't work. Please have a look at my triggers and
let me know if there's something I should change...
 

Attachments

  • complex unit system.w3x
    30.8 KB · Views: 63
Level 3
Joined
Mar 5, 2016
Messages
25
there is so sooo much problem in triggers so im leaving to pros (sry to lazy atleast im leaving the triggers here )


  • main lol
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set entitlelimit = 400
      • Set Unitcounter = 1
      • For each (Integer B) from 1 to 20, do (Actions)
        • Loop - Actions
          • Set Grade_food[(Integer A)] = 0
          • Set Grade_luxu[(Integer A)] = 0
          • Set Grade_priority[(Integer A)] = 0
          • Set Grade_wage[(Integer A)] = 0
          • Set Grade_value[(Integer A)] = 0
          • Set Grade_insl[(Integer A)] = 1
      • For each (Integer A) from 1 to entitlelimit, do (Actions)
        • Loop - Actions
          • Set Units[(Integer A)] = No unit
          • Set Unitsgrade[(Integer A)] = Civilian
          • Set Unitsnick[(Integer A)] = <Empty String>
          • Set Unitstitle[(Integer A)] = <Empty String>
          • Set Unit_prio[(Integer A)] = 0
          • Set Unit_prio[(Integer A)] = 0
          • Set Unit_wage[(Integer A)] = 0
          • Set Unit_food[(Integer A)] = 0
          • Set Unit_kills[(Integer A)] = 0
          • Set Unit_luxu[(Integer A)] = 0
          • Set Units_loya[(Integer A)] = 0
          • Set Units_malo[(Integer A)] = 0
          • Set Unit_luxu[(Integer A)] = 0
  • Defining
    • Events
      • Player - Player 1 (Red) types a chat message containing -define as A substring
    • Conditions
    • Actions
      • For each (Integer Gradecounter) from 1 to 20, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Substring((Entered chat string), 9, 18)) Equal to Grade_name[Gradecounter]
            • Then - Actions
              • Game - Display to Player Group - Player 1 (Red) the text: (Grade_name[Gradecounter] + is already used!!!)
              • Set Gradecounter = 101
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Grade_name[Gradecounter] Equal to <Empty String>
                • Then - Actions
                  • Set tempstring = (Entered chat string)
                  • Set Grade_priority[Gradecounter] = (Integer((Substring(tempstring, 20, 21))))
                  • Set Grade_food[Gradecounter] = (Integer((Substring(tempstring, 23, 25))))
                  • Set Grade_wage[Gradecounter] = (Integer((Substring(tempstring, 27, 29))))
                  • Set Grade_luxu[Gradecounter] = (Integer((Substring(tempstring, 31, 33))))
                  • Set Grade_insl[Gradecounter] = (Integer((Substring(tempstring, 35, 36))))
                  • Set Grade_value[Gradecounter] = (Grade_food[Gradecounter] + (Grade_wage[Gradecounter] x 3))
                  • Set Grade_value[Gradecounter] = (Grade_value[Gradecounter] + (Grade_luxu[Gradecounter] x 10))
                  • Set Grade_value[Gradecounter] = ((Grade_value[Gradecounter] - 100) + (Grade_insl[Gradecounter] x 100))
                  • For each (Integer Gradecounter2) from 1 to 20, do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • And - All (Conditions) are true
                            • Conditions
                              • Grade_priority[Gradecounter] Greater than Grade_priority[Gradecounter2]
                              • Grade_value[Gradecounter] Greater than Grade_value[Gradecounter2]
                              • Gradecounter2 Not equal to Gradecounter
                        • Then - Actions
                          • Set Grade_name[Gradecounter] = (Substring((Entered chat string), 9, 20))
                          • Game - Display to Player Group - Player 1 (Red) the text: (You have created the grade + Grade_name[Gradecounter])
                          • Set Gradecounter = 101
                          • Set Gradecounter2 = 101
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • And - All (Conditions) are true
                                • Conditions
                                  • Grade_priority[Gradecounter] Less than Grade_priority[Gradecounter2]
                                  • Grade_value[Gradecounter] Less than Grade_value[Gradecounter2]
                                  • Gradecounter2 Not equal to Gradecounter
                            • Then - Actions
                              • Set Grade_name[Gradecounter] = (Substring((Entered chat string), 9, 21))
                              • Game - Display to Player Group - Player 1 (Red) the text: (You have created the grade + Grade_name[Gradecounter])
                              • Set Gradecounter = 101
                              • Set Gradecounter2 = 101
                            • Else - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • And - All (Conditions) are true
                                    • Conditions
                                      • Grade_priority[Gradecounter] Equal to Grade_priority[Gradecounter2]
                                      • Gradecounter2 Not equal to Gradecounter
                                • Then - Actions
                                  • Set Grade_name[Gradecounter] = (Substring((Entered chat string), 9, 21))
                                  • Game - Display to Player Group - Player 1 (Red) the text: (You have created the grade + Grade_name[Gradecounter])
                                  • Set Gradecounter = 101
                                  • Set Gradecounter2 = 101
                                • Else - Actions
                                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    • If - Conditions
                                      • Gradecounter2 Equal to 20
                                    • Then - Actions
                                      • Game - Display to Player Group - Player 1 (Red) the text: This grade is eithe...
                                      • Set Grade_value[Gradecounter] = 0
                                      • Set Gradecounter = 101
                                    • Else - Actions
                                      • Set Grade_value[Gradecounter] = 0
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Gradecounter Equal to 100
                    • Then - Actions
                      • Game - Display to Player Group - Player 1 (Red) the text: You have reached th...
                    • Else - Actions
  • Putting units in the unit index
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • ((Entering unit) is Polymorphed) Equal to False
              • ((Entering unit) is Summoned) Equal to False
              • ((Entering unit) is A structure) Equal to False
        • Then - Actions
          • For each (Integer Unitcounter) from 1 to (entitlelimit - 1), do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Units[Unitcounter] Equal to No unit
                • Then - Actions
                  • Set Units[Unitcounter] = (Entering unit)
                  • Set UnitH[Unitcounter] = (Random integer number between 1 and 10)
                  • Set UnitA[Unitcounter] = (Random integer number between 1 and 10)
                  • Set Unit_Age[Unitcounter] = (Random integer number between 15 and 31)
                  • Floating Text - Create floating text that reads (Unitstitle[Unitcounter] + Unitsnick[Unitcounter]) above Units[Unitcounter] with Z offset 40.00, using font size 8.00, color (80.00%, 80.00%, 80.00%), and 0.00% transparency
                  • Set Unitsname[Unitcounter] = (Last created floating text)
                  • Floating Text - Create floating text that reads Unitsgrade[Unitcounter] above (Picked unit) with Z offset 0.00, using font size 8.00, color (80.00%, 80.00%, 80.00%), and 0.00% transparency
                  • Set Unitsg[Unitcounter] = (Last created floating text)
                  • Unit - Remove Unit Inventory (Undead) from Units[(Integer A)]
                  • Unit - Remove Unit Inventory (Night Elf) from Units[(Integer A)]
                  • Unit - Remove Unit Inventory (Orc) from Units[(Integer A)]
                  • Unit - Remove Unit Inventory (Human) from Units[(Integer A)]
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is A Hero) Equal to False
                    • Then - Actions
                      • Unit - Add Inventory (entitled) to Units[(Integer A)]
                    • Else - Actions
                  • Set Unitcounter = entitlelimit
                • Else - Actions
        • Else - Actions
  • Promoting
    • Events
      • Player - Player 1 (Red) types a chat message containing -promote as A substring
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units currently selected by Player 1 (Red)) and do (Actions)
        • Loop - Actions
          • For each (Integer promotecounter) from 1 to 100, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Substring((Entered chat string), 10, 21)) Equal to Grade_name[(Integer B)]
                • Then - Actions
                  • For each (Integer A) from 1 to entitlelimit, do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Unit_prio[(Integer A)] Less than Grade_priority[(Integer B)]
                        • Then - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Picked unit) Equal to Units[(Integer A)]
                            • Then - Actions
                              • Floating Text - Destroy Unitsg[(Integer A)]
                              • Floating Text - Create floating text that reads (Unitsgrade[(Integer A)] + Unitsnick[(Integer A)]) above Units[(Integer A)] with Z offset 0.00, using font size 8.00, color (80.00%, 80.00%, 80.00%), and 0.00% transparency
                              • Set Unitsname[(Integer A)] = (Last created floating text)
                            • Else - Actions
                        • Else - Actions
                • Else - Actions
                  • Game - Display to Player Group - Player 1 (Red) the text: There is no such gr...
                  • Set promotecounter = 101
  • Changing Nicks
    • Events
      • Player - Player 1 (Red) types a chat message containing -n as A substring
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units currently selected by Player 1 (Red)) and do (Actions)
        • Loop - Actions
          • For each (Integer A) from 1 to entitlelimit, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked unit) Equal to Units[(Integer A)]
                • Then - Actions
                  • Floating Text - Destroy Unitsname[(Integer A)]
                  • Set Unitsnick[(Integer A)] = (Substring((Entered chat string), 3, 20))
                  • Floating Text - Create floating text that reads (Unitstitle[(Integer A)] + Unitsnick[(Integer A)]) above Units[(Integer A)] with Z offset 40.00, using font size 8.00, color (80.00%, 80.00%, 80.00%), and 0.00% transparency
                  • Set Unitsname[(Integer A)] = (Last created floating text)
                • Else - Actions
  • Events
    • Player - Player 1 (Red) types a chat message containing -t as A substring
  • Texts
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to entitlelimit, do (Actions)
        • Loop - Actions
          • Floating Text - Change the position of Unitsname[(Integer A)] to Units[(Integer A)] with Z offset 40.00
          • Floating Text - Change the position of Unitsg[(Integer A)] to Units[(Integer A)] with Z offset 0.00
  • Combat
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • For each (Integer A) from 1 to entitlelimit, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Attacked unit) Equal to Units[(Integer A)]
            • Then - Actions
              • Set random = (Random integer number between 1 and 2)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • And - All (Conditions) are true
                    • Conditions
                      • random Equal to 1
                • Then - Actions
                  • Hero - Create Health Leveling 1 and give it to (Attacked unit)
                • Else - Actions
              • Set random3 = (Random integer number between 1 and (30 - UnitH[(Integer A)]))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • random3 Less than 2
                • Then - Actions
                  • Hero - Create Health Leveling 8 and give it to (Attacked unit)
                • Else - Actions
            • Else - Actions
      • For each (Integer A) from 1 to entitlelimit, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Attacking unit) Equal to Units[(Integer A)]
            • Then - Actions
              • Set random2 = (Random integer number between 1 and 9)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • random2 Equal to 1
                • Then - Actions
                  • Hero - Create Attack Leveling 1 and give it to (Attacking unit)
                • Else - Actions
              • Set random4 = (Random integer number between 1 and (30 - UnitA[(Integer A)]))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • random4 Less than 2
                • Then - Actions
                  • Hero - Create Attack Leveling 3 and give it to (Attacking unit)
                • Else - Actions
            • Else - Actions
  • Killing
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set random5 = (Random integer number between 1 and 7)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • random5 Equal to 7
        • Then - Actions
          • Set random6 = (Random integer number between 1 and 2)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • random6 Equal to 1
            • Then - Actions
              • For each (Integer A) from 1 to entitlelimit, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Killing unit) Equal to Units[(Integer A)]
                    • Then - Actions
                      • Set UnitA[(Integer A)] = (UnitA[(Integer A)] + 1)
                    • Else - Actions
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • random6 Equal to 2
                • Then - Actions
                  • For each (Integer A) from 1 to entitlelimit, do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Killing unit) Equal to Units[(Integer A)]
                        • Then - Actions
                          • Set UnitH[(Integer A)] = (UnitH[(Integer A)] + 1)
                        • Else - Actions
                • Else - Actions
        • Else - Actions
  • Stats
    • Events
      • Player - Player 1 (Red) types a chat message containing -stats as An exact match
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units currently selected by Player 1 (Red)) and do (Actions)
        • Loop - Actions
          • For each (Integer A) from 1 to entitlelimit, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked unit) Equal to Units[(Integer A)]
                • Then - Actions
                  • Game - Display to Player Group - Player 1 (Red) for 10.00 seconds the text: (Title & Name: + (Unitstitle[(Integer A)] + Unitsnick[(Integer A)]))
                  • Game - Display to Player Group - Player 1 (Red) for 10.00 seconds the text: (Grade: + (Unitsgrade[(Integer A)] + ( ( + ((String(Unit_prio[(Integer A)])) + )))))
                  • Game - Display to Player Group - Player 1 (Red) for 10.00 seconds the text: (Loyalty: + ((String(Units_loya[(Integer A)])) + (/ + (String(Units_malo[(Integer A)])))))
                  • Game - Display to Player Group - Player 1 (Red) for 10.00 seconds the text: (Kills: + (String(Unit_kills[(Integer A)])))
                  • Game - Display to Player Group - Player 1 (Red) for 10.00 seconds the text: (Health Aptitude: + (String(UnitH[(Integer A)])))
                  • Game - Display to Player Group - Player 1 (Red) for 10.00 seconds the text: (Attack Aptitude: + (String(UnitA[(Integer A)])))
                  • Game - Display to Player Group - Player 1 (Red) for 10.00 seconds the text: (Periodical Cost: + (((String(Unit_food[(Integer A)])) + /) + ((String(Grade_wage[(Integer A)])) + (/ + (String(Unit_luxu[(Integer A)]))))))
                  • Game - Display to Player Group - Player 1 (Red) for 10.00 seconds the text: (Age: + (String(Unit_Age[(Integer A)])))
                • Else - Actions
  • cleaning
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to entitlelimit, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Units[(Integer A)] is alive) Equal to False
            • Then - Actions
              • Set Units[(Integer A)] = No unit
              • Set Unitsgrade[(Integer A)] = Civilian
              • Set Unitsnick[(Integer A)] = <Empty String>
              • Set Unitstitle[(Integer A)] = <Empty String>
              • Set Unit_prio[(Integer A)] = 0
              • Set Unit_wage[(Integer A)] = 0
              • Set Unit_food[(Integer A)] = 0
              • Set Unit_kills[(Integer A)] = 0
              • Set Unit_luxu[(Integer A)] = 0
              • Floating Text - Destroy Unitsname[(Integer A)]
              • Floating Text - Destroy Unitsg[(Integer A)]
            • Else - Actions
 
Level 3
Joined
Mar 5, 2016
Messages
25
btw try to use Variables for those (stats) cause food gold lumber can be broke at middle of games and when you need to see stats just make player type -stats or something so it will more easy for you
 
Level 29
Joined
Sep 26, 2009
Messages
2,596
I can see that you put a lot of work in those trigger, however there are some serious error which make them really bad function-wise and efficiency-wise.

The most important thing first is to actually make a check for the entered chat substrings!

Most your trigger are fired by writing some text and you use substring of that text to fire the trigger. However you do not make any check for what is written. So if I were to write the following:
"-n-promote-define" I may very well end up crashing your game. The whole text contains all valid substrings "-n", "-promote" and "-define".

So what you should do is something like this:
  • Events
    • Player - Player 1 (Red) types a chat message containing -define as A substring
  • Conditions
    • (Substring((Entered chat string), 0, 7)) Equal to "-define "
  • Actions
    • ...
or so and do that for all the other triggers which fire when substring is entered into chat.

Map initialization trigger:
There is no need to initialize anything via those loops, as everything is initialized with a default (null) value.
Null value for integers is 0, null value for string is <empty string>, null value for unit is "No unit". Hence initializing it over again is just a waste of resources.

So the only things that would need to be initialized are actually Grade_insl[] and Unitsgrade[] arrays, as those do not use the null value.
Then again, this can be set in the variable editor.
For Grade_insl[] set default value 1 and size 20 to initialize this value in the first 20 slots; and set default value Civilian for Unitsgrade[] and set size 400.


Defining trigger:
Instead of doing this:
  • For each (Integer Gradecounter) from 1 to 20, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Substring((Entered chat string), 9, 18)) Equal to Grade_name[Gradecounter]
        • etc.
I would first save the substring into a variable and then compare the variable. Like this:
  • Set subst = (Substring((Entered chat string), 9, 18))
  • For each (Integer Gradecounter) from 1 to 20, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • subst Equal to Grade_name[Gradecounter]
        • etc.
The difference is that you create the substring 20 times (once for each iteration of the loop while doing it the way I showed creates the substring only once and then it compares that same substring 20 times, so you don't waste your pc's power on computing the same over and over again.

Next, the entire section where you start with this piece of script:
  • For each (Integer Gradecounter2) from 1 to 20, do (Actions)
    • Loop - Actions
should be changed to a more logical order so you avoid using the same actions all over the place.
Also, I'm not sure if this is intentional or not, but in the first two ITEs, you compare both these values:
  • Grade_priority[Gradecounter] Less than / Greater than Grade_priority[Gradecounter2]
    • Grade_value[Gradecounter] Less than / Greater than Grade_value[Gradecounter2]
But in the third ITE you only compare
  • Grade_priority[Gradecounter] Equal to Grade_priority[Gradecounter2]
and no longer do you compare Grade_value. Is this intentional?

Next, since you do this everywhere in the trigger:
  • Set Gradecounter = 101
Then the following code will never execute the "Then" block as the condition will always return false:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Gradecounter Equal to 100
    • Then - Actions
      • Game - Display to Player Group - Player 1 (Red) the text: You have reached th...
    • Else - Actions

Putting units in the unit index
This is one of the less efficient triggers.
First of all, you set "entitlelimit" variable to 400, but is the 400th slot anything special which should not be touched? Because you loop "from 1 to (entitlelimit - 1)", so basically from 1 to 399.

Then there are these actions:
  • Unit - Remove Unit Inventory (Undead) from Units[(Integer A)]
  • Unit - Remove Unit Inventory (Night Elf) from Units[(Integer A)]
  • Unit - Remove Unit Inventory (Orc) from Units[(Integer A)]
  • Unit - Remove Unit Inventory (Human) from Units[(Integer A)]
You use (Integer A) when your loop uses Unitcounter

And these:
  • Floating Text - Create floating text that reads Unitsgrade[Unitcounter] above (Picked unit) with Z offset 0.00, using font size 8.00, color (80.00%, 80.00%, 80.00%), and 0.00% transparency
  • ...
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • ((Picked unit) is A Hero) Equal to False
    • Then - Actions
      • Unit - Add Inventory (entitled) to Units[(Integer A)]
    • Else - Actions
These do stuff with (Picked unit) when there is no picked unit (since you're in For loop, not Unit Group loop) and you once again use (Integer A) as index for unit when your index is Unitcounter.

Now these things aside, a more important thing needs to be asked: Is there always 400 units in the map?
If not, you should consider using dynamic indexing. With dynamic indexing, you would index and keep count of only the actual units, not all possible slots for units.
Check this tutorial - http://www.hiveworkshop.com/forums/...orials-279/visualize-dynamic-indexing-241896/ to learn how to use dynamic indexing.


Promoting trigger
First, you leak unit group.
Second, you use (Integer B) as index, when your loops don't use (Integer B).
Third, I have no idea what you are trying to achieve there, but the worst-case scenario is that you make a 40 000-time loop for each unit player has in selection. I can assure you that there is most likely a far better way than 40 000 loops.


Changing Nicks trigger
You leak unit group.
Now I cannot say if your trigger here is bad efficiency-wise or not, as I have no idea how your map is set up (like if entitlelimit is for each player alone or for all players together, etc., so I cannot say if there is better way to organize things or not)


Texts trigger
Worst trigger in the posted triggers.
As I said before I have no idea if you always have 400 units in map, or if it is simply a maximum number of units you can have. However if it is the latter, you should immediately change to from what you have to dynamic indexing.
Basically imagine you have only 20 unit in your map. This trigger of your goes from 1 to 400, but since you only have 20 units, it runs 380 times for no reason - and it does that every 0.03 seconds!
That's 12667 useless iterations PER SECOND!

Now not only that, but you also leak 2 locations per each unit. Considering the worst-case scenario (400 units in your map) that would be 26 667 leaks per second. That is really lot and even if you didn't have 400 units but only for example 50, it would eventually lag your map so bad that it would be unplayable.

Last but not least, I think there is a limit to how many floating texts can be in game and i think the limit is far below 400, so I don't think all your units would have any floating text above them.


Combat trigger
This requires Damage Detection System (DDS) not a "unit is attacked" event.
The difference is that DDS catches when a unit actually deals the damage, while on the other hand the "unit is attacked" fire when a unit starts attacking (e.g. starts swinging sword) which is usually an offset from the actual damage dealt some time (more so if we talk about ranged unit like night elf Archer, who fires the "unit is attacked" even when it prepares to fire an arrow, which is far sooner than when the arrow hits the target).

Not only is that a problem, you can even re-fire the event by simply press the "Stop" button for the unit before it lands the attack. Due to any units AI (it tried to auto-attack enemies) you can quite easily spam the event even if none of your attacks hit.
So use a DDS instead. Far better choice.

Next thing: Place both the stuff for (attacked unit) and (attacking unit) into the same loop.
For each attack you loop up to 800 times for no reason. If you need to do it this way (I once again advise you to use dynamic indexing), at least half the amount of iterations to 400.

Also, use the same variable "random" instead of 4 different variables. When you set random number to the variable and check it to determine if you're gonna give someone an item or not, then you're done with that number. So re-use the variable again. Also, the "Condition" block is by default an "And" block, so putting the "And" block there is useless and unneeded.
E.g. something like this:
  • Set random = (Random integer number between 1 and 2)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
    • And - All (Conditions) are true
      • Conditions
        • random Equal to 1
    • Then - Actions
      • Hero - Create Health Leveling 1 and give it to (Attacked unit)
    • Else - Actions
  • Set random = (Random integer number between 1 and (30 - UnitH[(Integer A)]))
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • random Less than 2
    • Then - Actions
      • Hero - Create Health Leveling 8 and give it to (Attacked unit)
    • Else - Actions

Killing trigger
Re-organise the trigger.
Instead of doing:
Code:
If
    random6 = 1
Then
    Loop 400 times to change value of UnitA
Else
    If
        random6 = 2
    Then
        Loop 400 times to change value of UnitH
    Else
which makes no sense at all, as you pick a random number between 1 and 2 so if your number is not 1 then it obviously has to be number 2 (so checking again if number is equal to 2 is redundant), you can change it to simpler and easier to read code:

Code:
random6 = random number between 1 and 2
Loop 400 times
    if
        random6 = 1
    Then
        Change value for UnitA
    Else
        Change value for UnitH


Stats trigger
This leaks unit group.
This iterates 400 times for each selected unit for no reason (e.g. the condition "(Picked unit) Equal to Units[(Integer A)]" is true when (Integer A) is equal to for example 1, yet you still iterate even the 399 times)



cleaning trigger
Completely useless trigger.
This should be done only once and when unit dies.
The condition:
  • If - Conditions
    • (Units[(Integer A)] is alive) Equal to False
returns "False" even if Units[(Integer A)] is null (or no unit). In this case, you set the values to 0 for each non-existent unit over and over and over... not a good idea.
 
Status
Not open for further replies.
Top