SC2Mapster Forums

Development > Triggers

How do i search for units owned by a Player Group?

  • 14 posts
    #1 Jan 24, 2013 at 22:20 UTC - 0 likes

    I have a trigger that searches for untis owned by a player group, in this case the group is Team 1 as determined in the lobby, but when i display the number that the trigger has found, it shows only the units owned by the player first in the index of the picked players.

    Overall how do i Make a trigger search for units that owned owned by an array/group of players?

    #2 Jan 25, 2013 at 00:17 UTC - 0 likes

    You can do a nested loop starting with Pick Each Player in Player Group then Pick Each Unit in Unit Group. The unit group can be Units in Region Matching Condition with the region set as the entire map.

    Current Project: SquadCraft 2
    Project Page
    Feedback Thread
    Latest Video
    Published Regions: SEA, NA, EU, KOR
    Status: Open Beta

    #3 Jan 25, 2013 at 01:17 UTC - 0 likes

    Yea that is the actin part of my trigger... but im pretty sure it only records the first player it picks, or maybe the last player.

    Heres the setup of my trigger:

    -Events Timer - Every 1.0 seconds of Game Time

    Actions Player Group - Pick each player in (Players on team 1) and do (Actions)

    Actions Unit Group - Pick each unit in (Command Point - Fuel units in (Entire map) owned by player (Picked player) matching Excluded: Missile, Dead, Hidden, with at most Any Amount) and do (Actions)

    Actions Variable - Set Fuel Flags Team 1 = (Number of Living units in (Unit group((Picked unit))))

    #4 Jan 25, 2013 at 02:08 UTC - 0 likes
    Quote from Project_06: Go

    Actions Variable - Set Fuel Flags Team 1 = (Number of Living units in (Unit group((Picked unit))))

    This seems to be the problem. Setting the variable will only work on the last unit in the group. The modify integer action should fix this as it's adding to the variable each time.

    #5 Jan 25, 2013 at 02:29 UTC - 0 likes

    here the issue with that: the ownership changes numerous times throughout the game, so do this would require me to add a trigger that subtracts one from the integer, in this case would be ridiculously complex. Also, it does find multiple units of the type it looks for, the issue is that it wont find units owned by each player in the Player group(Team 1) and combine them.

    Last edited Jan 25, 2013 by Project_06
    #6 Jan 25, 2013 at 07:48 UTC - 0 likes

    An easier solution may be to have as many integer variables as the number of teams you want. You could pick each unit in the entire map first, check if the owner of those units belong to particular teams, then increment the appropriate variable.

    This should solve your problem about combining counts between players. If you must take ownership into account then provide more info and I could prob provide a simple solution.

    Otherwise having that last action in your trigger doesn't count units properly.

    #7 Jan 25, 2013 at 09:04 UTC - 0 likes

    I do believe i need to take count of ownership because the ORIGINAL owner is always player 15, and over the time of the game players will take over these flags, as in thye become the owner of that flag/unit so im pretty sure i must count the owners.Ill give the "tweaked" but still not functioning trigger action:

    - Actions Player Group - Pick each player in (Players on team 1) and do (Actions)

    - - - Actions Unit Group - Pick each unit in (Command Point - Fuel units in (Entire map) owned by player (Picked player) matching Excluded: Missile, Dead, Hidden, with at most Any Amount) and do (Actions)

    - - - - - - -Actions Variable - Set Fuel Flags Team 1 = (Number of Living units in (Command Point - Fuel units in (Entire map) owned by player (Picked player) matching Excluded: Missile, Dead, Hidden, with at most Any Amount))

    This is the setup of the trigger, and it doesnt record them correctly.

    #8 Jan 25, 2013 at 09:58 UTC - 0 likes

    My solution where you change the set variable action to a modify variable action is all you need. It doesn't matter that the flags change ownership. Every time the map tries to count them it will only consider the player group. When they return to player 15 it will be excluded from the count if player 15 is neutral or hostile (and hence not active).

    The reason this works is because it adds to the variable after each player is checked (giving a total count like you want). They will be checked in turn from player 1 to the last so setting the variable to any player's count will always give you the count of the last player in the group.

    If you still don't understand then you're welcome to ask more questions but I encourage you to try this first and see if it works.

    #9 Jan 26, 2013 at 01:34 UTC - 0 likes

    They dont "return" to player 15, there are two teams of 3 human players, and the ownerswhip will go between there 6 players throughout the game duration. Also simply adding wont work, because the trigger it periodic every 1 second to check for ownership changes... sorry i forgot to mention the periodic event in the trigger layout.

    Last edited Jan 26, 2013 by Project_06
    #10 Jan 26, 2013 at 01:53 UTC - 0 likes

    Sorry, I forgot to mention you need to set the count variable to 0 at the beginning of the trigger as well.

    Does it work now?

    #11 Jan 26, 2013 at 07:10 UTC - 0 likes

    okay i understand now, ill tell you if it works after i test it.

    #12 Jan 28, 2013 at 02:35 UTC - 0 likes

    Nope, it just count 1 and thats it.

    #13 Jan 29, 2013 at 06:59 UTC - 0 likes

    I made a map real quick which counts all of the units in a player group and says it in a message. You can also add/remove units from the game and check the count again.

    The problem you are having is probably not with your triggers, but with how the editor interacts with computer players. For some reason it never counts more than one computer player on a team. This does not happen on Battle.net, so you could always publish your map to test it. But using "Test Map" you won't find more than a single computer player on a team, or at least be able to communicate with any computers on a team other than the first one.

    To get around the issue you can add all of the computers into a separate player group like I have (called "Computers"). This player group will report computer players just fine, unlike "Players on Team". Even if this isn't the problem you are having, this sample map should help.

    Anyways here is the map.

    Hope this helps.

    Last edited Jan 29, 2013 by rtschutter
    #14 Jan 31, 2013 at 07:57 UTC - 0 likes

    @Project_06: Go

    Maybe you could count with a local variable then set the global one. Are there any other triggers that change your count variable in real time?

  • 14 posts

You must login to post a comment. Don't have an account? Register to get one!