• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Something wicked this way leaks, BIG triggers

Status
Not open for further replies.
I think my map is pretty cool, but every time someone shoots a bullet the average framerate goes down anywhere from .3 to 1.0
Something is clearly leaking, and leaking bad.
Here are the triggers that have to do with the bullets.

CreateBullet
  • CreateBullet
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Attack (rifle)
    • Actions
      • Set TEMPunit0 = (Casting unit)
      • Set TEMPplayer0 = (Owner of TEMPunit0)
      • Set TEMPpoint0 = (Position of TEMPunit0)
      • Set TEMPpoint1 = (Target point of ability being cast)
      • Set TEMPreal0 = (Angle from TEMPpoint0 to TEMPpoint1)
      • Unit - Create 1 Bullet (base) for TEMPplayer0 at TEMPpoint0 facing TEMPreal0 degrees
      • Set TEMPunit1 = (Last created unit)
      • Set TEMPinteger0 = (Terrain cliff level at TEMPpoint0)
      • Set TEMPinteger1 = (Terrain cliff level at TEMPpoint1)
      • -------- width --------
      • Set TEMPreal1 = (Distance between TEMPpoint0 and TEMPpoint1)
      • -------- height --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TEMPinteger0 Not equal to TEMPinteger1
        • Then - Actions
          • Set TEMPreal2 = (((Abs(((Real(TEMPinteger0)) - (Real(TEMPinteger1))))) x CliffHeights) + GunHeight)
        • Else - Actions
          • Set TEMPreal2 = 0.00
      • -------- speed --------
      • Set TEMPreal3 = (Current movement speed of TEMPunit1)
      • Set TEMPreal4 = ((Current movement speed of TEMPunit1) x BmovePeriod)
      • -------- hypotenuse --------
      • Set TEMPreal5 = (Square root(((Power(TEMPreal2, 2.00)) + (Power(TEMPreal1, 2.00)))))
      • Set TEMPreal6 = ((TEMPreal5 x BmovePeriod) / TEMPreal4)
      • Set TEMPreal0 = (TEMPreal4 x (TEMPreal2 / TEMPreal5))
      • Unit - Set life of TEMPunit1 to (STATplayerRange[(Player number of TEMPplayer0)] / 100.00)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TEMPinteger0 Greater than TEMPinteger1
        • Then - Actions
          • Set TEMPreal0 = (TEMPreal0 x -1.00)
        • Else - Actions
      • Cinematic - Clear the screen of text messages for (All players)
      • Unit - Add Crow Form to TEMPunit1
      • Animation - Change TEMPunit1 flying height to GunHeight at 0.00
      • Custom script: call AssignSlot( udg_TEMPunit1, udg_TEMPreal0, udg_TEMPplayer0 )
      • Custom script: call RemoveLocation( udg_TEMPpoint0 )
      • Custom script: call RemoveLocation( udg_TEMPpoint1 )
Alert
  • Alert
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Attack (rifle)
    • Actions
      • Set TEMPunit0 = (Casting unit)
      • Set TEMPplayer0 = (Owner of TEMPunit0)
      • Set TEMPpoint0 = (Position of TEMPunit0)
      • Set TEMPgroup0 = (Units within 3000.00 of TEMPpoint0 matching ((Unit-type of (Matching unit)) Equal to Ghoul))
      • Unit Group - Add all units of TEMPgroup0 to TEMPgroup1
      • Set TEMPgroup0 = (Units within 3000.00 of TEMPpoint0 matching ((Unit-type of (Matching unit)) Equal to Zombie))
      • Unit Group - Add all units of TEMPgroup0 to TEMPgroup1
      • Set TEMPgroup0 = (Units within 3000.00 of TEMPpoint0 matching ((Unit-type of (Matching unit)) Equal to Zombie (wanderer)))
      • Unit Group - Add all units of TEMPgroup0 to TEMPgroup1
      • Set TEMPgroup0 = (Units within 3000.00 of TEMPpoint0 matching ((Unit-type of (Matching unit)) Equal to Flesh Giant))
      • Unit Group - Pick every unit in TEMPgroup0 and do (Actions)
        • Loop - Actions
          • Set TEMPplayer1 = (Owner of (Picked unit))
          • Set TEMPforce0 = (Player group(TEMPplayer1))
          • Cinematic - Ping minimap for TEMPforce0 at TEMPpoint0 for 1.00 seconds
          • Set TEMPgroup2 = (Units owned by TEMPplayer1)
          • Unit Group - Remove all units of TEMPgroup2 from TEMPgroup0
      • Unit Group - Pick every unit in TEMPgroup1 and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Attack TEMPunit0
      • Custom script: call RemoveLocation( udg_TEMPpoint0 )
      • Custom script: call DestroyGroup( udg_TEMPgroup1 )
      • Custom script: call DestroyGroup( udg_TEMPgroup0 )
      • Custom script: call DestroyGroup( udg_TEMPgroup2 )
      • Custom script: call DestroyForce( udg_TEMPforce0 )
