• 🏆 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] Anti-Block (Lag)

Status
Not open for further replies.
Level 9
Joined
Aug 27, 2009
Messages
473
Ok, so the idea was to make a working Anti-Block system which actually don't lag.. And which works instantly.. I came up with this idea:

  • Anti Block
    • Events
      • Unit - A unit Begins construction
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (ABChain is empty) Equal to True
        • Then - Actions
          • Set TempLoc = (Position of (Triggering unit))
          • Set ABChain = (Units in (Entire map) matching ((Matching unit) Equal to (Triggering unit)))
          • Set ABMin = (X of TempLoc)
          • Set ABMax = (X of TempLoc)
        • Else - Actions
      • Set ABCheck = False
      • Unit Group - Pick every unit in ABChain and do (Actions)
        • Loop - Actions
          • Set TempLoc2 = (Position of (Picked unit))
          • Set TempGroup = (Units owned by (Owner of (Triggering unit)))
          • Unit Group - Pick every unit in TempGroup and do (Actions)
            • Loop - Actions
              • Set TempLoc3 = (Position of (Picked unit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Not equal to Human Builder
                  • ((Picked unit) is in ABChain) Equal to False
                  • (Distance between TempLoc2 and TempLoc3) Less than 182.00
                • Then - Actions
                  • Unit Group - Add (Picked unit) to ABChain
                  • If ((X of TempLoc3) Less than ABMin) then do (Set ABMin = (X of TempLoc3)) else do (Do nothing)
                  • If ((X of TempLoc3) Greater than ABMax) then do (Set ABMax = (X of TempLoc3)) else do (Do nothing)
                  • Set ABCheck = True
                • Else - Actions
      • Custom script: call DestroyGroup(udg_TempGroup)
      • Custom script: call RemoveLocation(udg_TempLoc3)
      • Custom script: call RemoveLocation(udg_TempLoc2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ABCheck Equal to False
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (ABMax - ABMin) Greater than or equal to 1792.00
            • Then - Actions
              • Special Effect - Create a special effect at TempLoc using Abilities\Spells\Human\DispelMagic\DispelMagicTarget.mdl
              • Special Effect - Destroy (Last created special effect)
              • Unit - Remove (Triggering unit) from the game
            • Else - Actions
          • Custom script: call DestroyGroup(udg_ABChain)
          • Custom script: call RemoveLocation(udg_TempLoc)
        • Else - Actions
          • Trigger - Run Anti Block <gen> (checking conditions)
This does work for anti-blocking.. This works instantly.. But when the "Chain" is long enough, it lags everytime you build a new tower into the chain.

So the question is: Any ideas how to "remove" the lag?

Define "chain": Towers which touches each other.

Examples:
This wont lag
Code:
|       |
|XXXXXX |
|       |
| XXXXXX|
|       |
|XXXXXX |
|       |
| XXXXXX|
|       |
|XXXXXX |
|       |
This will lag
Code:
|       |
|XXXXXX |
|     X |
| XXX X |
| X   X |
| X XXX |
| X     |
| XXXXXX|
|       |
|XXXXXX |
|       |
EDIT:
Trigger updated with leak (pointed out by Maker) fixed..
 
Last edited:
Level 9
Joined
Aug 27, 2009
Messages
473
Is it required to run that in every Trigger, or just once in (for example) Map Initialization..?
And it's faster because you just run 1 action instead of 2, right?

Anyway, anything else that may make this script quicker to excecute? I was hoping someone had a cleaver way of skipping the looping I use..
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
These are in wrong place:
  • Custom script: call DestroyGroup(udg_TempGroup)
  • Custom script: call RemoveLocation(udg_TempLoc3)
  • Custom script: call RemoveLocation(udg_TempLoc2)
Could you post the system in a map? There are thingsthat can be optimized, but I'm too lazy to type them. Easier to just fix in the editor.
 
Level 9
Joined
Aug 27, 2009
Messages
473
I know all my Custom Scripts can be placed somewhere else. But wouldn't it cause more lag if it's excecuted more times? I mean.. If a variable is used in a loop like this:

loop 1 to 10...
set TempLocation = some location

Wouldn't it be cleaver to destroy the leak outside the loop, and destroy the variable just once instead of 10 times? I don't believe the variable is stored somewhere else outside itself, unless you or someone else can prove me wrong.. :p
 
Status
Not open for further replies.
Top