• 🏆 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!

[Trigger] Each time this script fires, my fps reduces by 2

Status
Not open for further replies.
Level 6
Joined
Apr 5, 2013
Messages
154
I have made a script for a missile launcher. But each time I fire it, my FPS gets reduced by 2?

  • Launch Rocket
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Missile Launcher (Neutral Hostile)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) has an item of type Missile) Equal to True
        • Then - Actions
          • Trigger - Turn on MovingDatMissile <gen>
          • Set AKUNIT = (Triggering unit)
          • Sound - Play TinkerMissileLaunch1 <gen>
          • Custom script: call SetUnitAnimationByIndex(udg_AKUNIT, 151)
          • Animation - Queue AKUNIT's stand animation
          • Player - Add 5 to (Owner of (Triggering unit)) Food used
          • Set MissileFiringGuy[(Player number of (Owner of (Triggering unit)))] = (Triggering unit)
          • Item - Set charges remaining in (Item carried by (Triggering unit) of type Missile) to ((Charges remaining in (Item carried by (Triggering unit) of type Missile)) - 1)
          • Unit - Create 1 Missile Dummy for (Owner of (Triggering unit)) at ((Position of (Triggering unit)) offset by 150.00 towards (Angle from (Position of (Triggering unit)) to (Target point of ability being cast)) degrees) facing Default building facing degrees
          • Set MISSILE[(Player number of (Owner of (Triggering unit)))] = (Last created unit)
          • Set WarheadLocation[(Player number of (Owner of (Triggering unit)))] = (Target point of ability being cast)
        • Else - Actions
  • MovingDatMissile
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Unit - Move MISSILE[(Integer A)] instantly to ((Position of MISSILE[(Integer A)]) offset by 40.00 towards (Angle from (Position of MISSILE[(Integer A)]) to WarheadLocation[(Integer A)]) degrees), facing WarheadLocation[(Integer A)]
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Distance between (Position of MISSILE[(Integer A)]) and WarheadLocation[(Integer A)]) Less than or equal to 20.00) or ((Number of units in (Units within 75.00 of (Position of MISSILE[(Integer A)]))) Greater than 1)
            • Then - Actions
              • Unit Group - Pick every unit in (Units within 200.00 of (Position of MISSILE[(Integer A)])) and do (Actions)
                • Loop - Actions
                  • Special Effect - Create a special effect at (Position of MISSILE[(Integer A)]) using Objects\Spawnmodels\Other\NeutralBuildingExplosion\NeutralBuildingExplosion.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Unit - Cause MissileFiringGuy[(Integer A)] to damage (Picked unit), dealing 195.00 damage of attack type Chaos and damage type Universal
                  • Unit - Remove MISSILE[(Integer A)] from the game
                  • Custom script: call RemoveLocation( udg_WarheadLocation[bj_forLoopAIndex])
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Number of units in (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Missile Dummy))) Equal to 0
                    • Then - Actions
                      • Trigger - Turn off (This trigger)
                    • Else - Actions
            • Else - Actions
 