BulletDies
  • BulletDies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Bullet (base)
    • Actions
      • Set TEMPunit0 = (Dying unit)
      • For each (Integer A) from 0 to 120, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TEMPunit0 Equal to Bullets[(Integer A)]
            • Then - Actions
              • Set TEMPinteger0 = (Integer A)
              • Set BulletSlots[TEMPinteger0] = False
              • Unit - Remove TEMPunit0 from the game
              • Custom script: set bj_forLoopAIndex = 121
            • Else - Actions
              • Custom script: if (bj_forLoopAIndex == 120) then
              • Unit - Remove TEMPunit0 from the game
              • Custom script: endif
MoveBullets
  • MoveBullets
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Set TEMPgroup0 = (Units of type Bullet (base))
      • Unit Group - Pick every unit in TEMPgroup0 and do (Actions)
        • Loop - Actions
          • Set TEMPunit0 = (Picked unit)
          • For each (Integer A) from 0 to 120, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TEMPunit0 Equal to Bullets[(Integer A)]
                • Then - Actions
                  • Set TEMPinteger2 = (Integer A)
                  • Custom script: set bj_forLoopAIndex = 121
                • Else - Actions
                  • Custom script: if (bj_forLoopAIndex == 120) then
                  • Unit - Remove TEMPunit0 from the game
                  • Set BulletSlots[TEMPinteger2] = False
                  • Custom script: endif
          • Set TEMPplayer0 = (Owner of TEMPunit0)
          • Set TEMPpoint0 = (Position of TEMPunit0)
          • Set TEMPinteger0 = (Terrain cliff level at TEMPpoint0)
          • Set TEMPreal0 = (Facing of TEMPunit0)
          • -------- RoC --------
          • Set TEMPreal1 = BulletAltChange[(Integer A)]
          • -------- speed --------
          • Set TEMPreal2 = 100.00
          • Set TEMPreal3 = (Current flying height of TEMPunit0)
          • Set TEMPpoint1 = (TEMPpoint0 offset by TEMPreal2 towards TEMPreal0 degrees)
          • Set TEMPinteger1 = (Terrain cliff level at TEMPpoint1)
          • Set TEMPinteger3 = (Abs((TEMPinteger0 - TEMPinteger1)))
          • Set TEMPreal4 = (TEMPreal3 + TEMPreal1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TEMPinteger0 Greater than TEMPinteger1
            • Then - Actions
              • Set TEMPreal4 = (TEMPreal4 + (CliffHeights x (Real(TEMPinteger3))))
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TEMPinteger0 Less than TEMPinteger1
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • TEMPreal4 Greater than or equal to (CliffHeights x (Real(TEMPinteger3)))
                    • Then - Actions
                      • Set TEMPreal4 = (TEMPreal4 - (CliffHeights x (Real(TEMPinteger3))))
                    • Else - Actions
                      • Unit - Remove TEMPunit0 from the game
                      • Set BulletSlots[TEMPinteger2] = False
                      • Custom script: call DestroyEffectBJ( AddSpecialEffectLocBJ( udg_TEMPpoint1, "Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl" ) )
                • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TEMPreal4 Less than 0.00
            • Then - Actions
              • Unit - Remove TEMPunit0 from the game
              • Set BulletSlots[TEMPinteger2] = False
            • Else - Actions
          • Set TEMPgroup1 = (Units within 50.00 of TEMPpoint1 matching ((((Matching unit) is alive) Equal to True) and (((Owner of (Matching unit)) is an enemy of TEMPplayer0) Equal to True)))
          • Unit Group - Pick every unit in TEMPgroup1 and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (TEMPgroup1 is empty) Equal to False
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • TEMPreal4 Less than 128.00
                    • Then - Actions
                      • Custom script: call DestroyEffectBJ( AddSpecialEffectTargetUnitBJ( "chest", GetEnumUnit(), "Objects\\Spawnmodels\\Critters\\Albatross\\CritterBloodAlbatross.mdl" ) )
                      • Unit - Cause Rifles[(Player number of TEMPplayer0)] to damage (Picked unit), dealing 200.00 damage of attack type Chaos and damage type Normal
                      • Custom script: call DestroyGroup( udg_TEMPgroup1 )
                      • Unit - Remove TEMPunit0 from the game
                      • Set BulletSlots[TEMPinteger2] = False
                    • Else - Actions
                • Else - Actions
          • Custom script: call DestroyGroup( udg_TEMPgroup1 )
          • Destructible - Pick every destructible within 50.00 of TEMPpoint1 and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Destructible-type of (Picked destructible)) Equal to Summer Tree Wall
                      • (Destructible-type of (Picked destructible)) Equal to Pathing Blocker (Ground)
                      • (Destructible-type of (Picked destructible)) Equal to Pathing Blocker (Ground)
                • Then - Actions
                  • Custom script: call DestroyEffectBJ( AddSpecialEffectLocBJ( udg_TEMPpoint1, "Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl" ) )
                  • Unit - Remove TEMPunit0 from the game
                  • Set BulletSlots[TEMPinteger2] = False
                • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Playable map area) contains TEMPpoint1) Equal to True
            • Then - Actions
              • Unit - Move TEMPunit0 instantly to TEMPpoint1
            • Else - Actions
              • Unit - Remove TEMPunit0 from the game
              • Set BulletSlots[TEMPinteger2] = False
              • Game - Display to (All players) the text: (LastRec FlyHeight: + (String(TEMPreal4)))
          • Animation - Change TEMPunit1 flying height to TEMPreal4 at 0.00
          • Set BulletLife[(Integer A)] = (BulletLife[(Integer A)] - TEMPreal2)
          • Custom script: call RemoveLocation( udg_TEMPpoint0 )
          • Custom script: call RemoveLocation( udg_TEMPpoint1 )
      • Custom script: call RemoveLocation( udg_TEMPpoint0 )
      • Custom script: call RemoveLocation( udg_TEMPpoint1 )
      • Custom script: call DestroyGroup( udg_TEMPgroup0 )
 
