Trigger causing lag

Wratox1

Member
Reaction score
22
Hello, i have some problem with my map, i have a spell, which creates a bullet:
Trigger:
  • machinegun
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Machinegun
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • machinegunammo[(Player number of (Owner of (Triggering unit)))] Greater than or equal to 5
        • Then - Actions
          • For each (Integer bulletint[(Player number of (Owner of (Triggering unit)))]) from 1 to 5, do (Actions)
            • Loop - Actions
              • Set bulletcreatepoint = (Position of (Triggering unit))
              • Set bulletcreatefacing = (Facing of (Triggering unit))
              • Set machinegunammo[(Player number of (Owner of (Triggering unit)))] = (machinegunammo[(Player number of (Owner of (Triggering unit)))] - 1)
              • Unit - Create 1 machinegun bullet for (Owner of (Triggering unit)) at bulletcreatepoint facing bulletcreatefacing degrees
              • Unit Group - Add (Last created unit) to bulletsinmap
              • Custom script: call RemoveLocation(udg_bulletcreatepoint)
              • Wait 0.10 seconds
        • Else - Actions
          • Set tmp_group = (Player group((Owner of (Triggering unit))))
          • Game - Display to tmp_group the text: |cffff0000Ammo is o...
          • Custom script: call DestroyForce(udg_tmp_group)


and when a bullet is created, it is moved with this trigger:

Trigger:
  • bullet move
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in bulletsinmap 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
                  • (Unit-type of (Picked unit)) Equal to machinegun bullet
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to machinegun bullet
                • Then - Actions
                  • Set bulletspeed = 30.00
                • Else - Actions
              • Set bulletposition = (Position of (Picked unit))
              • Set bulletfacing = (Facing of (Picked unit))
              • Set bulletmoveto = (bulletposition offset by bulletspeed towards bulletfacing degrees)
              • Unit - Move (Picked unit) instantly to bulletmoveto, facing bulletfacing degrees
              • Unit - Add a 8.00 second Generic expiration timer to (Last created unit)
              • Custom script: call RemoveLocation(udg_bulletposition)
              • Custom script: call RemoveLocation(udg_bulletmoveto)
            • Else - Actions


and since the bullets will move until it hits an enemy, or it enters the black area outside the playable map area, i created this trigger(to prevent fatal error that occurs when a unit enters that black area):
Trigger:
  • bulletproof
    • Events
      • Unit - A unit enters topside <gen>
      • Unit - A unit enters rightside <gen>
      • Unit - A unit enters leftside <gen>
      • Unit - A unit enters downside <gen>
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to machinegun bullet
    • Actions
      • Unit - Remove (Triggering unit) from the game


but the problem is, when i some bullets and then comes to the black area, theyre supposed to be removed, and they are removed, but then it starts to lag heavily, but just for some seconds, then it goes back to normal.(atleast it has something to do with the bullets)

can anyone figure out why this is happening?
 

Cookiemaster

New Member
Reaction score
36
First of,

Trigger:
  • Wait 0.10 seconds

Don't use waits for such things. They are inaccurate. Just remove them and create the units at different distances from the caster. (E.g. 60,80,100,120,140. The bullets will have 20 distance in between. But if you really want to spawn the bullets on intervals, look into timers and get a bit more knowledge of JASS.(Though JASS is not required. Just very recommended if you get into these things.))


Moving on, your bullet "Move" code. It needs some cleaning up to do.

What you do is for every unit in the bulletsinmap unit group, you check if it's a "machinegun bullet" unit. (This is okay if you're going to add other bullets later.)

But after that, you check if the picked unit is a "machinegun bullet" unit for the second time, and if that is true (which it will always be, since otherwise it would not reach these checks), it sets bulletspeed to 30.

A simple thing you could do is change this:
Trigger:
  • Set bulletmoveto = (bulletposition offset by bulletspeed towards bulletfacing degrees)