Level 20
Joined
Aug 13, 2013
Messages
1,696
Set the looping\periodic timer to 0.04 or 0.05 to gain performance and reduces fps drops. Learn about proper triggering and removing of leaks ( you will notice the lag if you don't destroy it ). Neutral explosion effects creation also causes the lag, try some simple effects or minimize the amount if possible. Use the variables as reference ( your creating multiple variables for a single unit? ). So obviously the reason
 
Level 6
Joined
Apr 5, 2013
Messages
154
  • Launch Rocket
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Missile Launcher (Neutral Hostile)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) has an item of type Missile) Equal to True
        • Then - Actions
          • Trigger - Turn on MovingDatMissile <gen>
          • Set AKUNIT = (Triggering unit)
          • Sound - Play TinkerMissileLaunch1 <gen>
          • Custom script: call SetUnitAnimationByIndex(udg_AKUNIT, 151)
          • Animation - Queue AKUNIT's stand animation
          • Player - Add 5 to (Owner of (Triggering unit)) Food used
          • Set MissileFiringGuy[(Player number of (Owner of (Triggering unit)))] = (Triggering unit)
          • Item - Set charges remaining in (Item carried by (Triggering unit) of type Missile) to ((Charges remaining in (Item carried by (Triggering unit) of type Missile)) - 1)
          • Set PolarPointVariable2 = ((Position of (Triggering unit)) offset by 150.00 towards (Angle from (Position of (Triggering unit)) to (Target point of ability being cast)) degrees)
          • Unit - Create 1 Missile Dummy for (Owner of (Triggering unit)) at PolarPointVariable2 facing (Angle from (Position of (Triggering unit)) to (Target point of ability being cast)) degrees
          • Custom script: call RemoveLocation(udg_PolarPointVariable2)
          • Set MISSILE[(Player number of (Owner of (Triggering unit)))] = (Last created unit)
          • Set WarheadLocation[(Player number of (Owner of (Triggering unit)))] = (Target point of ability being cast)
        • Else - Actions
  • MovingDatMissile
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Set PolarPointVariable1[(Integer A)] = ((Position of MISSILE[(Integer A)]) offset by 40.00 towards (Angle from (Position of MISSILE[(Integer A)]) to WarheadLocation[(Integer A)]) degrees)
          • Unit - Move MISSILE[(Integer A)] instantly to PolarPointVariable1[(Integer A)], facing WarheadLocation[(Integer A)]
          • Custom script: call RemoveLocation(udg_PolarPointVariable1[bj_forLoopAIndex])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Distance between (Position of MISSILE[(Integer A)]) and WarheadLocation[(Integer A)]) Less than or equal to 20.00) or ((Number of units in (Units within 75.00 of (Position of MISSILE[(Integer A)]))) Greater than 1)
            • Then - Actions
              • Set UnitGroupVariable1[(Integer A)] = (Units within 200.00 of (Position of MISSILE[(Integer A)]))
              • Unit Group - Pick every unit in UnitGroupVariable1[(Integer A)] and do (Actions)
                • Loop - Actions
                  • Sound - Play MortarImpact <gen>
                  • Special Effect - Create a special effect at (Position of MISSILE[(Integer A)]) using Abilities\Spells\Other\Doom\DoomDeath.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Unit - Cause MissileFiringGuy[(Integer A)] to damage (Picked unit), dealing 195.00 damage of attack type Chaos and damage type Universal
                  • Unit - Remove MISSILE[(Integer A)] from the game
                  • Custom script: call DestroyGroup (udg_UnitGroupVariable1[bj_forLoopAIndex])
                  • Custom script: call RemoveLocation(udg_WarheadLocation[bj_forLoopAIndex])
            • Else - Actions
      • Set UnitGroupVariable2 = (Units of type Missile Dummy)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in UnitGroupVariable2) Equal to 0
        • Then - Actions
          • Custom script: call DestroyGroup (udg_UnitGroupVariable2)
          • Trigger - Turn off (This trigger)
        • Else - Actions
Here's what I came up with, but something still seems to be missing?
 
Level 13
Joined
Mar 24, 2013
Messages
1,105
In the initial trigger you need to set position of the missile to a point and clear it.
In the Moving you need to set the position of the missile to a point and clear it also.
In the Moving the condition you need to set the position of missile and clear it. In the 2nd part of the condition you're still leaking a unit group and the aforementioned point.
When you set UnitGroupVar1 you're leaking a point.
You need to move the DestroyGroup/Remove calls to outside of the Pick Every Unit loop.
You need to destroy UnitGroupVar2 regardless of whether there are units in it, move it outside of the if statement

The 2nd UnitGroup could be avoided all together if you were to rewrite it following a format like this: http://www.hiveworkshop.com/threads/visualize-dynamic-indexing.241896/
 