Level 8
Joined
Aug 4, 2006
Messages
357
whenever you're looping through something 120 times, it's going to create some lag. do you really need to be doing that? also, picking all units in a unit group is a loop as well. if there are a lot of units that it has to sort out, it will lag.
in your move trigger, you're doing a loop within a loop. if there are actually 120 units of type bullet, it's going to loop through a maximum of over 14400 times every .03 seconds. this is bad. also, whenever you do something like "set TEMPgroup1 = (Units within 50.00 of TEMPpoint1...", it has to check each unit on the map to see if it is within 50 of TEMPpoint1. i didn't have time to suggest an alternative method of doing things, but hopefully i got you thinking. :p
 
I see your reasoning.
How else would I be able to go about this?
Hmm... In my assign slot function I get rid of the bullet if it can't be assigned. So I guess I could skip the group thing all together. That would help it a lot. But I still don't see any alternatives to the...
Do you think it would work if I gave bullets an Aura, then check all units with buff?
No that would have to check all units in the map too, then it would do it for units within range of different bullets too. Hmm, just thinkin aloud.
I don't see any alternatives to that one.
 
Level 8
Joined
Aug 4, 2006
Messages
357
you have so many unnecessary "Temp" integers, reals, units, players, etc. the main things you need to put in variables are things that will leak, and need to be destroyed at the end of their use (i.e. unit groups, player groups, positions). also, your variable names are so generic i have no idea what their purpose is, and it's hard for me to refer back to what they are set, everytime i see them.

