• 🏆 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] Need help Optimizing this

Status
Not open for further replies.
Level 12
Joined
May 20, 2009
Messages
822
Nevermind the level check, I can fix that later. (Unless that'd make less visible lag in-game) Right now, this causes some pretty noticeable lag, which is bad because this is a common unit that has this ability.


  • Sense Calc
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer SenseInit) from 1 to SenseUnitMaxIndex, do (Actions)
        • Loop - Actions
          • Set SenseUnitPoint[SenseInit] = (Position of SenseUnit[SenseInit])
          • Custom script: call RemoveLocation(GetUnitLoc(udg_SenseUnit[udg_SenseInit]))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Sense for SenseUnit[SenseInit]) Equal to 1
            • Then - Actions
              • Set SenseRange[SenseInit] = 1200.00
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Sense for SenseUnit[SenseInit]) Equal to 2
                • Then - Actions
                  • Set SenseRange[SenseInit] = 1700.00
                • Else - Actions
          • Unit Group - Pick every unit in (Units within SenseRange[SenseInit] of SenseUnitPoint[SenseInit]) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) has buff Sense ) Equal to True
                  • ((Picked unit) is A structure) Equal to False
                  • ((Picked unit) is alive) Equal to True
                  • ((Picked unit) belongs to an ally of (Owner of SenseUnit[SenseInit])) Equal to False
                  • Or - Any (Conditions) are true
                    • Conditions
                      • ((Picked unit) belongs to an enemy of (Owner of SenseUnit[SenseInit])) Equal to True
                      • (Owner of (Picked unit)) Equal to Neutral Hostile
                      • (Owner of (Picked unit)) Equal to Neutral Victim
                      • (Owner of (Picked unit)) Equal to Neutral Extra
                      • (Owner of (Picked unit)) Equal to Neutral Passive
                • Then - Actions
                  • Set SensedPointMaxIndex = (SensedPointMaxIndex + 1)
                  • Set SensedUnitPoint[SensedPointMaxIndex] = (Position of (Picked unit))
                  • Custom script: call RemoveLocation(GetUnitLoc(GetEnumUnit()))
                  • For each (Integer SensedUnitInit) from 1 to SensedPointMaxIndex, do (Actions)
                    • Loop - Actions
                      • Unit - Create 1 Dummy Sense Unit for (Owner of SenseUnit[SenseInit]) at SensedUnitPoint[SensedUnitInit] facing SensedUnitPoint[SensedUnitInit]
                      • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
                      • Custom script: call RemoveLocation(udg_SensedUnitPoint[udg_SensedUnitInit])
                  • Custom script: call DestroyGroup(GetLastCreatedGroup())
                  • Custom script: call DestroyGroup(udg_SensingUnitGroup)
                • Else - Actions



  • Orb of Shadow Curse Calc
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (GDD_DamagedUnit has buff Curse (Orb of Shadow)) Equal to True
        • Then - Actions
          • Set RandomInitPayOut = (Random integer number between 1 and 5)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomInitPayOut Equal to 5
            • Then - Actions
              • Set RandomInitPayOut = 4
            • Else - Actions
          • For each (Integer RandomInit) from 1 to RandomInitPayOut, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RandomInit Equal to 4
                • Then - Actions
                  • Set RandomInitPayOut = 0
                  • Game - Display to (All players) the text: (RandomInit has become equal to + ((String(RandomInit)) + !)) \\Debug text
                  • Unit - Remove Curse (Orb of Shadow) buff from GDD_DamagedUnit
                  • Unit - Create 1 Dummy Ability Unit 1 for (Owner of GDD_DamageSource) at (Position of GDD_DamagedUnit) facing (Position of GDD_DamagedUnit)
                  • Unit - Order (Last created unit) to Undead Banshee - Curse GDD_DamagedUnit
                  • Unit - Add a 3.00 second Generic expiration timer to (Last created unit)
                • Else - Actions
        • Else - Actions
Does this achieve in making a 2/5 chance? (40%)
Also, I'll fix the leaks on this later.
 
Last edited:
Level 11
Joined
Oct 11, 2012
Messages
711
I am not good at GUI, but I think you should use a "set up" trigger (setting the range) to avoid having three loops in one trigger. Also, I don't think you need to store and remove the locations of "GetEnumUnit()" in the second loop.
You remove the location right after you store it to a variable:
  • Set SenseUnitPoint[SenseInit] = (Position of SenseUnit[SenseInit])
  • Custom script: call RemoveLocation(GetUnitLoc(udg_SenseUnit[udg_SenseInit]))
I don't think this is right. You should remove it when you won't use it anymore for this trigger.
 
call RemoveLocation(GetUnitLoc(unit)) doesnt make sense at all. "GetUnitLoc" returns a location, and you immediatly remove this location. :S
You should read a tutorial about memory leaks: http://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/

Store "Picked unit" into a variable at begining, and further work with the variable to prevent unneeded function calls.

The lag might come of a lot of unit creations at same time.
 
Level 12
Joined
May 20, 2009
Messages
822
Yeah, I was thinking the same thing but I have no way of knowing for sure...So I need to ask for help, because I don't know how to fix that if that IS the issue...

And as for the RemoveLocation thing, I don't know what I was thinking. xD

Does "Set SensedUnitPoint[SensedPointMaxIndex] = (Position of (Picked unit))" not leak a location? That was kind of the track of mind I was on but I dunno why I did that function...xD
 
Level 11
Joined
Oct 11, 2012
Messages
711
Yeah, I was thinking the same thing but I have no way of knowing for sure...So I need to ask for help, because I don't know how to fix that if that IS the issue...

And as for the RemoveLocation thing, I don't know what I was thinking. xD

Does "Set SensedUnitPoint[SensedPointMaxIndex] = (Position of (Picked unit))" not leak a location? That was kind of the track of mind I was on but I dunno why I did that function...xD

(Position of (Picked unit)) < ------ this does leak a location. So thats why you store it to a variable and then remove it.
"Set SensedUnitPoint[SensedPointMaxIndex] = (Position of (Picked unit))" <----this just store the location in a variable, the action itself does not leak. I hope that doesn't sound confusing to you. :)
 
Level 12
Joined
May 20, 2009
Messages
822
(Position of (Picked unit)) < ------ this does leak a location. So thats why you store it to a variable and then remove it.
"Set SensedUnitPoint[SensedPointMaxIndex] = (Position of (Picked unit))" <----this just store the location in a variable, the action itself does not leak. I hope that doesn't sound confusing to you. :)

Nah, I get it. Thanks. =)

So then does anyone know how I can fix the super-lag issue when the units spawn? I mean even if it's just ONE Archer on the entire map doing this, you can still VISIBLY see a drop in frames.
 
Level 12
Joined
May 20, 2009
Messages
822
I will have to make a separate map, because it has a lot of stuff I wanna keep secret until my work is done.

So, I'll get on that and edit this post when it's ready.

EDIT: K, a test map is attached to this post.
 

Attachments

  • SenseTestMap.w3x
    20.9 KB · Views: 31
Last edited:
Level 12
Joined
May 20, 2009
Messages
822
Alright, let me try again then...

EDIT: Maybe I should have tested it before I uploaded it...It's not even functioning properly.

For now, I'll put this on hold and update this post tomorrow with a new map...Sorry but it's just a little too late for me to be doing this stuff.
 
Status
Not open for further replies.
Top