• 🏆 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] Why is this trigger not "random"

Status
Not open for further replies.
Level 6
Joined
Feb 10, 2011
Messages
188
I am working on a Risk game and I am working on the give bases to player trigger. Basically it counts the number of bases and the number of players, then iterates through the players assigning random bases. The problem is that its not really random, bases are always assigned the same.

  • Randomize Bases
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • -------- Count Bases --------
      • Set tempGroup1 = (Units owned by Neutral Hostile matching ((((Matching unit) is A structure) Equal to True) and (((Matching unit) is alive) Equal to True)))
      • Set numOfBases = (Number of units in tempGroup1)
      • -------- Count Players --------
      • Set tempForce1 = (All players matching (((Matching player) slot status) Equal to Is playing))
      • Set numOfPlayers = (Number of players in tempForce1)
      • Set numOfBasesPerPlayer = (numOfBases / numOfPlayers)
      • -------- Create Bases --------
      • Unit Group - Pick every unit in tempGroup1 and do (Actions)
        • Loop - Actions
          • Set tempUnit1 = (Picked unit)
          • Set tempPlayer1 = (Random player from tempForce1)
          • Set tempPoint1 = (Position of tempUnit1)
          • Set tempPoint2 = (tempPoint1 offset by (0.00, -220.00))
          • Unit - Create 1 defaultUnitType for Neutral Hostile at tempPoint2 facing Default building facing degrees
          • Set tempUnit2 = (Last created unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • tempInt[(Player number of tempPlayer1)] Less than numOfBasesPerPlayer
            • Then - Actions
              • Unit - Change ownership of tempUnit1 to tempPlayer1 and Change color
              • Unit - Change ownership of tempUnit2 to tempPlayer1 and Change color
              • Unit - Order tempUnit1 to Undead Necromancer - Unholy Frenzy tempUnit2
              • Set tempInt[(Player number of tempPlayer1)] = (tempInt[(Player number of tempPlayer1)] + 1)
            • Else - Actions
          • Custom script: call RemoveLocation( udg_tempPoint1 )
          • Custom script: set udg_tempPoint1 = null
          • Custom script: call RemoveLocation( udg_tempPoint2 )
          • Custom script: set udg_tempPoint2 = null
          • Custom script: set udg_tempUnit1 = null
          • Custom script: set udg_tempUnit2 = null
          • Player Group - Remove tempPlayer1 from tempForce1
          • Player Group - Add tempPlayer1 to tempForce2
          • Custom script: set udg_tempPlayer1 = null
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of players in tempForce1) Equal to 0
            • Then - Actions
              • Player Group - Pick every player in tempForce2 and do (Actions)
                • Loop - Actions
                  • Player Group - Add (Picked player) to tempForce1
                  • Player Group - Remove (Picked player) from tempForce2
            • Else - Actions
      • Set tempGroup2 = (Units owned by Neutral Hostile matching ((((Matching unit) is A structure) Equal to True) and (((Matching unit) is alive) Equal to True)))
      • Unit Group - Pick every unit in tempGroup2 and do (Actions)
        • Loop - Actions
          • Set tempUnit1 = (Picked unit)
          • Set tempPlayer1 = (Owner of tempUnit1)
          • Set tempPoint1 = (Position of tempUnit1)
          • Set tempPoint2 = (tempPoint1 offset by 300.00 towards 270.00 degrees)
          • Set G_TempGroup = (Units within 150.00 of tempPoint2 matching ((((((Matching unit) is alive) Equal to True) and (((Matching unit) is in G_Group) Not equal to True)) and (((Matching unit) is A structure) Not equal to True)) and ((Owner of (Matching unit)) Equal to tempPlayer1))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (G_TempGroup is empty) Equal to False
            • Then - Actions
              • Unit - Order tempUnit1 to Undead Necromancer - Unholy Frenzy (Random unit from G_TempGroup)
            • Else - Actions
              • Unit - Create 1 dummyType for tempPlayer1 at tempPoint2 facing 270.00 degrees
              • Unit - Order tempUnit1 to Undead Necromancer - Unholy Frenzy (Last created unit)
          • Custom script: call RemoveLocation( udg_tempPoint1 )
          • Custom script: set udg_tempPoint1 = null
          • Custom script: call RemoveLocation( udg_tempPoint2 )
          • Custom script: set udg_tempPoint2 = null
          • Custom script: set udg_tempUnit1 = null
          • Custom script: set udg_tempPlayer1 = null
          • Custom script: call DestroyGroup (udg_G_TempGroup)
      • Custom script: call DestroyForce( udg_tempForce1 )
      • Custom script: set udg_tempForce1 = null
      • Custom script: call DestroyForce( udg_tempForce2 )
      • Custom script: set udg_tempForce2 = null
      • Custom script: call DestroyGroup( udg_tempGroup1 )
      • Custom script: set udg_tempGroup1 = null
      • Custom script: call DestroyGroup( udg_tempGroup2 )
      • Custom script: set udg_tempGroup2 = null
      • Custom script: call DestroyTrigger( GetTriggeringTrigger() )
 
Last edited:
Level 6
Joined
Feb 10, 2011
Messages
188
I have remade the trigger it seems to work as intended now. does it leak? can i make it more efficient?


  • Randomize Bases
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • -------- Count Bases --------
      • Set tempGroup1 = (Units owned by Neutral Hostile matching ((((Matching unit) is A structure) Equal to True) and (((Matching unit) is alive) Equal to True)))
      • Set numOfBases = (Number of units in tempGroup1)
      • -------- Count Players --------
      • Set tempForce1 = (All players matching (((Matching player) slot status) Equal to Is playing))
      • Set numOfPlayers = (Number of players in tempForce1)
      • Set numOfBasesPerPlayer = (numOfBases / numOfPlayers)
      • -------- Create Bases --------
      • Unit Group - Pick every unit in tempGroup1 and do (Actions)
        • Loop - Actions
          • Set tempUnit1 = (Picked unit)
          • Set tempPlayer1 = (Random player from tempForce1)
          • Set tempPoint1 = (Position of tempUnit1)
          • Set tempPoint2 = (tempPoint1 offset by (0.00, -220.00))
          • Unit - Create 1 Marine Warrior for Neutral Hostile at tempPoint2 facing Default building facing degrees
          • Set tempUnit2 = (Last created unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • tempInt[(Player number of tempPlayer1)] Less than numOfBasesPerPlayer
            • Then - Actions
              • Unit - Change ownership of tempUnit1 to tempPlayer1 and Change color
              • Unit - Change ownership of tempUnit2 to tempPlayer1 and Change color
              • Unit - Order tempUnit1 to Undead Necromancer - Unholy Frenzy tempUnit2
              • Set tempInt[(Player number of tempPlayer1)] = (tempInt[(Player number of tempPlayer1)] + 1)
            • Else - Actions
          • Custom script: call RemoveLocation( udg_tempPoint1 )
          • Custom script: call RemoveLocation( udg_tempPoint2 )
          • Custom script: set udg_tempUnit1 = null
          • Custom script: set udg_tempUnit2 = null
          • Player Group - Remove tempPlayer1 from tempForce1
          • Player Group - Add tempPlayer1 to tempForce2
          • Custom script: set udg_tempPlayer1 = null
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of players in tempForce1) Equal to 0
            • Then - Actions
              • Player Group - Pick every player in tempForce2 and do (Actions)
                • Loop - Actions
                  • Player Group - Add (Picked player) to tempForce1
                  • Player Group - Remove (Picked player) from tempForce2
            • Else - Actions
      • Set tempGroup2 = (Units owned by Neutral Hostile matching ((((Matching unit) is A structure) Equal to True) and (((Matching unit) is alive) Equal to True)))
      • Unit Group - Pick every unit in tempGroup2 and do (Actions)
        • Loop - Actions
          • Set G_TempGroup = (Units within 150.00 of ((Position of (Picked unit)) offset by 300.00 towards 270.00 degrees) matching ((((((Matching unit) is alive) Equal to True) and (((Matching unit) is in G_Group) Not equal to True)) and (((Matching unit) is A structure) Not equal to Tr
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (G_TempGroup is empty) Equal to False
            • Then - Actions
              • Unit - Order (Picked unit) to Undead Necromancer - Unholy Frenzy (Random unit from G_TempGroup)
            • Else - Actions
              • Unit - Create 1 Guard Station for (Owner of (Picked unit)) at ((Position of (Picked unit)) offset by 300.00 towards 270.00 degrees) facing 270.00 degrees
              • Unit - Order (Picked unit) to Undead Necromancer - Unholy Frenzy (Last created unit)
          • Custom script: call DestroyGroup (udg_G_TempGroup)
      • Custom script: call DestroyForce( udg_tempForce1 )
      • Custom script: set udg_tempForce1 = null
      • Custom script: call DestroyForce( udg_tempForce2 )
      • Custom script: set udg_tempForce2 = null
      • Custom script: call DestroyGroup( udg_tempGroup1 )
      • Custom script: set udg_tempGroup1 = null
      • Custom script: call DestroyGroup( udg_tempGroup2 )
      • Custom script: set udg_tempGroup2 = null
      • Custom script: call DestroyTrigger( GetTriggeringTrigger() )
 
Last edited:

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
No leaks that I can spot. Efficiency isn't a factor in a script that runs once.

Edit: here are some leaks: Set G_TempGroup = (Units within 150.00 of ((Position of (Picked unit)) offset by 300.00 towards 270.00 degrees) matching ((((((Matching unit) is alive) Equal to True) and (((Matching unit) is in G_Group) Not equal to True)) and (((Matching unit) is A structure) Not equal to True
 
Level 6
Joined
Feb 10, 2011
Messages
188
Ok thankyou bribe I think I fixed the leak could you check it out?

Also when this trigger runs it makes the game pretty much freeze for about 30seconds to a minute, that is why I was concerned about efficiency. Is there a way I can change this to make it not freeze up the game. Starting a game with it freezing for a minute is not appealing. I tried to cover it up with the cinematic screen but for some reason I cant get it to work, the screen waits till after this trigger runs even tough I turn on cinematic mode first

  • Randomize Bases
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • -------- Count Bases --------
      • Set tempGroup1 = (Units owned by Neutral Hostile matching ((((Matching unit) is A structure) Equal to True) and (((Matching unit) is alive) Equal to True)))
      • Set numOfBases = (Number of units in tempGroup1)
      • -------- Count Players --------
      • Set tempForce1 = (All players matching (((Matching player) slot status) Equal to Is playing))
      • Set numOfPlayers = (Number of players in tempForce1)
      • Set numOfBasesPerPlayer = (numOfBases / numOfPlayers)
      • -------- Create Bases --------
      • Unit Group - Pick every unit in tempGroup1 and do (Actions)
        • Loop - Actions
          • Set tempUnit1 = (Picked unit)
          • Set tempPlayer1 = (Random player from tempForce1)
          • Set tempPoint1 = (Position of tempUnit1)
          • Set tempPoint2 = (tempPoint1 offset by (0.00, -220.00))
          • Unit - Create 1 defaultUnitType for Neutral Hostile at tempPoint2 facing Default building facing degrees
          • Set tempUnit2 = (Last created unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • tempInt[(Player number of tempPlayer1)] Less than numOfBasesPerPlayer
            • Then - Actions
              • Unit - Change ownership of tempUnit1 to tempPlayer1 and Change color
              • Unit - Change ownership of tempUnit2 to tempPlayer1 and Change color
              • Unit - Order tempUnit1 to Undead Necromancer - Unholy Frenzy tempUnit2
              • Set tempInt[(Player number of tempPlayer1)] = (tempInt[(Player number of tempPlayer1)] + 1)
            • Else - Actions
          • Custom script: call RemoveLocation( udg_tempPoint1 )
          • Custom script: set udg_tempPoint1 = null
          • Custom script: call RemoveLocation( udg_tempPoint2 )
          • Custom script: set udg_tempPoint2 = null
          • Custom script: set udg_tempUnit1 = null
          • Custom script: set udg_tempUnit2 = null
          • Player Group - Remove tempPlayer1 from tempForce1
          • Player Group - Add tempPlayer1 to tempForce2
          • Custom script: set udg_tempPlayer1 = null
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of players in tempForce1) Equal to 0
            • Then - Actions
              • Player Group - Pick every player in tempForce2 and do (Actions)
                • Loop - Actions
                  • Player Group - Add (Picked player) to tempForce1
                  • Player Group - Remove (Picked player) from tempForce2
            • Else - Actions
      • Set tempGroup2 = (Units owned by Neutral Hostile matching ((((Matching unit) is A structure) Equal to True) and (((Matching unit) is alive) Equal to True)))
      • Unit Group - Pick every unit in tempGroup2 and do (Actions)
        • Loop - Actions
          • Set tempUnit1 = (Picked unit)
          • Set tempPlayer1 = (Owner of tempUnit1)
          • Set tempPoint1 = (Position of tempUnit1)
          • Set tempPoint2 = (tempPoint1 offset by 300.00 towards 270.00 degrees)
          • Set G_TempGroup = (Units within 150.00 of tempPoint2 matching ((((((Matching unit) is alive) Equal to True) and (((Matching unit) is in G_Group) Not equal to True)) and (((Matching unit) is A structure) Not equal to True)) and ((Owner of (Matching unit)) Equal to tempPlayer1))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (G_TempGroup is empty) Equal to False
            • Then - Actions
              • Unit - Order tempUnit1 to Undead Necromancer - Unholy Frenzy (Random unit from G_TempGroup)
            • Else - Actions
              • Unit - Create 1 dummyType for tempPlayer1 at tempPoint2 facing 270.00 degrees
              • Unit - Order tempUnit1 to Undead Necromancer - Unholy Frenzy (Last created unit)
          • Custom script: call RemoveLocation( udg_tempPoint1 )
          • Custom script: set udg_tempPoint1 = null
          • Custom script: call RemoveLocation( udg_tempPoint2 )
          • Custom script: set udg_tempPoint2 = null
          • Custom script: set udg_tempUnit1 = null
          • Custom script: set udg_tempPlayer1 = null
          • Custom script: call DestroyGroup (udg_G_TempGroup)
      • Custom script: call DestroyForce( udg_tempForce1 )
      • Custom script: set udg_tempForce1 = null
      • Custom script: call DestroyForce( udg_tempForce2 )
      • Custom script: set udg_tempForce2 = null
      • Custom script: call DestroyGroup( udg_tempGroup1 )
      • Custom script: set udg_tempGroup1 = null
      • Custom script: call DestroyGroup( udg_tempGroup2 )
      • Custom script: set udg_tempGroup2 = null
      • Custom script: call DestroyTrigger( GetTriggeringTrigger() )
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
You do not need to null variables in GUI.

To me, it seems impossible for the trigger to freeze your game. Even the trigger contained 100 leaks it wouldn't matter. And since this trigger is only run once, it seems close to impossible without infinite loops, which you don't have.

If you disable the trigger, does it lag? Check that.

edit: I did a quick test, this trigger counted to 3500 and I still didn't lag. So I am pretty certain that trigger is not the cause.
  • Untitled Trigger 001
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Set counter = (counter + 1.00)
      • Game - Display to (All players) the text: ((String(counter)) + leaks)
      • Set loc = (Random point in (Playable map area))
 
Level 6
Joined
Feb 10, 2011
Messages
188
does nulling variables effect performance? should I remove the null custom scripts?

I just tested it with the trigger disabled, there was no lag at all. So it has to be from this trigger. Keep in mind it doesn't freeze the game to where you have to restart, it only freezes the game for about 30 seconds to 1 min while this trigger runs. Once the trigger is done running there is no more freeze/lag

The trigger loops roughly 193 times (there is 193 command centers)


I can give you the map if you would like to test it yourself.
 
Level 6
Joined
Feb 10, 2011
Messages
188
Don't worry about that, my flawless testing methods will fix it. Don't change anything just yet xD

Give me an hour max, depends on my luck.

lol ok. dont make fun of my other triggering in the map if it sucks :p
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Okay, so I have done some testing now. With only said trigger enabled, it does indeed freeze the game.

I removed about the bottom half of the trigger to see in which part the problem lied, as it turns out the first unit group is the issue. I deleted the player group inside the unit group to make sure this was true, and it made no difference.

As such, I deleted almost all units from the map, which made the total unit count go from 192 to 32, the lag is gone. So it's the number of units that cause the lag.

But the actions inside the unit group are not very heavy so I don't think that's the actual issue. The GUI unit group got a limit of 64 units max or something like that, thus is suspect that has to do with the lag somehow. I will confirmed this in a a few minutes.

edit: Does not seem to be the case but I will continue to test for a while.

edit2: Found it.

Remove the following and the lag is gone.
  • Unit - Change ownership of tempUnit1 to tempPlayer1 and Change color
  • Unit - Change ownership of tempUnit2 to tempPlayer1 and Change color
 
Level 6
Joined
Feb 10, 2011
Messages
188
Well thats like the biggest part of the trigger haha.
I guess I have to start to figure out a work around?

well thanks for finding the issues, I will probably remake the trigger or just change it up a little.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Yeah that's the difficult part, normally we'd just replace those lines with the jass versions because that's more efficient in most cases. Sadly this is an exception, the jass and gui is the same here.

My only idea is to do it periodically.
Pick one random unit from the tempGroup1 ever 0.01- seconds and do the stuff to it. Then remove him from the group.
 
Status
Not open for further replies.
Top