maybe if you could tell me in your own words (but in detail) what needs to be done every time MoveBullets is executed, i can help you rewrite your code.

also, please don't take offense to anything i say. i'm just trying to help. :wink:
 
Level 8
Joined
Aug 4, 2006
Messages
357
hey red, when you get a chance, can you also tell me what's wrong with my thinking? i'd like to improve my programming ability and appreciate constructive criticism.

he should at least use variable names more specific to what they're used for (i.e. tempCliffHeight instead of tempInteger) as it well help everyone (including him) write/debug his code.
 
In the trigger comments I have what everything means, I use these same variables several times over in about 7 different triggers. I don't want to have to create that many different variables when I only need these ones.
I only use non temp variables in triggers that will not be finished with the variable by the time it ends, or if the trigger has GetPolledWait() anywhere in it.

But if this isn't causing the huge leaks every time someone shoots I don't know what is. But maskedpoptart has a point. Doing hundreds of loops every .03 seconds doesn't sound very good for a map. But shouldn't it recover afterwards?
 
Last edited:
Okay until I get this working I'm going to forget the Y axis.
  • CreateBulletV2
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Attack (rifle)
    • Actions
      • Set TEMPunit0 = (Casting unit)
      • Set TEMPplayer0 = (Owner of TEMPunit0)
      • Set TEMPpoint0 = (Position of TEMPunit0)
      • Set TEMPpoint1 = (Target point of ability being cast)
      • Set TEMPreal0 = (Angle from TEMPpoint0 to TEMPpoint1)
      • Unit - Create 1 Bullet (base) for TEMPplayer0 at TEMPpoint0 facing TEMPreal0 degrees
      • Set TEMPunit1 = (Last created unit)
      • Set TEMPinteger0 = (Terrain cliff level at TEMPpoint0)
      • Set TEMPinteger1 = (Terrain cliff level at TEMPpoint1)
      • Set TEMPreal0 = 0.00
      • Animation - Change TEMPunit1 flying height to GunHeight at 0.00
      • Custom script: call AssignSlot( udg_TEMPunit1, udg_TEMPreal0, udg_TEMPplayer0 )
      • Custom script: call RemoveLocation( udg_TEMPpoint0 )
      • Custom script: call RemoveLocation( udg_TEMPpoint1 )
