# Units In Unit Group For Player

Grammar — Units in group|Unit Group owned by player player, with at most count
FlagsNative | Function

Returns a unit group by extracting units from a unit group belonging to the specified player.

# Arguments

  • unitgroup — Group
  • int — Player
  • int — Count

Returns — unitgroup

native unitgroup UnitGroupFilterPlayer(
	unitgroup g,
	int player,
	int maxCount,
);

Category: Unit Group / Useful Unit Groups

# Examples

campaigns/liberty.sc2campaignbase.sc2maps/maps/campaign/thanson02.sc2map/MapScript.galaxy:1758

            Wait(1.0, c_timeGame);
        }
        lv_spawners = UnitGroupFilterPlayer(gv_infestedStructureGroup, gv_pLAYER_03_INFESTED_REFUGEES, (gv_infestedTerranQty + gv_infestedMarineQty));
        auto59089212_n = gv_infestedMarineQty;
        for (auto59089212_i = 1; auto59089212_i <= auto59089212_n; auto59089212_i += 1) {

campaigns/liberty.sc2campaignbase.sc2maps/maps/campaign/thorner05s.sc2map/MapScript.galaxy:11444

    libNtve_gf_CinematicMode(false, PlayerGroupAll(), lv_fadeDuration);
    libNtve_gf_GlobalCinematicSetting(false);
    UnitGroupSelect(UnitGroupFilterPlayer(gv_playerUnitGroup, gv_p01_USER, 0), gv_p01_USER, true);
    libNtve_gf_SwooshCamera(gv_p01_USER, (gv_cameraDefault + 8.0), gv_cameraDefault, PlayerStartLocation(gv_p01_USER), lv_fadeDuration);
    CinematicFade(true, lv_fadeDuration, c_fadeStyleNormal, ColorWithAlpha(0.00, 0.00, 0.00, 0.00), 0.0, true);

campaigns/liberty.sc2campaignbase.sc2maps/maps/campaign/thorner05s.sc2map/MapScript.galaxy:12743

    }
    Wait(0.2, c_timeGame);
    auto80222410_g = UnitGroupFilterPlayer(gv_playerUnitGroup, gv_p01_USER, 0);
    auto80222410_u = UnitGroupCount(auto80222410_g, c_unitCountAll);
    for (;; auto80222410_u -= 1) {

campaigns/liberty.sc2campaignbase.sc2maps/maps/campaign/thorner05s.sc2map/MapScript.galaxy:12761

    Wait(0.2, c_timeGame);
    SoundPlay(SoundLink("Medivac_Load", 0), PlayerGroupAll(), 100.0, 0.0);
    auto41E84B64_g = UnitGroupFilterPlayer(gv_playerUnitGroup, gv_p01_USER, 0);
    auto41E84B64_u = UnitGroupCount(auto41E84B64_g, c_unitCountAll);
    for (;; auto41E84B64_u -= 1) {

campaigns/liberty.sc2campaignbase.sc2maps/maps/campaign/traynor01.sc2map/MapScript.galaxy:2950

    }

    auto14FBE439_g = UnitGroupFilterPlayer(gv_dominionCompoundCivilian, gv_p3_RIKSVILLE_YELLOW, 0);
    auto14FBE439_u = UnitGroupCount(auto14FBE439_g, c_unitCountAll);
    for (;; auto14FBE439_u -= 1) {

campaigns/liberty.sc2campaignbase.sc2maps/maps/campaign/traynor01.sc2map/MapScript.galaxy:5931

        libNtve_gf_PauseUnit(auto5A1D1538_var, false);
    }
    auto67CB5E3A_g = UnitGroupFilterPlayer(gv_escapeCivilians, gv_p3_RIKSVILLE_YELLOW, 0);
    auto67CB5E3A_u = UnitGroupCount(auto67CB5E3A_g, c_unitCountAll);
    for (;; auto67CB5E3A_u -= 1) {

campaigns/liberty.sc2campaignbase.sc2maps/maps/campaign/ttosh03a.sc2map/MapScript.galaxy:388

    }

    libCamp_gf_CreateDropPod(libCamp_ge_DropPodRace_Terran, lp_dest, UnitGroupFilterPlayer(lv_dropGroup, lp_who, 0), false);
    Wait(lp_delay, c_timeGame);
    SoundtrackPlay(PlayerGroupAll(), c_soundtrackCategoryMusic, "TTosh03AMusicEventA", c_soundtrackCueAny, c_soundtrackIndexAny, false);

campaigns/liberty.sc2campaign/base.sc2maps/maps/campaign/thanson02.sc2mapMapScript.galaxy:1758

            Wait(1.0, c_timeGame);
        }
        lv_spawners = UnitGroupFilterPlayer(gv_infestedStructureGroup, gv_pLAYER_03_INFESTED_REFUGEES, (gv_infestedTerranQty + gv_infestedMarineQty));
        auto59089212_n = gv_infestedMarineQty;
        for (auto59089212_i = 1; auto59089212_i <= auto59089212_n; auto59089212_i += 1) {

campaigns/liberty.sc2campaign/base.sc2maps/maps/campaign/thorner05s.sc2mapMapScript.galaxy:11444

    libNtve_gf_CinematicMode(false, PlayerGroupAll(), lv_fadeDuration);
    libNtve_gf_GlobalCinematicSetting(false);
    UnitGroupSelect(UnitGroupFilterPlayer(gv_playerUnitGroup, gv_p01_USER, 0), gv_p01_USER, true);
    libNtve_gf_SwooshCamera(gv_p01_USER, (gv_cameraDefault + 8.0), gv_cameraDefault, PlayerStartLocation(gv_p01_USER), lv_fadeDuration);
    CinematicFade(true, lv_fadeDuration, c_fadeStyleNormal, ColorWithAlpha(0.00, 0.00, 0.00, 0.00), 0.0, true);

campaigns/liberty.sc2campaign/base.sc2maps/maps/campaign/thorner05s.sc2mapMapScript.galaxy:12743

    }
    Wait(0.2, c_timeGame);
    auto80222410_g = UnitGroupFilterPlayer(gv_playerUnitGroup, gv_p01_USER, 0);
    auto80222410_u = UnitGroupCount(auto80222410_g, c_unitCountAll);
    for (;; auto80222410_u -= 1) {

campaigns/liberty.sc2campaign/base.sc2maps/maps/campaign/thorner05s.sc2mapMapScript.galaxy:12761

    Wait(0.2, c_timeGame);
    SoundPlay(SoundLink("Medivac_Load", 0), PlayerGroupAll(), 100.0, 0.0);
    auto41E84B64_g = UnitGroupFilterPlayer(gv_playerUnitGroup, gv_p01_USER, 0);
    auto41E84B64_u = UnitGroupCount(auto41E84B64_g, c_unitCountAll);
    for (;; auto41E84B64_u -= 1) {

campaigns/liberty.sc2campaign/base.sc2maps/maps/campaign/traynor01.sc2mapMapScript.galaxy:2950

    }

    auto14FBE439_g = UnitGroupFilterPlayer(gv_dominionCompoundCivilian, gv_p3_RIKSVILLE_YELLOW, 0);
    auto14FBE439_u = UnitGroupCount(auto14FBE439_g, c_unitCountAll);
    for (;; auto14FBE439_u -= 1) {

campaigns/liberty.sc2campaign/base.sc2maps/maps/campaign/traynor01.sc2mapMapScript.galaxy:5931

        libNtve_gf_PauseUnit(auto5A1D1538_var, false);
    }
    auto67CB5E3A_g = UnitGroupFilterPlayer(gv_escapeCivilians, gv_p3_RIKSVILLE_YELLOW, 0);
    auto67CB5E3A_u = UnitGroupCount(auto67CB5E3A_g, c_unitCountAll);
    for (;; auto67CB5E3A_u -= 1) {

campaigns/liberty.sc2campaign/base.sc2maps/maps/campaign/ttosh03a.sc2mapMapScript.galaxy:388

    }

    libCamp_gf_CreateDropPod(libCamp_ge_DropPodRace_Terran, lp_dest, UnitGroupFilterPlayer(lv_dropGroup, lp_who, 0), false);
    Wait(lp_delay, c_timeGame);
    SoundtrackPlay(PlayerGroupAll(), c_soundtrackCategoryMusic, "TTosh03AMusicEventA", c_soundtrackCueAny, c_soundtrackIndexAny, false);

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/swarm/zkorhal02.sc2map/MapScript.galaxy:7062

    }

    autoA19DE0EE_g = UnitGroupFilterPlayer(gv_cinematicTempUnits, 1, 0);
    autoA19DE0EE_u = UnitGroupCount(autoA19DE0EE_g, c_unitCountAll);
    for (;; autoA19DE0EE_u -= 1) {

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/swarm/zspace02.sc2map/MapScript.galaxy:2950

    TriggerExecute(gt__1LockedDoorAttack04, true, false);
    libNtve_gf_WaitForTimer(lv_waitTimer, 10.0, false);
    while (!((UnitGroupCount(UnitGroupFilterPlayer(gv__1LockedDoorWave, gv_p02_DOMINION, 0), c_unitCountAlive) == 0))) {
        Wait(1.0, c_timeGame);
    }

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/swarm/zspace02.sc2map/MapScript.galaxy:8591

    lv_stage1Units = UnitGroup(null, c_playerAny, RegionFromId(24), UnitFilter(0, 0, (1 << c_targetFilterMissile), (1 << (c_targetFilterDead - 32)) | (1 << (c_targetFilterHidden - 32))), 0);
    UnitGroupRemove(lv_stage1Units, gv_kerrigan);
    UnitGroupRemoveUnitGroup(lv_stage1Units, UnitGroupFilterPlayer(lv_stage1Units, gv_p01_USER, 0));
    autoF7D33005_g = lv_stage1Units;
    autoF7D33005_u = UnitGroupCount(autoF7D33005_g, c_unitCountAll);

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/zkorhal02.sc2mapMapScript.galaxy:7062

    }

    autoA19DE0EE_g = UnitGroupFilterPlayer(gv_cinematicTempUnits, 1, 0);
    autoA19DE0EE_u = UnitGroupCount(autoA19DE0EE_g, c_unitCountAll);
    for (;; autoA19DE0EE_u -= 1) {

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/zspace02.sc2mapMapScript.galaxy:2950

    TriggerExecute(gt__1LockedDoorAttack04, true, false);
    libNtve_gf_WaitForTimer(lv_waitTimer, 10.0, false);
    while (!((UnitGroupCount(UnitGroupFilterPlayer(gv__1LockedDoorWave, gv_p02_DOMINION, 0), c_unitCountAlive) == 0))) {
        Wait(1.0, c_timeGame);
    }

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/zspace02.sc2mapMapScript.galaxy:8591

    lv_stage1Units = UnitGroup(null, c_playerAny, RegionFromId(24), UnitFilter(0, 0, (1 << c_targetFilterMissile), (1 << (c_targetFilterDead - 32)) | (1 << (c_targetFilterHidden - 32))), 0);
    UnitGroupRemove(lv_stage1Units, gv_kerrigan);
    UnitGroupRemoveUnitGroup(lv_stage1Units, UnitGroupFilterPlayer(lv_stage1Units, gv_p01_USER, 0));
    autoF7D33005_g = lv_stage1Units;
    autoF7D33005_u = UnitGroupCount(autoF7D33005_g, c_unitCountAll);

campaigns/void.sc2campaignbase.sc2maps/maps/campaign/void/pcampaigntest.sc2map/MapScript.galaxy:1037

    TriggerExecute(gt_ObjectiveRescueStalkersCreate, true, false);
    lv_warpedUnits = UnitGroupSelected(gv_pLAYER_01_USER);
    if ((UnitGroupCount(UnitGroupFilterPlayer(lv_warpedUnits, gv_pLAYER_01_USER, 0), c_unitCountAlive) == 0)) {
        SoundPlay(SoundLink("UI_GenericError", 0), PlayerGroupAll(), 100.0, 0.0);
        return true;

campaigns/void.sc2campaignbase.sc2maps/maps/campaign/void/sc2epilogue02.sc2map/MapScript.galaxy:8283

    }

    auto02182281_g = UnitGroupFilterPlayer(gv_midCineFlyingStructures, gv_pLAYER_02_DOMINION8, 0);
    auto02182281_u = UnitGroupCount(auto02182281_g, c_unitCountAll);
    for (;; auto02182281_u -= 1) {

campaigns/void.sc2campaignbase.sc2maps/maps/campaign/void/sc2epilogue02.sc2map/MapScript.galaxy:8325

    }

    autoBB1AECC8_g = UnitGroupFilterPlayer(gv_midCineFlyingStructures, gv_pLAYER_02_DOMINION8, 0);
    autoBB1AECC8_u = UnitGroupCount(autoBB1AECC8_g, c_unitCountAll);
    for (;; autoBB1AECC8_u -= 1) {

campaigns/void.sc2campaign/base.sc2maps/maps/campaign/void/pcampaigntest.sc2mapMapScript.galaxy:1037

    TriggerExecute(gt_ObjectiveRescueStalkersCreate, true, false);
    lv_warpedUnits = UnitGroupSelected(gv_pLAYER_01_USER);
    if ((UnitGroupCount(UnitGroupFilterPlayer(lv_warpedUnits, gv_pLAYER_01_USER, 0), c_unitCountAlive) == 0)) {
        SoundPlay(SoundLink("UI_GenericError", 0), PlayerGroupAll(), 100.0, 0.0);
        return true;

campaigns/void.sc2campaign/base.sc2maps/maps/campaign/void/sc2epilogue02.sc2mapMapScript.galaxy:8283

    }

    auto02182281_g = UnitGroupFilterPlayer(gv_midCineFlyingStructures, gv_pLAYER_02_DOMINION8, 0);
    auto02182281_u = UnitGroupCount(auto02182281_g, c_unitCountAll);
    for (;; auto02182281_u -= 1) {

campaigns/void.sc2campaign/base.sc2maps/maps/campaign/void/sc2epilogue02.sc2mapMapScript.galaxy:8325

    }

    autoBB1AECC8_g = UnitGroupFilterPlayer(gv_midCineFlyingStructures, gv_pLAYER_02_DOMINION8, 0);
    autoBB1AECC8_u = UnitGroupCount(autoBB1AECC8_g, c_unitCountAll);
    for (;; autoBB1AECC8_u -= 1) {

mods/heroesbrawlmods/brawlmapmods/coop/escapefrombraxis.stormmodbase.stormdata/LibPEB1.galaxy:5796


        Wait(libPEB1_gv_zergWaveDelay, c_timeGame);
        while (!((UnitGroupCount(UnitGroupFilterPlayer(libPEB1_gv_activeZergMinions, libCore_gv_cOMPUTER_TeamChaos, 0), c_unitCountAlive) < libPEB1_gv_maxActiveZergMinions))) {
            Wait(1.0, c_timeGame);
        }

mods/heroesbrawlmods/brawlmapmods/coop/escapefrombraxis.stormmodbase.stormdata/LibPEB1.galaxy:6027


        Wait(libPEB1_gv_zergWaveDelay, c_timeGame);
        while (!((UnitGroupCount(UnitGroupFilterPlayer(libPEB1_gv_activeZergMinions, libCore_gv_cOMPUTER_TeamChaos, 0), c_unitCountAlive) < libPEB1_gv_maxActiveZergMinions))) {
            Wait(1.0, c_timeGame);
        }

mods/heroesbrawlmods/brawlmapmods/coop/escapefrombraxis.stormmodbase.stormdata/LibPEB1.galaxy:8139

    libNtve_gf_StopTimer(libPEB1_gv_holdoutTimer);
    while (true) {
        lv_zergRemaining = (UnitGroupCount(UnitGroupFilterAlliance(libPEB1_gv_activeZergHeroes, libCore_gv_cOMPUTER_TeamChaos, c_unitAllianceAlly, 0), c_unitCountAlive) + UnitGroupCount(UnitGroupFilterPlayer(libPEB1_gv_activeZergMinions, libCore_gv_cOMPUTER_TeamChaos, 0), c_unitCountAlive));
        if ((lv_zergRemaining == 0)) {
            break;

mods/heroesbrawlmods/brawlmapmods/coop/escapefrombraxis.stormmodbase.stormdata/LibPEB1.galaxy:8729

    libNtve_gf_StopTimer(libPEB1_gv_holdoutTimer);
    while (true) {
        if ((UnitGroupCount(UnitGroupFilterPlayer(libPEB1_gv_activeZergMinions, libCore_gv_cOMPUTER_TeamChaos, 0), c_unitCountAlive) == 0) && (UnitGroupCount(UnitGroupFilterAlliance(libPEB1_gv_activeZergHeroes, libCore_gv_cOMPUTER_TeamChaos, c_unitAllianceAlly, 0), c_unitCountAlive) == 0)) {
            break;
        }

mods/heroesbrawlmods/brawlmapmods/coop/escapefrombraxis.stormmodbase.stormdata/LibPEB1.galaxy:8733

        }
        else {
            libPEB1_gf_SetHoldoutPanelZergRemaining((UnitGroupCount(UnitGroupFilterAlliance(libPEB1_gv_activeZergHeroes, libCore_gv_cOMPUTER_TeamChaos, c_unitAllianceAlly, 0), c_unitCountAlive) + UnitGroupCount(UnitGroupFilterPlayer(libPEB1_gv_activeZergMinions, libCore_gv_cOMPUTER_TeamChaos, 0), c_unitCountAlive)));
            TextExpressionSetToken("Param/Expression/lib_PEB1_8C9C6DCD", "A", IntToText((UnitGroupCount(libPEB1_gv_activeZergHeroes, c_unitCountAlive) + UnitGroupCount(libPEB1_gv_activeZergMinions, c_unitCountAlive))));
            TextTagSetText(lv_countdownTextTag, TextExpressionAssemble("Param/Expression/lib_PEB1_8C9C6DCD"));

mods/heroesbrawlmods/brawlmapmods/coop/escapefrombraxis.stormmodbase.stormdata/LibPEB1.galaxy:10700

    }

    if ((UnitGroupCount(UnitGroupFilterPlayer(libPEB1_gv_activeZergMinions, libCore_gv_cOMPUTER_TeamChaos, 0), c_unitCountAlive) == 0) && (UnitGroupCount(UnitGroupFilterAlliance(libPEB1_gv_activeZergHeroes, libCore_gv_cOMPUTER_TeamChaos, c_unitAllianceAlly, 0), c_unitCountAlive) == 0)) {
        TransmissionSendForPlayerSelect(PlayerGroupAll(), TransmissionSource(), c_invalidPortraitId, "", "Talk", SoundLinkNoIndex(ConversationDataGetSound("AdjutantPVEVO|Line00016", false)), null, null, 0.0, c_transmissionDurationAdd, true, c_maxPlayers, false);
    }

mods/heroesbrawlmods/brawlmapmods/coop/escapefrombraxis.stormmodbase.stormdata/LibPEB1.galaxy:10901

    }

    if ((UnitGroupCount(UnitGroupFilterPlayer(libPEB1_gv_activeZergMinions, libCore_gv_cOMPUTER_TeamChaos, 0), c_unitCountAlive) == 0) && (UnitGroupCount(UnitGroupFilterAlliance(libPEB1_gv_activeZergHeroes, libCore_gv_cOMPUTER_TeamChaos, c_unitAllianceAlly, 0), c_unitCountAlive) == 0)) {
        TransmissionSendForPlayerSelect(PlayerGroupAll(), TransmissionSource(), c_invalidPortraitId, "", "Talk", SoundLinkNoIndex(ConversationDataGetSound("AdjutantPVEVO|Line00016", false)), null, null, 0.0, c_transmissionDurationAdd, true, c_maxPlayers, false);
    }

mods/heroesdata.stormmodbase.stormdata/TriggerLibs/SupportLib.galaxy:2743

    if ((DialogIsVisible(libSprt_gv_qACheatsControlsPanel.lv_mainDialog, EventPlayer()) == false)) {
        DialogSetVisible(libSprt_gv_qACheatsControlsPanel.lv_mainDialog, libCore_gv_playerGroupFromPlayer[EventPlayer()], true);
        libSprt_gv_qACheatsSelectedUnit = UnitGroupUnit(UnitGroupFilterPlayer(libGame_gv_players[EventPlayer()].lv_heroUnitGroup, EventPlayer(), 0), 1);
    }
    else {

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOMI.galaxy:1709

            lv_attackPlayerIter = PlayerGroupNextPlayer(autoC08EEF33_g, lv_attackPlayerIter);
            if (lv_attackPlayerIter < 0) { break; }
            libCOMI_gf_CM_CoopAI_AttackForce_DropTerran(lv_attackPlayerIter, UnitGroupFilterPlayer(lv_dropGroupTerran, lv_attackPlayerIter, 0), lp_dropLocation);
        }
    }

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOMI.galaxy:1723

            lv_attackPlayerIter = PlayerGroupNextPlayer(auto18A3184F_g, lv_attackPlayerIter);
            if (lv_attackPlayerIter < 0) { break; }
            libCOMI_gf_CM_CoopAI_AttackForce_DropZerg(lv_attackPlayerIter, UnitGroupFilterPlayer(lv_dropGroupZerg, lv_attackPlayerIter, 0), lp_dropLocation);
        }
    }

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOMI.galaxy:2105

        lv_playerIter = PlayerGroupNextPlayer(auto69893063_g, lv_playerIter);
        if (lv_playerIter < 0) { break; }
        lv_playerAttackForce = UnitGroupFilterPlayer(lv_attackForce, lv_playerIter, 0);
        libCOMU_gf_CT_Mutator_AttackWaveHook_WaveCreated(lv_playerIter, lv_playerAttackForce, lp_spawnLocation, libCOMI_ge_CM_CoopAI_WaveAttackTargetType_PlayerBase);
        UnitGroupAddUnitGroup(lv_attackForce, lv_playerAttackForce);

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOMI.galaxy:2311

        lv_playerIter = PlayerGroupNextPlayer(autoD30D4817_g, lv_playerIter);
        if (lv_playerIter < 0) { break; }
        libCOMI_gf_CM_CoopAI_AttackForce_SendPlayerAttack(lv_playerIter, UnitGroupFilterPlayer(lp_attackForce, lv_playerIter, 0), lp_time, lp_waitDontWait);
    }
    libCOMI_gf_CM_CoopAI_AttackForce_ClearWaypointList();

mods/warcoop/warmeleeai.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:32

bool GAw3_AIThreatedByNonHostilePlayer(int player){
    unitgroup ug=AIGetTownThreats(player,-1);
    unitgroup ugH=UnitGroupFilterPlayer(ug,GAw3_AICreepPlayer,c_noMaxCount);
    if(ug==null){return false;}
    return (UnitGroupCount(ug,c_unitCountAlive)-UnitGroupCount(ugH,c_unitCountAlive)>0);