Last edited:
Level 6
Joined
Apr 5, 2013
Messages
154
Well, I tried this.

  • Launch Rocket
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Missile Launcher (Neutral Hostile)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) has an item of type Missile) Equal to True
        • Then - Actions
          • Trigger - Turn on MovingDatMissile <gen>
          • Set AKUNIT = (Triggering unit)
          • Sound - Play TinkerMissileLaunch1 <gen>
          • Custom script: call SetUnitAnimationByIndex(udg_AKUNIT, 151)
          • Animation - Queue AKUNIT's stand animation
          • Player - Add 5 to (Owner of (Triggering unit)) Food used
          • Set MissileFiringGuy[(Player number of (Owner of (Triggering unit)))] = (Triggering unit)
          • Item - Set charges remaining in (Item carried by (Triggering unit) of type Missile) to ((Charges remaining in (Item carried by (Triggering unit) of type Missile)) - 1)
          • Set PolarPointVariable2 = ((Position of (Triggering unit)) offset by 150.00 towards (Angle from (Position of (Triggering unit)) to (Target point of ability being cast)) degrees)
          • Unit - Create 1 Missile Dummy for (Owner of (Triggering unit)) at PolarPointVariable2 facing (Angle from (Position of (Triggering unit)) to (Target point of ability being cast)) degrees
          • Custom script: call RemoveLocation(udg_PolarPointVariable2)
          • Set MISSILE[(Player number of (Owner of (Triggering unit)))] = (Last created unit)
          • Set WarheadLocation[(Player number of (Owner of (Triggering unit)))] = (Target point of ability being cast)
        • Else - Actions
  • MovingDatMissile
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Set PolarPointVariable1[(Integer A)] = ((Position of MISSILE[(Integer A)]) offset by 40.00 towards (Angle from (Position of MISSILE[(Integer A)]) to WarheadLocation[(Integer A)]) degrees)
          • Unit - Move MISSILE[(Integer A)] instantly to PolarPointVariable1[(Integer A)], facing WarheadLocation[(Integer A)]
          • Custom script: call RemoveLocation(udg_PolarPointVariable1[bj_forLoopAIndex])
          • Set Positionofmissile[(Integer A)] = (Position of MISSILE[(Integer A)])
          • Set UnitGroupVariable4[(Integer A)] = (Units within 200.00 of (Position of MISSILE[(Integer A)]))
          • Set UnitGroupVariable3[(Integer A)] = (Units within 75.00 of Positionofmissile[(Integer A)])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Distance between (Position of MISSILE[(Integer A)]) and WarheadLocation[(Integer A)]) Less than or equal to 20.00) or ((Number of units in UnitGroupVariable3[(Integer A)]) Greater than 1)
            • Then - Actions
              • Set UnitGroupVariable1[(Integer A)] = UnitGroupVariable4[(Integer A)]
              • Unit Group - Pick every unit in UnitGroupVariable1[(Integer A)] and do (Actions)
                • Loop - Actions
                  • Sound - Play MortarImpact <gen>
                  • Special Effect - Create a special effect at (Position of MISSILE[(Integer A)]) using Abilities\Spells\Other\Doom\DoomDeath.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Unit - Cause MissileFiringGuy[(Integer A)] to damage (Picked unit), dealing 195.00 damage of attack type Chaos and damage type Universal
                  • Unit - Remove MISSILE[(Integer A)] from the game
            • Else - Actions
      • Custom script: call DestroyGroup (udg_UnitGroupVariable1[bj_forLoopAIndex])
      • Custom script: call DestroyGroup (udg_UnitGroupVariable3[bj_forLoopAIndex])
      • Custom script: call DestroyGroup (udg_UnitGroupVariable4[bj_forLoopAIndex])
      • Custom script: call RemoveLocation(udg_Positionofmissile[bj_forLoopAIndex])
      • Custom script: call RemoveLocation(udg_WarheadLocation[bj_forLoopAIndex])
      • Set UnitGroupVariable2 = (Units of type Missile Dummy)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in UnitGroupVariable2) Equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
      • Custom script: call DestroyGroup (udg_UnitGroupVariable2)
 
Status
Not open for further replies.
Top