1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Dismiss Notice
  5. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Would this trigger cause lag?

Discussion in 'Triggers & Scripts' started by Qrom Bellascream, Nov 4, 2017.

  1. Qrom Bellascream

    Qrom Bellascream

    Joined:
    Apr 5, 2013
    Messages:
    150
    Resources:
    0
    Resources:
    0
    • ZombieSpawnsSpawn
      • Events
        • Time - Every (Random real number between 2.00 and 4.00) seconds of game time
      • Conditions
      • Actions
        • Unit - Create 1 Zombie for Player 12 (Brown) at (Center of SpawnZombieSpawner[(Random integer number between 1 and AmountOfZombieSpawners)]) facing Default building facing degrees
        • For each (Integer A) from 1 to 10, 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
                    • (Distance between (Position of (Last created unit)) and (Position of PlayerUnit[(Integer A)])) Greater than Distance
              • Then - Actions
                • Unit - Remove (Last created unit) from the game
                • Trigger - Run (This trigger) (ignoring conditions)
              • Else - Actions
        • Unit Group - Add (Last created unit) to ALLZombies
        • AI - Ignore (Last created unit)'s guard position
        • Unit - Order (Last created unit) to Attack-Move To (Position of PlayerUnit[(Random integer number between 1 and 4)])


    I'm mostly worried about the distance check part. It checks if the place where the zombie spawned is atleast 6000 meters from the nearest hero unit, and if it isn't it kills the zombie and spawns it at another random location, hopefully near the hero. Would this trigger cause lag if the zombie somehow spawned like 5 times in a row at a distance too far away from a hero?
     
  2. KILLCIDE

    KILLCIDE

    Administrator

    Joined:
    Jul 22, 2015
    Messages:
    3,505
    Resources:
    20
    Models:
    2
    Icons:
    10
    Spells:
    7
    Tutorials:
    1
    Resources:
    20
    Yes it would. You are creating a ton of locations and not clearing them properly. I advise you take a look at Memory Leaks.
     
  3. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,805
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    This might not do what you think it does. At map initialization it will roll a random real between 2 and 4 and then periodically every that period run the trigger. For example if it rolled 2.50 it would then have a period of exactly 2.50 seconds for the rest of the game. You might want to use a timer instead that each tick you restart with a random timeout of 2.00 to 4.00.

    As KILLCIDE mentioned, it leaks a lot of location object. These can degrade game performance over time.
     
  4. Qrom Bellascream

    Qrom Bellascream

    Joined:
    Apr 5, 2013
    Messages:
    150
    Resources:
    0
    Resources:
    0
    yeah, I looked over some triggers and noticed alot of leaks with the "location of unit" and I've cleaned them already. But the part with rerunning the trigger, would that cause lag on its own?
     
  5. KILLCIDE

    KILLCIDE

    Administrator

    Joined:
    Jul 22, 2015
    Messages:
    3,505
    Resources:
    20
    Models:
    2
    Icons:
    10
    Spells:
    7
    Tutorials:
    1
    Resources:
    20
    If you have cleared the 4 location leaks (technically 22), then it shouldn't. You can improve it by not repeating function calls and storing things into variables and referencing them instead (like Last created unit).

    You should also keep note of what DSG said about the periodic event.
     
  6. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,805
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Getting the trigger to start a timer does not produce any leaks. Trigger event should be when a timer expires and the trigger restarts the timer at the end of the actions.