[Trigger] Help checking if triggers are leakless

Status
Not open for further replies.
Level 13
Joined
Sep 25, 2013
Messages
717
Hello! Ive made a resource system with many triggers. My map seems to lag a bit and i'm not sure where its coming from. Can you tell if there are leaks in these triggers? Any help is appreciated, thank you!

This trigger causes trade caravans to produce gold. When they get to a fortress they generate gold based off of how far they are from your market. Also, allied fortresses produce more gold.


  • Trade Caravan Generate Gold
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set tempUnitGroup3 = (Units in (Playable map area) matching (((Matching unit) has buff Trade Caravan (All)) Equal to True))
      • Unit Group - Pick every unit in tempUnitGroup3 and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) has buff Trading Post (Market)(All)) Equal to True
              • ((Picked unit) has an item of type Trade Goods) Equal to False
            • Then - Actions
              • Special Effect - Create a special effect attached to the overhead of (Picked unit) using Abilities\Spells\Items\AIsm\AIsmTarget.mdl
              • Special Effect - Destroy (Last created special effect)
              • Hero - Create Trade Goods and give it to (Picked unit)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) has buff Trading Post (Fortress)(Owner)) Equal to True
                  • ((Picked unit) has buff Trading Post (Fortress)(Ally)) Equal to False
                  • ((Picked unit) has an item of type Trade Goods) Equal to True
                • Then - Actions
                  • Set tempUnitGroup = (Units within 500.00 of (Position of (Picked unit)) matching (((Matching unit) has buff Fortress (All)) Equal to True))
                  • Unit - Move (Picked unit) instantly to (Position of (Random unit from tempUnitGroup))
                  • Set tempUnitGroup2 = (Units in (Playable map area) matching (((Owner of (Matching unit)) Equal to (Owner of (Picked unit))) and (((Matching unit) has buff Market (All)) Equal to True)))
                  • Set tempPoint = (Position of (Random unit from tempUnitGroup2))
                  • Set tempPoint2 = (Position of (Picked unit))
                  • Set tempReal = (Distance between tempPoint and tempPoint2)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • tempReal Greater than or equal to 11200.00
                    • Then - Actions
                      • Set tempInteger = 100
                      • Special Effect - Create a special effect attached to the overhead of (Picked unit) using Abilities\Spells\Items\AIsm\AIsmTarget.mdl
                      • Special Effect - Destroy (Last created special effect)
                      • Hero - Drop (Item carried by (Picked unit) of type Trade Goods) from (Picked unit)
                      • Item - Remove (Last dropped item)
                      • Unit - Order (Picked unit) to Patrol To tempPoint
                      • Set tempId = (Player number of (Owner of (Picked unit)))
                      • Set OHS_OilResource[tempId] = (OHS_OilResource[tempId] + tempInteger)
                      • Floating Text - Create floating text that reads (+ + ((String(tempInteger)) + Gold)) at tempPoint2 with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
                      • Set tempFloatingText = (Last created floating text)
                      • Floating Text - Set the velocity of tempFloatingText to 64.00 towards 90.00 degrees
                      • Floating Text - Change tempFloatingText: Disable permanence
                      • Floating Text - Change the lifespan of tempFloatingText to 3.00 seconds
                      • Floating Text - Change the fading age of tempFloatingText to 0.01 seconds
                      • Custom script: call RemoveLocation (udg_tempPoint)
                      • Custom script: call DestroyGroup (udg_tempUnitGroup)
                      • Custom script: call RemoveLocation (udg_tempPoint2)
                      • Custom script: call DestroyGroup (udg_tempUnitGroup2)
                    • Else - Actions
                      • Set tempInteger = ((Integer(tempReal)) / 500)
                      • Set tempInteger = (tempInteger x tempInteger)
                      • Set tempInteger = (tempInteger / 5)
                      • Special Effect - Create a special effect attached to the overhead of (Picked unit) using Abilities\Spells\Items\AIsm\AIsmTarget.mdl
                      • Special Effect - Destroy (Last created special effect)
                      • Hero - Drop (Item carried by (Picked unit) of type Trade Goods) from (Picked unit)
                      • Item - Remove (Last dropped item)
                      • Unit - Order (Picked unit) to Patrol To tempPoint
                      • Set tempId = (Player number of (Owner of (Picked unit)))
                      • Set OHS_OilResource[tempId] = (OHS_OilResource[tempId] + tempInteger)
                      • Floating Text - Create floating text that reads (+ + ((String(tempInteger)) + Gold)) at tempPoint2 with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
                      • Set tempFloatingText = (Last created floating text)
                      • Floating Text - Set the velocity of tempFloatingText to 64.00 towards 90.00 degrees
                      • Floating Text - Change tempFloatingText: Disable permanence
                      • Floating Text - Change the lifespan of tempFloatingText to 3.00 seconds
                      • Floating Text - Change the fading age of tempFloatingText to 0.01 seconds
                      • Custom script: call RemoveLocation (udg_tempPoint)
                      • Custom script: call DestroyGroup (udg_tempUnitGroup)
                      • Custom script: call RemoveLocation (udg_tempPoint2)
                      • Custom script: call DestroyGroup (udg_tempUnitGroup2)
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) has buff Trading Post (Fortress)(Ally)) Equal to True
                      • ((Picked unit) has an item of type Trade Goods) Equal to True
                    • Then - Actions
                      • Set tempUnitGroup = (Units within 500.00 of (Position of (Picked unit)) matching (((Matching unit) has buff Fortress (All)) Equal to True))
                      • Unit - Move (Picked unit) instantly to (Position of (Random unit from tempUnitGroup))
                      • Set tempUnitGroup2 = (Units in (Playable map area) matching (((Owner of (Matching unit)) Equal to (Owner of (Picked unit))) and (((Matching unit) has buff Market (All)) Equal to True)))
                      • Set tempPoint = (Position of (Random unit from tempUnitGroup2))
                      • Set tempPoint2 = (Position of (Picked unit))
                      • Set tempReal = (Distance between tempPoint and tempPoint2)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • tempReal Greater than or equal to 11200.00
                        • Then - Actions
                          • Set tempInteger = 100
                          • Special Effect - Create a special effect attached to the overhead of (Picked unit) using Abilities\Spells\Items\AIsm\AIsmTarget.mdl
                          • Special Effect - Destroy (Last created special effect)
                          • Hero - Drop (Item carried by (Picked unit) of type Trade Goods) from (Picked unit)
                          • Item - Remove (Last dropped item)
                          • Unit - Order (Picked unit) to Patrol To tempPoint
                          • Set tempId = (Player number of (Owner of (Picked unit)))
                          • Set OHS_OilResource[tempId] = (OHS_OilResource[tempId] + tempInteger)
                          • Floating Text - Create floating text that reads (+ + ((String(tempInteger)) + Gold)) at tempPoint2 with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
                          • Set tempFloatingText = (Last created floating text)
                          • Floating Text - Set the velocity of tempFloatingText to 64.00 towards 90.00 degrees
                          • Floating Text - Change tempFloatingText: Disable permanence
                          • Floating Text - Change the lifespan of tempFloatingText to 3.00 seconds
                          • Floating Text - Change the fading age of tempFloatingText to 0.01 seconds
                          • Custom script: call RemoveLocation (udg_tempPoint)
                          • Custom script: call DestroyGroup (udg_tempUnitGroup)
                          • Custom script: call RemoveLocation (udg_tempPoint2)
                          • Custom script: call DestroyGroup (udg_tempUnitGroup2)
                        • Else - Actions
                          • Set tempInteger = ((Integer(tempReal)) / 460)
                          • Set tempInteger = (tempInteger x tempInteger)
                          • Set tempInteger = (tempInteger / 5)
                          • Special Effect - Create a special effect attached to the overhead of (Picked unit) using Abilities\Spells\Items\AIsm\AIsmTarget.mdl
                          • Special Effect - Destroy (Last created special effect)
                          • Hero - Drop (Item carried by (Picked unit) of type Trade Goods) from (Picked unit)
                          • Item - Remove (Last dropped item)
                          • Unit - Order (Picked unit) to Patrol To tempPoint
                          • Set tempId = (Player number of (Owner of (Picked unit)))
                          • Set OHS_OilResource[tempId] = (OHS_OilResource[tempId] + tempInteger)
                          • Floating Text - Create floating text that reads (+ + ((String(tempInteger)) + Gold)) at tempPoint2 with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
                          • Set tempFloatingText = (Last created floating text)
                          • Floating Text - Set the velocity of tempFloatingText to 64.00 towards 90.00 degrees
                          • Floating Text - Change tempFloatingText: Disable permanence
                          • Floating Text - Change the lifespan of tempFloatingText to 3.00 seconds
                          • Floating Text - Change the fading age of tempFloatingText to 0.01 seconds
                          • Custom script: call RemoveLocation (udg_tempPoint)
                          • Custom script: call DestroyGroup (udg_tempUnitGroup)
                          • Custom script: call RemoveLocation (udg_tempPoint2)
                          • Custom script: call DestroyGroup (udg_tempUnitGroup2)
                    • Else - Actions
      • Custom script: call DestroyGroup (udg_tempUnitGroup3)