Into this:
Trigger:
  • Set bulletmoveto = (bulletposition offset by 30.00 towards bulletfacing degrees)

And then remove the "if machinegun = bullet then set bulletspeed = 30.00" altogether.


A third thing I would like to address about your triggers would be this:
Trigger:
  • Unit - Add a 8.00 second Generic expiration timer to (Last created unit)

Why do you do this every time the bullets gets moved? You could instead perform this action when you create the bullet, so that the game doesn't have to handle it every time it moves a bullet.
 

Wratox1

Member
Reaction score
22
First of,

Trigger:
  • Wait 0.10 seconds

Don't use waits for such things. They are inaccurate. Just remove them and create the units at different distances from the caster. (E.g. 60,80,100,120,140. The bullets will have 20 distance in between. But if you really want to spawn the bullets on intervals, look into timers and get a bit more knowledge of JASS.(Though JASS is not required. Just very recommended if you get into these things.))


Moving on, your bullet "Move" code. It needs some cleaning up to do.

What you do is for every unit in the bulletsinmap unit group, you check if it's a "machinegun bullet" unit. (This is okay if you're going to add other bullets later.)

But after that, you check if the picked unit is a "machinegun bullet" unit for the second time, and if that is true (which it will always be, since otherwise it would not reach these checks), it sets bulletspeed to 30.

A simple thing you could do is change this:
Trigger:
  • Set bulletmoveto = (bulletposition offset by bulletspeed towards bulletfacing degrees)

Into this:
Trigger:
  • Set bulletmoveto = (bulletposition offset by 30.00 towards bulletfacing degrees)

And then remove the "if machinegun = bullet then set bulletspeed = 30.00" altogether.


A third thing I would like to address about your triggers would be this:
Trigger:
  • Unit - Add a 8.00 second Generic expiration timer to (Last created unit)

Why do you do this every time the bullets gets moved? You could instead perform this action when you create the bullet, so that the game doesn't have to handle it every time it moves a bullet.

the wait is ok, since i use a custom integer with player index

yes, i am going to add other kind of bullets, and since not all bullets have the same speed i am doing this..

and about the expiration timer, i forgot about that:eek:, will move it to when its created asap!
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
well, can this system cause lag? i'd say yeah because all periodic triggers can cause lag.

however, could that system cause lag spikes which come and go? naaah, i dont think so.

if you are really sure that these lags only sometimes appear and stay only for a little time i'd say its not because of this sytem. lag spikes are more likely to come together with loading object editor data. for example custom units with custom abilities being spawned for the very first time in the game. that could cause short little lag spikes.

if what you are saying is true i would rather look for something else as the cause of this.


well, just looked through your triggers, there are no memory leaks at all, and nothing which is downright wrong with this. its, maybe not perfect, but fine though.

one thing however i'd say should be changed if possible.
in the very first trigger, create the TempPoint variable before the loop and remove it after. because all of your bullets get spawned at the Position of the triggering unit. and since it will most probably not move in this short intervall of shooting, or maybe it couldnt even move because its shooting, you could just create 1 point variable for all of the bullets at once instead of creating and destroying as many points as you are shooting bullets.
 

Wratox1

Member
Reaction score
22
well, can this system cause lag? i'd say yeah because all periodic triggers can cause lag.

however, could that system cause lag spikes which come and go? naaah, i dont think so.

if you are really sure that these lags only sometimes appear and stay only for a little time i'd say its not because of this sytem. lag spikes are more likely to come together with loading object editor data. for example custom units with custom abilities being spawned for the very first time in the game. that could cause short little lag spikes.

if what you are saying is true i would rather look for something else as the cause of this.


well, just looked through your triggers, there are no memory leaks at all, and nothing which is downright wrong with this. its, maybe not perfect, but fine though.

one thing however i'd say should be changed if possible.
in the very first trigger, create the TempPoint variable before the loop and remove it after. because all of your bullets get spawned at the Position of the triggering unit. and since it will most probably not move in this short intervall of shooting, or maybe it couldnt even move because its shooting, you could just create 1 point variable for all of the bullets at once instead of creating and destroying as many points as you are shooting bullets.

