• 🏆 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] Count Index not resetting

Status
Not open for further replies.
Level 4
Joined
Jan 17, 2018
Messages
112
  • Spawn FanaticsER
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in FanaticsERGroup and do (Actions)
        • Loop - Actions
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Count[(Player number of (Picked player))] = 0
          • Set FanaticsERLoc = (Position of (Picked unit))
          • Set FanaticsERG = (Units within 250.00 of FanaticsERLoc matching ((Unit-type of (Matching unit)) Equal to Peasant))
          • Custom script: call RemoveLocation(udg_FanaticsERLoc)
          • Unit Group - Remove (Picked unit) from FanaticsERG
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in FanaticsERG and do (Actions)
            • Loop - Actions
              • Set Index = (Player number of (Owner of (Picked unit)))
              • Set Count[Index] = (Count[Index] + 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Count[Index] Equal to 3
                • Then - Actions
                  • Unit Group - Pick every unit in FanaticsERG and do (Unit - Kill (Picked unit))
                • Else - Actions
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Index = (Player number of (Picked player))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Count[Index] Greater than or equal to 3
                • Then - Actions
                  • Set FanaticsERLoc = ((Picked player) start location)
                  • Unit - Create 5 Goblin Sapper for (Picked player) at FanaticsERLoc facing Default building facing degrees
                  • Custom script: call RemoveLocation(udg_FanaticsERLoc)
                  • Wait 0.00 seconds
                  • Set Count[Index] = (Count[Index] - 3)
                • Else - Actions
When I have 3 units in FanaticsERGroup, they get killed but the Count[Index] counter doesn't want to go to zero, I've tried "Set Count[Index] = 0" and still nothing, and I also put that Wait 0 seconds in there and still nothing.
 
Level 7
Joined
Mar 10, 2013
Messages
366
  • Spawn FanaticsER
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in FanaticsERGroup and do (Actions)
        • Loop - Actions
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Count[(Player number of (Picked player))] = 0
          • Set FanaticsERLoc = (Position of (Picked unit))
          • Set FanaticsERG = (Units within 250.00 of FanaticsERLoc matching ((Unit-type of (Matching unit)) Equal to Peasant))
          • Custom script: call RemoveLocation(udg_FanaticsERLoc)
          • Unit Group - Remove (Picked unit) from FanaticsERG
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in FanaticsERG and do (Actions)
            • Loop - Actions
              • Set Index = (Player number of (Owner of (Picked unit)))
              • Set Count[Index] = (Count[Index] + 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Count[Index] Equal to 3
                • Then - Actions
                  • Unit Group - Pick every unit in FanaticsERG and do (Unit - Kill (Picked unit))
                • Else - Actions
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Index = (Player number of (Picked player))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Count[Index] Greater than or equal to 3
                • Then - Actions
                  • Set FanaticsERLoc = ((Picked player) start location)
                  • Unit - Create 5 Goblin Sapper for (Picked player) at FanaticsERLoc facing Default building facing degrees
                  • Custom script: call RemoveLocation(udg_FanaticsERLoc)
                  • Set Count[Index] = 0
                • Else - Actions
There no real reason to put a wait there. And just setting to 0 is good as well. Are you certain that this section is firing?
  • If - Conditions
    • Count[Index] Greater than or equal to
    • Then - Actions
      • Set FanaticsERLoc = ((Picked player) start location)
      • Unit - Create 5 Goblin Sapper for (Picked player) at FanaticsERLoc facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_FanaticsERLoc)
      • Set Count[Index] = 0
Otherwise I think you might have a problem with your 'picked unit' variable. I'm not certain now, but they both use the same global. So when you do a loop inside a loop of the same group of units, 'picked unit' ends as the last one after the inner loop, but I may be wrong.

Also to have a better debug of this, you could make the elapser slower and add some 'custom script: BjDebugMsg(udg_Count[0])' and for other variable as well, just to be certain that it's really not working.
 
Level 13
Joined
May 10, 2009
Messages
868
Waits should not be used within Unit and Player groups.

upload_2018-3-10_16-29-15.png
 
Level 4
Joined
Jan 17, 2018
Messages
112
  • Spawn FanaticsER
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in FanaticsERGroup and do (Actions)
        • Loop - Actions
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Count[(Player number of (Picked player))] = 0
          • Set FanaticsERLoc = (Position of (Picked unit))
          • Set FanaticsERG = (Units within 250.00 of FanaticsERLoc matching ((Unit-type of (Matching unit)) Equal to Peasant))
          • Custom script: call RemoveLocation(udg_FanaticsERLoc)
          • Unit Group - Remove (Picked unit) from FanaticsERG
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in FanaticsERG and do (Actions)
            • Loop - Actions
              • Set Index = (Player number of (Owner of (Picked unit)))
              • Set Count[Index] = (Count[Index] + 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Count[Index] Equal to 3
                  • ((Picked unit) is alive) Equal to True
                • Then - Actions
                  • Unit Group - Pick every unit in FanaticsERG and do (Unit - Kill (Picked unit))
                • Else - Actions
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Index = (Player number of (Picked player))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Count[Index] Greater than or equal to 3
                  • ((Picked unit) is alive) Equal to True
                • Then - Actions
                  • Set FanaticsERLoc = ((Picked player) start location)
                  • Unit - Create 5 Goblin Sapper for (Picked player) at FanaticsERLoc facing Default building facing degrees
                  • Custom script: call RemoveLocation(udg_FanaticsERLoc)
                • Else - Actions
I've added the matching unit is alive to either side and also to both as above, but it still creates 5 every second.
 
Level 13
Joined
May 10, 2009
Messages
868
Could you provide a description of what you are trying to do? I mean, what type of unit gets added to FanaticsERGroup? Should it count the number of units in FanaticsERGroup or another specific unit type? Who should be killed once it counts to 3?

Also
  • Unit Group - Pick every unit in FanaticsERG and do (Actions)
    • Loop - Actions
      • Set Index = (Player number of (Owner of (Picked unit)))
      • Set Count[Index] = (Count[Index] + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Count[Index] Equal to 3
          • ((Picked unit) is alive) Equal to True
        • Then - Actions
          • Unit Group - Pick every unit in FanaticsERG and do (Unit - Kill (Picked unit))
        • Else - Actions
That's still counting dead units.
 
Level 4
Joined
Jan 17, 2018
Messages
112
Could you provide a description of what you are trying to do? I mean, what type of unit gets added to FanaticsERGroup? Should it count the number of units in FanaticsERGroup or another specific unit type? Who should be killed once it counts to 3?

Also
  • Unit Group - Pick every unit in FanaticsERG and do (Actions)
    • Loop - Actions
      • Set Index = (Player number of (Owner of (Picked unit)))
      • Set Count[Index] = (Count[Index] + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Count[Index] Equal to 3
          • ((Picked unit) is alive) Equal to True
        • Then - Actions
          • Unit Group - Pick every unit in FanaticsERG and do (Unit - Kill (Picked unit))
        • Else - Actions
That's still counting dead units.

The FanaticsERGroup is a circle of power, once 3 peasants stand on it, they should die and spawn 5 goblin sappers at their base, the starting point basically.
 
Level 13
Joined
May 10, 2009
Messages
868
I decided to help you out with this. Well, I took into consideration (or assumed) that in your map there could be more than one circle of power, and also that they do not count units globally - for example, a player not being able to use two circles of power in order to convert 3 units into goblin sappers (2 stand on circle A, and the last one stands on B).

So, I used 1 unit group for storing pre-placed circles of power, and 1 player group for all players (optional). Then, in my "loop trigger", I added the player group first and nested the Circle of Power group within it, and at last, another unit group is used for detecting nearby units too.

  • Convert Units at CoP
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in SQ_AllPlayers and do (Actions)
        • Loop - Actions
          • Set tmp_player = (Picked player)
          • Set tmp_pid = (Player number of tmp_player)
          • Unit Group - Pick every unit in SQ_CoP and do (Actions)
            • Loop - Actions
              • Set SQ_QueuedCounter = 0
              • Set tmp_point[0] = (Position of (Picked unit))
              • Custom script: set bj_wantDestroyGroup = true
              • Unit Group - Pick every unit in (Units within SQ_CircleAoE of tmp_point[0]) and do (Actions)
                • Loop - Actions
                  • Set tmp_unit = (Picked unit)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of tmp_unit) Equal to SQ_ConversionUnit
                      • (tmp_unit is dead) Equal to False
                      • (Owner of tmp_unit) Equal to tmp_player
                    • Then - Actions
                      • Set SQ_QueuedCounter = (SQ_QueuedCounter + 1)
                      • Set SQ_QueuedUnit[SQ_QueuedCounter] = tmp_unit
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • SQ_QueuedCounter Equal to SQ_ConversionRequirement
                        • Then - Actions
                          • Set tmp_point[1] = (tmp_player start location)
                          • Unit - Create SQ_SpawnNumber SQ_SpawnUnit for tmp_player at tmp_point[1] facing Default building facing degrees
                          • For each (Integer SQ_Loop) from 1 to SQ_QueuedCounter, do (Actions)
                            • Loop - Actions
                              • Unit - Kill SQ_QueuedUnit[SQ_Loop]
                              • Special Effect - Create a special effect attached to the SQ_SFX_Attachment of SQ_QueuedUnit[SQ_Loop] using SQ_SFX_Sacrifice
                              • Special Effect - Destroy (Last created special effect)
                          • Set SQ_QueuedCounter = 0
                          • Custom script: call RemoveLocation(udg_tmp_point[1])
                        • Else - Actions
                    • Else - Actions
              • Custom script: call RemoveLocation(udg_tmp_point[0])
This way you just do everything at once; That means, you'll know which player and which CoP is being enumerated, and then it's possible to perform your actions on them without worrying about hashtables or simulating 2D arrays.

I believe there are some things you might want to change from my trigger. For example, dealing with players that left the game, or perhaps circles of power that may be added/killed/removed from the game.

Overall, this trigger does its job, but I, personally, don't like it for having too much nested loops. Perhaps it'd be better using a table + a unit enters rect event? Oh well...


Core Triggers

Settings
  • Config Conversion and Register Preplaced CoPs
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • -------- SETTINGS - BEGIN --------
      • Set SQ_CircleOfPower = Circle of Power (large)
      • Set SQ_ConversionUnit = Peasant
      • Set SQ_ConversionRequirement = 3
      • Set SQ_SpawnUnit = Goblin Sapper
      • Set SQ_SpawnNumber = 5
      • Set SQ_CircleAoE = 170.00
      • Set SQ_SFX_Sacrifice = Abilities\Spells\Undead\DarkRitual\DarkRitualTarget.mdl
      • Set SQ_SFX_Attachment = origin
      • -------- SETTINGS - END --------
      • -------- Register preplaced circles of power and players --------
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • Set tmp_unit = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of tmp_unit) Equal to SQ_CircleOfPower
            • Then - Actions
              • Unit Group - Add tmp_unit to SQ_CoP
            • Else - Actions
      • -------- The following is not really needed, but I like to avoid calling functions needlessly. GetPlayersAll() = (All Players) --------
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Player Group - Add (Picked player) to SQ_AllPlayers
      • -------- Preload units? --------
      • Set tmp_point[0] = (Center of (Playable map area))
      • Unit - Create 1 SQ_ConversionUnit for Neutral Passive at tmp_point[0] facing Default building facing degrees
      • Unit - Remove (Last created unit) from the game
      • Unit - Create 1 SQ_SpawnUnit for Neutral Passive at tmp_point[0] facing Default building facing degrees
      • Unit - Remove (Last created unit) from the game
      • Custom script: call RemoveLocation(udg_tmp_point[0])
Loop
  • Convert Units at CoP
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in SQ_AllPlayers and do (Actions)
        • Loop - Actions
          • Set tmp_player = (Picked player)
          • Set tmp_pid = (Player number of tmp_player)
          • Unit Group - Pick every unit in SQ_CoP and do (Actions)
            • Loop - Actions
              • Set SQ_QueuedCounter = 0
              • Set tmp_point[0] = (Position of (Picked unit))
              • Custom script: set bj_wantDestroyGroup = true
              • Unit Group - Pick every unit in (Units within SQ_CircleAoE of tmp_point[0]) and do (Actions)
                • Loop - Actions
                  • Set tmp_unit = (Picked unit)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of tmp_unit) Equal to SQ_ConversionUnit
                      • (tmp_unit is dead) Equal to False
                      • (Owner of tmp_unit) Equal to tmp_player
                    • Then - Actions
                      • Set SQ_QueuedCounter = (SQ_QueuedCounter + 1)
                      • Set SQ_QueuedUnit[SQ_QueuedCounter] = tmp_unit
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • SQ_QueuedCounter Equal to SQ_ConversionRequirement
                        • Then - Actions
                          • Set tmp_point[1] = (tmp_player start location)
                          • Unit - Create SQ_SpawnNumber SQ_SpawnUnit for tmp_player at tmp_point[1] facing Default building facing degrees
                          • For each (Integer SQ_Loop) from 1 to SQ_QueuedCounter, do (Actions)
                            • Loop - Actions
                              • Unit - Kill SQ_QueuedUnit[SQ_Loop]
                              • Special Effect - Create a special effect attached to the SQ_SFX_Attachment of SQ_QueuedUnit[SQ_Loop] using SQ_SFX_Sacrifice
                              • Special Effect - Destroy (Last created special effect)
                          • Set SQ_QueuedCounter = 0
                          • Custom script: call RemoveLocation(udg_tmp_point[1])
                        • Else - Actions
                    • Else - Actions
              • Custom script: call RemoveLocation(udg_tmp_point[0])
Optional Triggers

Add future CoPs
  • Should We Add Future CoPs
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to SQ_CircleOfPower
    • Actions
      • Unit Group - Add (Triggering unit) to SQ_CoP
When a circle of power gets killed
  • Is it possible to kill a CoP
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to SQ_CircleOfPower
    • Actions
      • Unit Group - Remove (Triggering unit) from SQ_CoP
 

Attachments

  • SpawnSappers.w3x
    21.9 KB · Views: 30
Last edited:
Level 4
Joined
Jan 17, 2018
Messages
112

Thanks alot, while walking home today I was thinking of implementing what I'd like into 2 triggers, not like you did, but I sort of had an idea.

And yea, I forget that explaining to the T is a necessity, but your assumptions are spot on.

You said something that got me worried though, I have to modify triggers to take into consideration players that left? Isn't the player number fixed no matter who stays and leaves?
 
Level 13
Joined
May 10, 2009
Messages
868
I have to modify triggers to take into consideration players that left?
Not necessarily. Depending on your map, it could even be worse making peasants unable to be converted into goblins for players that left the game - I mean, perhaps other players are capable of controlling units from that player.

However, if you want to render units from "leavers" unable to become goblins, then you just need to remove them from the group, simply using a trigger like this:
  • Player Leaves
    • Events
      • Player - Player 1 (Red) leaves the game
      • Player - Player 2 (Blue) leaves the game
      • Player - Player 3 (Teal) leaves the game
      • Player - Player 4 (Purple) leaves the game
      • Player - Player 5 (Yellow) leaves the game
      • Player - Player 6 (Orange) leaves the game
      • -------- [...] --------
    • Conditions
    • Actions
      • Player Group - Remove (Triggering player) from SQ_AllPlayers
 
Last edited:

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
When I have 3 units in FanaticsERGroup, they get killed but the Count[Index] counter doesn't want to go to zero, I've tried "Set Count[Index] = 0" and still nothing, and I also put that Wait 0 seconds in there and still nothing.
Probably because of the thread crash induced by the TriggerSleepAction.

TriggerSleepAction (wait) cannot be run inside callback functions such as those used by timers, for unit group, for player group, conditions and filters.
 
Level 4
Joined
Jan 17, 2018
Messages
112
Probably because of the thread crash induced by the TriggerSleepAction.

TriggerSleepAction (wait) cannot be run inside callback functions such as those used by timers, for unit group, for player group, conditions and filters.

I only included it in after trying to see if the script works, but Bloodsoul's script is working good so far, so it's resolved
 
Level 4
Joined
Jan 17, 2018
Messages
112

Greetings, I hope you could help me once, or twice more with something probably a lot more difficult involving this script. I've made it easier for myself spawning units at the player's starting base, but now I got to the difficult part, I'd like to spawn 3 structures for the peasant owner's base with a same type of script.

So basically, it's an 8 player map with teams of 2, I should probably create 3 regions per team and save them in a variable, if possible to save multiple regions? And then where you have:

  • Set tmp_point[1] = (tmp_player start location)
I should add a check to see if the player is 1/2, use variable A with regions XYZ saved, 3/4 use B... and so on?

Also, the second thing, If say 3 units enter the COP, the player can cast a spell in a specific region and after he casts it, the units are killed. This is probably a -> create dummy unit if the number = 3 and I have no idea how to "force" the spell onto the player (as if he used the hotkey to cast the spell, bringing up the radius circle thingy allowing him to place the spell)

I would understand if you won't help, this is quite some big stuff, but that's me, a noob speaking here, lol so it might not be as hard as I think.
 
Status
Not open for further replies.
Top