This trigger causes workers with a mining speed upgrade to mine faster. It creates a unit with the bloodlust ability. Based on the workers buff level, it casts differing levels of bloodlust on the worker.


  • Gold Hit
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacking unit) has buff Worker (All)) Equal to True
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Gold Ore |cffffd700(1000 Gold)|r (Nature)
          • (Unit-type of (Triggering unit)) Equal to Gold Ore |cffffd700(2000 Gold)|r (Nature)
          • (Unit-type of (Triggering unit)) Equal to Gold Ore |cffffd700(3000 Gold)|r (Nature)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Worker (All) for (Attacking unit)) Equal to 1
        • Then - Actions
          • Set tempPoint = (Position of (Triggering unit))
          • Unit - Create 1 Nothing Unit for (Owner of (Attacking unit)) at tempPoint facing Default building facing degrees
          • Unit - Add Gold Miner (Nothing Unit) to (Last created unit)
          • Unit - Order (Last created unit) to Orc Shaman - Bloodlust (Attacking unit)
          • Unit - Remove (Last created unit) from the game
          • Special Effect - Create a special effect at tempPoint using UI\Feedback\GoldCredit\GoldCredit.mdl
          • Special Effect - Destroy (Last created special effect)
          • Custom script: call RemoveLocation(udg_tempPoint)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Worker (All) for (Attacking unit)) Equal to 2
            • Then - Actions
              • Set tempPoint = (Position of (Triggering unit))
              • Unit - Create 1 Nothing Unit for (Owner of (Attacking unit)) at tempPoint facing Default building facing degrees
              • Unit - Add Gold Miner (Nothing Unit) to (Last created unit)
              • Unit - Set level of Gold Miner (Nothing Unit) for (Last created unit) to 2
              • Unit - Order (Last created unit) to Orc Shaman - Bloodlust (Attacking unit)
              • Unit - Remove (Last created unit) from the game
              • Special Effect - Create a special effect at tempPoint using UI\Feedback\GoldCredit\GoldCredit.mdl
              • Special Effect - Destroy (Last created special effect)
              • Custom script: call RemoveLocation(udg_tempPoint)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Worker (All) for (Attacking unit)) Equal to 3
                • Then - Actions
                  • Set tempPoint = (Position of (Triggering unit))
                  • Unit - Create 1 Nothing Unit for (Owner of (Attacking unit)) at tempPoint facing Default building facing degrees
                  • Unit - Add Gold Miner (Nothing Unit) to (Last created unit)
                  • Unit - Set level of Gold Miner (Nothing Unit) for (Last created unit) to 3
                  • Unit - Order (Last created unit) to Orc Shaman - Bloodlust (Attacking unit)
                  • Unit - Remove (Last created unit) from the game
                  • Special Effect - Create a special effect at tempPoint using UI\Feedback\GoldCredit\GoldCredit.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Custom script: call RemoveLocation(udg_tempPoint)
                • Else - Actions


