1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Ride into the sunset with the 32nd Modeling Contest.
    Dismiss Notice
  4. This adventure has come to an end. Congratulate our heroes in the 16th Mini Mapping Contest Results.
    Dismiss Notice
  5. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  6. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Count Index not resetting

Discussion in 'Triggers & Scripts' started by Marcell, Mar 9, 2018.

  1. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    • 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.
     
  2. Hotwer

    Hotwer

    Joined:
    Mar 10, 2013
    Messages:
    370
    Resources:
    0
    Resources:
    0
    • 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.
     
  3. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    1,485
    Resources:
    18
    Tools:
    2
    Maps:
    3
    Spells:
    8
    Tutorials:
    4
    JASS:
    1
    Resources:
    18
    You do not filter out dead units.
    -> Dead Units are valid to control this points.
    Is matching Unit Alive = true should solve the problem.
     
  4. BloodSoul

    BloodSoul

    Joined:
    May 10, 2009
    Messages:
    768
    Resources:
    2
    Spells:
    2
    Resources:
    2
    Waits should not be used within Unit and Player groups.

    upload_2018-3-10_16-29-15.png
     
  5. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    • 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.
     
  6. BloodSoul

    BloodSoul

    Joined:
    May 10, 2009
    Messages:
    768
    Resources:
    2
    Spells:
    2
    Resources:
    2
    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.
     
  7. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    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.
     
  8. BloodSoul

    BloodSoul

    Joined:
    May 10, 2009
    Messages:
    768
    Resources:
    2
    Spells:
    2
    Resources:
    2
    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...

    Triggers

    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

     

    Attached Files:

    Last edited: Mar 14, 2018
  9. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    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?
     
  10. BloodSoul

    BloodSoul

    Joined:
    May 10, 2009
    Messages:
    768
    Resources:
    2
    Spells:
    2
    Resources:
    2
    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: Mar 15, 2018
  11. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,930
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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.
     
  12. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    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
     
  13. Marcell

    Marcell

    Joined:
    Jan 17, 2018
    Messages:
    112
    Resources:
    0
    Resources:
    0
    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.