im pretty sure that this system is whats causing the lags, since its only when i have fired some bullets these lags occurs, and doesnt have many more triggers than these that do something except for the beginning(at the moment), but there are my move triggers for my heroes however, i doubt they has something to do with this, but i can show you them anyway:
Trigger:
  • move
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Camera - Set (Player((Integer A)))'s camera Rotation to (Facing of ship[(Integer A)]) over 0.00 seconds
          • Camera - Set (Player((Integer A)))'s camera Angle of attack to -25.00 over 0.00 seconds
          • Camera - Set (Player((Integer A)))'s camera Distance to target to 2000.00 over 0.00 seconds
          • Camera - Set (Player((Integer A)))'s camera Height Offset to 150.00 over 0.00 seconds
          • Selection - Select ship[(Integer A)] for (Player((Integer A)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • forward[(Integer A)] Equal to True
              • shipspeed[(Integer A)] Less than or equal to ((Real((Intelligence of ship[(Integer A)] (Exclude bonuses)))) / 2.00)
            • Then - Actions
              • Set shipspeed[(Integer A)] = (shipspeed[(Integer A)] + 0.15)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • shipspeed[(Integer A)] Greater than 0.00
                • Then - Actions
                  • Set shipspeed[(Integer A)] = (shipspeed[(Integer A)] - 0.05)
                • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • backward[(Integer A)] Equal to True
                  • shipspeed[(Integer A)] Greater than 0.00
            • Then - Actions
              • Set shipspeed[(Integer A)] = (shipspeed[(Integer A)] - 0.15)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • left[(Integer A)] Equal to True
              • shipangle[(Integer A)] Less than (((Real((Intelligence of ship[(Integer A)] (Exclude bonuses)))) / 5.00) x 2.00)
            • Then - Actions
              • Set shipangle[(Integer A)] = (shipangle[(Integer A)] + 0.50)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • right[(Integer A)] Equal to True
              • shipangle[(Integer A)] Greater than (((Real((Intelligence of ship[(Integer A)] (Exclude bonuses)))) / 5.00) x -2.00)
            • Then - Actions
              • Set shipangle[(Integer A)] = (shipangle[(Integer A)] - 0.50)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • right[(Integer A)] Not equal to True
              • left[(Integer A)] Not equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • shipangle[(Integer A)] Greater than 0.00
                • Then - Actions
                  • Set shipangle[(Integer A)] = (shipangle[(Integer A)] - 0.50)
                • Else - Actions
                  • Set shipangle[(Integer A)] = (shipangle[(Integer A)] + 0.50)
            • Else - Actions
          • Set shipposition = (Position of ship[(Integer A)])
          • Set shipfacing = (Facing of ship[(Integer A)])
          • Set shipmoveto = (shipposition offset by shipspeed[(Integer A)] towards (shipfacing + shipangle[(Integer A)]) degrees)
          • Unit - Move ship[(Integer A)] instantly to shipmoveto, facing (shipfacing + shipangle[(Integer A)]) degrees
          • Custom script: call RemoveLocation(udg_shipmoveto)
          • Custom script: call RemoveLocation(udg_shipposition)
          • Set shipfacing = 0.00


Trigger:
  • forward press
    • Events
      • Player - Player 1 (Red) Presses the Up Arrow key
      • Player - Player 2 (Blue) Presses the Up Arrow key
    • Conditions
      • (ship[(Player number of (Triggering player))] is alive) Equal to True
    • Actions
      • Set forward[(Player number of (Triggering player))] = True

i have similar triggers for all the arrowkeys, and for the release event..

Edit: actually, on my last testing, which i did after i moved the Generic expiration action to my create-trigger, it didnt lag at all, no matter how many bullets i fired, so i think that did it, and if it didnt i will tell you!

thanks for the help(if it helped)!
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top