This trigger causes you to capture nearby pigs. It detects the number of allied units and enemy units around it. If there are more enemy units, it changes ownership to the enemy.


  • Pig Capture
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set tempUnitGroup = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Pig |cffff0000(100 Food)|r (Nature)))
      • Unit Group - Pick every unit in tempUnitGroup and do (Actions)
        • Loop - Actions
          • Set tempUnitGroup2 = (Units within 800.00 of (Position of (Picked unit)) matching ((((Matching unit) is A structure) Equal to False) and ((((Matching unit) is alive) Equal to True) and ((((Matching unit) has buff Animal (All)) Equal to False) and (((Unit-type of (Matching unit))
          • Set tempUnitGroup3 = (Units within 800.00 of (Position of (Picked unit)) matching ((((Matching unit) is A structure) Equal to False) and ((((Matching unit) is alive) Equal to True) and ((((Matching unit) has buff Animal (All)) Equal to False) and (((Unit-type of (Matching unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in tempUnitGroup2) Greater than (Number of units in tempUnitGroup3)
            • Then - Actions
              • Unit - Change ownership of (Picked unit) to (Owner of (Random unit from tempUnitGroup2)) and Change color
              • Special Effect - Create a special effect attached to the origin of (Picked unit) using Abilities\Spells\Other\Charm\CharmTarget.mdl
              • Special Effect - Destroy (Last created special effect)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in tempUnitGroup3) Greater than (Number of units in tempUnitGroup2)
                • Then - Actions
                • Else - Actions
          • Custom script: call DestroyGroup (udg_tempUnitGroup2)
          • Custom script: call DestroyGroup (udg_tempUnitGroup3)
      • Custom script: call DestroyGroup (udg_tempUnitGroup)
 
  • Unit - Move (Picked unit) instantly to (Position of (Random unit from tempUnitGroup))
^ leaks a point

  • Set tempUnitGroup = (Units within 500.00 of (Position of (Picked unit)) matching (((Matching unit) has buff Fortress (All)) Equal to True))
^ leaks a point

  • Unit - Move (Picked unit) instantly to (Position of (Random unit from tempUnitGroup))
^ leaks a point


You should also be storing data you reference a lot into variables. For example, in the Trade Caravan Generate Gold trigger, you call the fucntion GetEnumUnit() (equivalent to Picked unit) exactly 30 times. You can easily just store the unit into the variable and use that instead of (Picked unit). Another example is here:

  • Unit - Create 1 Nothing Unit for (Owner of (Attacking unit)) at tempPoint facing Default building facing degrees
  • Unit - Add Gold Miner (Nothing Unit) to (Last created unit)
  • Unit - Set level of Gold Miner (Nothing Unit) for (Last created unit) to 2
  • Unit - Order (Last created unit) to Orc Shaman - Bloodlust (Attacking unit)
  • Unit - Remove (Last created unit) from the game
You can store (Last created unit) into a variable instead of having to call the function 4 times.


If you're really desperate for a performance upgrade, you should avoid using (Matching unit) to filter out your unit groups and instead use an If/Then/Else inside the loop, comparing the (Picked unit) to your desired filters.
 
Level 13
Joined
Sep 25, 2013
Messages
717
Wow! Thank you so much for this! I didn't realize referencing picked unit and such could be demanding on systems! And i didn't think about saving the positions of random units for some reason, thank you!

Also, i heard that creating units continually, like i do in the gold mining trigger, causes leaks. If the dummy units i use are removed, does that still cause leaks? I made this newer trigger to try a different method. Instead of making a dummy unit each time something is triggered, i made it so theres a dummy unit on the map and it is moved to the triggering location and then i add the needed ability to it and remove the ability when the trigger is done. Is this better? Its the first if than else iteration that i made this new method, the others are the old way


  • Gold Hit
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacking unit) has buff Worker (All)) Equal to True
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Gold Ore |cffffd700(1000 Gold)|r (Nature)
          • (Unit-type of (Triggering unit)) Equal to Gold Ore |cffffd700(2000 Gold)|r (Nature)
          • (Unit-type of (Triggering unit)) Equal to Gold Ore |cffffd700(3000 Gold)|r (Nature)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Worker (All) for (Attacking unit)) Equal to 1
        • Then - Actions
          • Set tempPoint = (Position of (Triggering unit))
          • Unit - Change ownership of Nothing Unit 0025 <gen> to (Owner of (Attacking unit)) and Change color
          • Unit - Move Nothing Unit 0025 <gen> instantly to tempPoint
          • Unit - Add Gold Miner (Nothing Unit) to Nothing Unit 0025 <gen>
          • Unit - Order Nothing Unit 0025 <gen> to Orc Shaman - Bloodlust (Attacking unit)
          • Unit - Remove Gold Miner (Nothing Unit) from Nothing Unit 0025 <gen>
          • Special Effect - Create a special effect at tempPoint using UI\Feedback\GoldCredit\GoldCredit.mdl
          • Special Effect - Destroy (Last created special effect)
          • Custom script: call RemoveLocation(udg_tempPoint)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Worker (All) for (Attacking unit)) Equal to 2
            • Then - Actions
              • Set tempPoint = (Position of (Triggering unit))
              • Unit - Create 1 Nothing Unit for (Owner of (Attacking unit)) at tempPoint facing Default building facing degrees
              • Unit - Add Gold Miner (Nothing Unit) to (Last created unit)
              • Unit - Set level of Gold Miner (Nothing Unit) for (Last created unit) to 2
              • Unit - Order (Last created unit) to Orc Shaman - Bloodlust (Attacking unit)
              • Unit - Remove (Last created unit) from the game
              • Special Effect - Create a special effect at tempPoint using UI\Feedback\GoldCredit\GoldCredit.mdl
              • Special Effect - Destroy (Last created special effect)
              • Custom script: call RemoveLocation(udg_tempPoint)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Worker (All) for (Attacking unit)) Equal to 3
                • Then - Actions
                  • Set tempPoint = (Position of (Triggering unit))
                  • Unit - Create 1 Nothing Unit for (Owner of (Attacking unit)) at tempPoint facing Default building facing degrees
                  • Unit - Add Gold Miner (Nothing Unit) to (Last created unit)
                  • Unit - Set level of Gold Miner (Nothing Unit) for (Last created unit) to 3
                  • Unit - Order (Last created unit) to Orc Shaman - Bloodlust (Attacking unit)
                  • Unit - Remove (Last created unit) from the game
                  • Special Effect - Create a special effect at tempPoint using UI\Feedback\GoldCredit\GoldCredit.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Custom script: call RemoveLocation(udg_tempPoint)
                • Else - Actions
 
I didn't realize referencing picked unit and such could be demanding on systems!
I wouldn't say its demanding. Every little bit of improvement helps, especially for a trigger that runs every second and iterates through your entire map.

i heard that creating units continually, like i do in the gold mining trigger, causes leaks. If the dummy units i use are removed, does that still cause leaks?
The unit itself is actually what leaks. They will always leave their "footprint" in the game, which is about 0.04 kb. Heroes leave a little more. Unfortunately it's unpreventable, but systems like DummyRecyler and MissleRecycler help mitigate the issue.

Instead of making a dummy unit each time something is triggered, i made it so theres a dummy unit on the map and it is moved to the triggering location and then i add the needed ability to it and remove the ability when the trigger is done. Is this better?
Yep that's perfectly fine. A global dummy caster is always better.
 
Level 13
Joined
Sep 25, 2013
Messages
717
.04 kb, that sounds it could add up a lot for some of my triggers. I'll be just using a global dummy from now on. Maybe i'll just makes its abilities' cast range very far so i don't even have to move it.

Also, i redid the first chunk of the trade caravan trigger. How does this look?


  • Trade Caravan Generate Gold
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set tempUnitGroup3 = (Units in (Playable map area) matching (((Matching unit) has buff Trade Caravan (All)) Equal to True))
      • Unit Group - Pick every unit in tempUnitGroup3 and do (Actions)
        • Loop - Actions
          • Set PickedUnit = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (PickedUnit has buff Trading Post (Market)(All)) Equal to True
              • (PickedUnit has an item of type Trade Goods) Equal to False
            • Then - Actions
              • Special Effect - Create a special effect attached to the overhead of PickedUnit using Abilities\Spells\Items\AIsm\AIsmTarget.mdl
              • Special Effect - Destroy (Last created special effect)
              • Hero - Create Trade Goods and give it to PickedUnit
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (PickedUnit has buff Trading Post (Fortress)(Owner)) Equal to True
                  • (PickedUnit has buff Trading Post (Fortress)(Ally)) Equal to False
                  • (PickedUnit has an item of type Trade Goods) Equal to True
                • Then - Actions
                  • Set tempPoint = (Position of PickedUnit)
                  • Set tempUnitGroup = (Units within 500.00 of tempPoint)
                  • Unit Group - Pick every unit in tempUnitGroup and do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (PickedUnit has buff Fortress (All)) Equal to True
                        • Then - Actions
                          • Unit Group - Add PickedUnit to tempUnitGroup2
                        • Else - Actions
                  • Custom script: call DestroyGroup (udg_tempUnitGroup)
                  • Custom script: call RemoveLocation (udg_tempPoint)
                  • Set tempPoint = (Position of (Random unit from tempUnitGroup2))
                  • Unit - Move PickedUnit instantly to tempPoint
                  • Custom script: call RemoveLocation (udg_tempPoint)
                  • Custom script: call DestroyGroup (udg_tempUnitGroup2)
                  • Unit Group - Pick every unit in tempUnitGroup and do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (PickedUnit has buff Market (All)) Equal to True
                          • (Owner of (Picked unit)) Equal to (Owner of PickedUnit)
                        • Then - Actions
                          • Unit Group - Add PickedUnit to tempUnitGroup3
                        • Else - Actions
                  • Custom script: call DestroyGroup (udg_tempUnitGroup)
                  • Set tempPoint = (Position of (Random unit from tempUnitGroup3))
                  • Set tempPoint2 = (Position of PickedUnit)
                  • Set tempReal = (Distance between tempPoint and tempPoint2)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • tempReal Greater than or equal to 11200.00
                    • Then - Actions
                      • Set tempInteger = 100
                      • Special Effect - Create a special effect attached to the overhead of PickedUnit using Abilities\Spells\Items\AIsm\AIsmTarget.mdl
                      • Special Effect - Destroy (Last created special effect)
                      • Hero - Drop (Item carried by PickedUnit of type Trade Goods) from PickedUnit
                      • Item - Remove (Last dropped item)
                      • Unit - Order PickedUnit to Patrol To tempPoint
                      • Set tempId = (Player number of (Owner of PickedUnit))
                      • Set OHS_OilResource[tempId] = (OHS_OilResource[tempId] + tempInteger)
                      • Floating Text - Create floating text that reads (+ + ((String(tempInteger)) + Gold)) at tempPoint2 with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
                      • Set tempFloatingText = (Last created floating text)
                      • Floating Text - Set the velocity of tempFloatingText to 64.00 towards 90.00 degrees
                      • Floating Text - Change tempFloatingText: Disable permanence
                      • Floating Text - Change the lifespan of tempFloatingText to 3.00 seconds
                      • Floating Text - Change the fading age of tempFloatingText to 0.01 seconds
                      • Custom script: call RemoveLocation (udg_tempPoint)
                      • Custom script: call RemoveLocation (udg_tempPoint2)
                      • Custom script: call DestroyGroup (udg_tempUnitGroup3)
                    • Else - Actions
                      • Set tempInteger = ((Integer(tempReal)) / 500)
                      • Set tempInteger = (tempInteger x tempInteger)
                      • Set tempInteger = (tempInteger / 5)
                      • Special Effect - Create a special effect attached to the overhead of PickedUnit using Abilities\Spells\Items\AIsm\AIsmTarget.mdl
                      • Special Effect - Destroy (Last created special effect)
                      • Hero - Drop (Item carried by PickedUnit of type Trade Goods) from PickedUnit
                      • Item - Remove (Last dropped item)
                      • Unit - Order PickedUnit to Patrol To tempPoint
                      • Set tempId = (Player number of (Owner of PickedUnit))
                      • Set OHS_OilResource[tempId] = (OHS_OilResource[tempId] + tempInteger)
                      • Floating Text - Create floating text that reads (+ + ((String(tempInteger)) + Gold)) at tempPoint2 with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
                      • Set tempFloatingText = (Last created floating text)
                      • Floating Text - Set the velocity of tempFloatingText to 64.00 towards 90.00 degrees
                      • Floating Text - Change tempFloatingText: Disable permanence
                      • Floating Text - Change the lifespan of tempFloatingText to 3.00 seconds
                      • Floating Text - Change the fading age of tempFloatingText to 0.01 seconds
                      • Custom script: call RemoveLocation (udg_tempPoint)
                      • Custom script: call DestroyGroup (udg_tempUnitGroup)
                      • Custom script: call RemoveLocation (udg_tempPoint2)
                      • Custom script: call DestroyGroup (udg_tempUnitGroup2)
                • Else - Actions
      • Custom script: call DestroyGroup (udg_tempUnitGroup3)
 
Last edited:
that sounds it could add up a lot for some of my triggers.
Use a recycling system!

i redid the first chunk of the trade caravan trigger. How does this look?
It looks good, however there are some small errors:

  • Unit Group - Pick every unit in tempUnitGroup3 and do (Actions)
    • Loop - Actions
      • Set PickedUnit = (Picked unit)
      • -------- --------
      • Unit Group - Pick every unit in tempUnitGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (PickedUnit has buff Fortress (All)) Equal to True
            • Then - Actions
              • Unit Group - Add PickedUnit to tempUnitGroup2
            • Else - Actions
      • -------- --------
      • Unit Group - Pick every unit in tempUnitGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (PickedUnit has buff Market (All)) Equal to True
              • (Owner of (Picked unit)) Equal to (Owner of PickedUnit)
            • Then - Actions
              • Unit Group - Add PickedUnit to tempUnitGroup3
            • Else - Actions
^ PickedUnit is currently storing the most recent unit stored into that variable, which was at the very top of the loop when you were enumerating through tempUnitGroup3. You can either make one more unique unit variable, or go back to using (Picked unit) since you only reference it two or three times in the loop.



  • Unit Group - Pick every unit in tempUnitGroup and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (PickedUnit has buff Fortress (All)) Equal to True
        • Then - Actions
          • Unit Group - Add PickedUnit to tempUnitGroup2
        • Else - Actions
    • Custom script: call DestroyGroup (udg_tempUnitGroup)
    • Set tempPoint = (Position of (Random unit from tempUnitGroup2))
^ This doesn't look like it will work properly. You destroy the group before picking a random unit from it. I'm aware that the group's object is still there, but does it still hold the units you added to it?
 
Level 13
Joined
Sep 25, 2013
Messages
717
Well ive made a lot of changes. Here's what i've got. However its still not functioning. The PickedUnit isn't being "instantly moved" to the tempPoint2. However, the caravans do generate some gold when they come within range of the fortress. Its a bit confusing for me lol

  • Trade Caravan Generate Gold
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set tempUnitGroup3 = (Units in (Playable map area) matching (((Matching unit) has buff Trade Caravan (All)) Equal to True))
      • Unit Group - Pick every unit in tempUnitGroup3 and do (Actions)
        • Loop - Actions
          • Set PickedUnit = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (PickedUnit has buff Trading Post (Market)(All)) Equal to True
              • (PickedUnit has an item of type Trade Goods) Equal to False
            • Then - Actions
              • Special Effect - Create a special effect attached to the overhead of PickedUnit using Abilities\Spells\Items\AIsm\AIsmTarget.mdl
              • Special Effect - Destroy (Last created special effect)
              • Hero - Create Trade Goods and give it to PickedUnit
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (PickedUnit has buff Trading Post (Fortress)(Owner)) Equal to True
                  • (PickedUnit has buff Trading Post (Fortress)(Ally)) Equal to False
                  • (PickedUnit has an item of type Trade Goods) Equal to True
                • Then - Actions
                  • Set tempPoint = (Position of PickedUnit)
                  • Set tempUnitGroup = (Units within 1000.00 of tempPoint)
                  • Unit Group - Pick every unit in tempUnitGroup and do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • ((Picked unit) has buff Fortress (All)) Equal to True
                        • Then - Actions
                          • Unit Group - Add (Picked unit) to tempUnitGroup2
                        • Else - Actions
                  • Set tempPoint2 = (Position of (Random unit from tempUnitGroup2))
                  • Unit - Move PickedUnit instantly to tempPoint2
                  • Custom script: call RemoveLocation (udg_tempPoint)
                  • Custom script: call RemoveLocation (udg_tempPoint2)
                  • Custom script: call DestroyGroup (udg_tempUnitGroup)
                  • Custom script: call DestroyGroup (udg_tempUnitGroup2)
                  • Set tempUnitGroup = (Units in (Playable map area))
                  • Unit Group - Pick every unit in tempUnitGroup and do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • ((Picked unit) has buff Market (All)) Equal to True
                          • (Owner of (Picked unit)) Equal to (Owner of PickedUnit)
                        • Then - Actions
                          • Unit Group - Add (Picked unit) to tempUnitGroup2
                        • Else - Actions
                  • Set tempPoint = (Position of (Random unit from tempUnitGroup2))
                  • Set tempPoint2 = (Position of PickedUnit)
                  • Set tempReal = (Distance between tempPoint and tempPoint2)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • tempReal Greater than or equal to 11200.00
                    • Then - Actions
                      • Set tempInteger = 100
                      • Special Effect - Create a special effect attached to the overhead of PickedUnit using Abilities\Spells\Items\AIsm\AIsmTarget.mdl
                      • Special Effect - Destroy (Last created special effect)
                      • Hero - Drop (Item carried by PickedUnit of type Trade Goods) from PickedUnit
                      • Item - Remove (Last dropped item)
                      • Unit - Order PickedUnit to Patrol To tempPoint
                      • Set tempId = (Player number of (Owner of PickedUnit))
                      • Set OHS_OilResource[tempId] = (OHS_OilResource[tempId] + tempInteger)
                      • Floating Text - Create floating text that reads (+ + ((String(tempInteger)) + Gold)) at tempPoint2 with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
                      • Set tempFloatingText = (Last created floating text)
                      • Floating Text - Set the velocity of tempFloatingText to 64.00 towards 90.00 degrees
                      • Floating Text - Change tempFloatingText: Disable permanence
                      • Floating Text - Change the lifespan of tempFloatingText to 3.00 seconds
                      • Floating Text - Change the fading age of tempFloatingText to 0.01 seconds
                      • Custom script: call RemoveLocation (udg_tempPoint)
                      • Custom script: call RemoveLocation (udg_tempPoint2)
                      • Custom script: call DestroyGroup (udg_tempUnitGroup)
                      • Custom script: call DestroyGroup (udg_tempUnitGroup2)
                    • Else - Actions
                      • Set tempInteger = ((Integer(tempReal)) / 500)
                      • Set tempInteger = (tempInteger x tempInteger)
                      • Set tempInteger = (tempInteger / 5)
                      • Special Effect - Create a special effect attached to the overhead of PickedUnit using Abilities\Spells\Items\AIsm\AIsmTarget.mdl
                      • Special Effect - Destroy (Last created special effect)
                      • Hero - Drop (Item carried by PickedUnit of type Trade Goods) from PickedUnit
                      • Item - Remove (Last dropped item)
                      • Unit - Order PickedUnit to Patrol To tempPoint
                      • Set tempId = (Player number of (Owner of PickedUnit))
                      • Set OHS_OilResource[tempId] = (OHS_OilResource[tempId] + tempInteger)
                      • Floating Text - Create floating text that reads (+ + ((String(tempInteger)) + Gold)) at tempPoint2 with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
                      • Set tempFloatingText = (Last created floating text)
                      • Floating Text - Set the velocity of tempFloatingText to 64.00 towards 90.00 degrees
                      • Floating Text - Change tempFloatingText: Disable permanence
                      • Floating Text - Change the lifespan of tempFloatingText to 3.00 seconds
                      • Floating Text - Change the fading age of tempFloatingText to 0.01 seconds
                      • Custom script: call RemoveLocation (udg_tempPoint)
                      • Custom script: call DestroyGroup (udg_tempUnitGroup)
                      • Custom script: call RemoveLocation (udg_tempPoint2)
                      • Custom script: call DestroyGroup (udg_tempUnitGroup)
                      • Custom script: call DestroyGroup (udg_tempUnitGroup2)
                • Else - Actions
      • Custom script: call DestroyGroup (udg_tempUnitGroup3)
 
Add a text message to show how many units are in this tempUnitGroup.

  • Unit Group - Pick every unit in tempUnitGroup and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Picked unit) has buff Fortress (All)) Equal to True
        • Then - Actions
          • Unit Group - Add (Picked unit) to tempUnitGroup2
        • Else - Actions
Have it display before you move PickedUnit.
 
Status
Not open for further replies.
Top