Here is a second version of the move trigger. It however still drops framerates.
  • MoveBulletsV2
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 0 to 120, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • BulletSlots[(Integer A)] Equal to True
            • Then - Actions
              • Set TEMPunit0 = Bullets[(Integer A)]
              • Set TEMPplayer0 = (Owner of TEMPunit0)
              • Set TEMPpoint0 = (Position of TEMPunit0)
              • Set TEMPinteger0 = (Terrain cliff level at TEMPpoint0)
              • Set TEMPreal0 = (Facing of TEMPunit0)
              • -------- RoC --------
              • Set TEMPreal1 = BulletAltChange[(Integer A)]
              • -------- speed --------
              • Set TEMPreal2 = 100.00
              • Set TEMPreal3 = (Current flying height of TEMPunit0)
              • Set TEMPreal4 = (TEMPreal3 + TEMPreal1)
              • Set TEMPpoint1 = (TEMPpoint0 offset by TEMPreal2 towards TEMPreal0 degrees)
              • Set TEMPinteger1 = (Terrain cliff level at TEMPpoint1)
              • Set TEMPinteger3 = (Abs((TEMPinteger0 - TEMPinteger1)))
              • -------- move bullet --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Playable map area) contains TEMPpoint1) Equal to True
                • Then - Actions
                  • Unit - Move TEMPunit0 instantly to TEMPpoint1
                • Else - Actions
                  • Unit - Remove TEMPunit0 from the game
                  • Set BulletSlots[TEMPinteger2] = False
              • -------- adjust height --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TEMPinteger0 Greater than TEMPinteger1
                • Then - Actions
                  • Set TEMPreal4 = (TEMPreal4 + (CliffHeights x (Real(TEMPinteger3))))
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • TEMPinteger0 Less than TEMPinteger1
                    • Then - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • TEMPreal4 Greater than (CliffHeights x (Real(TEMPinteger3)))
                        • Then - Actions
                          • Set TEMPreal4 = (TEMPreal4 - (CliffHeights x (Real(TEMPinteger3))))
                        • Else - Actions
                          • Unit - Remove TEMPunit0 from the game
                          • Set BulletSlots[(Integer A)] = False
                          • Custom script: call DestroyEffectBJ( AddSpecialEffectLocBJ( udg_TEMPpoint1, "Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl" ) )
                    • Else - Actions
              • -------- ground collision --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TEMPreal4 Less than or equal to 0.00
                • Then - Actions
                  • Unit - Remove TEMPunit0 from the game
                  • Set BulletSlots[TEMPinteger2] = False
                • Else - Actions
              • Set TEMPgroup1 = (Units within 50.00 of TEMPpoint1 matching ((((Matching unit) is alive) Equal to True) and (((Owner of (Matching unit)) is an enemy of TEMPplayer0) Equal to True)))
              • Unit Group - Pick every unit in TEMPgroup1 and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (TEMPgroup1 is empty) Equal to False
                    • Then - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • TEMPreal4 Less than 128.00
                        • Then - Actions
                          • Custom script: call DestroyEffectBJ( AddSpecialEffectTargetUnitBJ( "chest", GetEnumUnit(), "Objects\\Spawnmodels\\Critters\\Albatross\\CritterBloodAlbatross.mdl" ) )
                          • Unit - Cause Rifles[(Player number of TEMPplayer0)] to damage (Picked unit), dealing 200.00 damage of attack type Chaos and damage type Normal
                          • Custom script: call DestroyGroup( udg_TEMPgroup1 )
                          • Unit - Remove TEMPunit0 from the game
                          • Set BulletSlots[(Integer A)] = False
                        • Else - Actions
                    • Else - Actions
              • Custom script: call DestroyGroup( udg_TEMPgroup1 )
              • Destructible - Pick every destructible within 50.00 of TEMPpoint1 and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Or - Any (Conditions) are true
                        • Conditions
                          • (Destructible-type of (Picked destructible)) Equal to Summer Tree Wall
                          • (Destructible-type of (Picked destructible)) Equal to Pathing Blocker (Ground)
                    • Then - Actions
                      • Custom script: call DestroyEffectBJ( AddSpecialEffectLocBJ( udg_TEMPpoint1, "Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl" ) )
                      • Unit - Remove TEMPunit0 from the game
                      • Set BulletSlots[(Integer A)] = False
                    • Else - Actions
              • Animation - Change TEMPunit0 flying height to TEMPreal4 at 0.00
              • Set BulletLife[(Integer A)] = (BulletLife[(Integer A)] - TEMPreal2)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • BulletLife[(Integer A)] Less than or equal to 0.00
                • Then - Actions
                  • Unit - Remove TEMPunit0 from the game
                  • Set BulletSlots[(Integer A)] = False
                • Else - Actions
              • Custom script: call RemoveLocation( udg_TEMPpoint0 )
              • Custom script: call RemoveLocation( udg_TEMPpoint1 )
            • Else - Actions
What about your missile system? How would I be able to tune that to apply for my map?
 
Last edited:
Level 8
Joined
Aug 4, 2006
Messages
357
oh i think i get how you're using variables now. it takes less time to reference the variable than to redo the calculations or do a WE function.

but if you're using a lot of "temp" global variables in multiple triggers, won't that pose a problem when people are actually playing the game? from what i've read, wc3 runs a different thread of execution for each trigger, so two triggers could be trying to use your global variables at the same time. (correct me if i'm wrong)

btw, the new triggers are looking less clunky. are they running faster/doing what they're supposed to?
 
Status
Not open for further replies.
Top