• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] count players controlled by a user

Status
Not open for further replies.
Level 7
Joined
Nov 15, 2009
Messages
225
I know two ways.
1. Use the ugly bj function (or the blizzard script itself)
JASS:
set i = CountPlayersInForceBJ(GetPlayersByMapControl(MAP_CONTROL_USER))
JASS:
function CountPlayersInForceEnum takes nothing returns nothing
     set bj_forceCountPlayers = bj_forceCountPlayers + 1
 endfunction 
 function CountPlayersInForceBJ takes force f returns integer
     set bj_forceCountPlayers = 0
     call ForForce(f, function CountPlayersInForceEnum)
     return bj_forceCountPlayers
 endfunction

2. Or use a loop for all player numbers and check if the player is controlled by user (this is how I do it)
 
Hi, you should not use BJ functions, and you should use camelCase for variable names.

Also, you probably want to check the player's slot state in addition to his controller.

JASS:
scope example initializer i
    globals
        private integer playersPlaying=0
    endglobals
    
    private function i takes nothing returns nothing
        local integer index=0
        loop
            exitwhen index>11
            if GetPlayerSlotState(Player(index))==PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(index))==MAP_CONTROL_USER then
                set playersPlaying=playersPlaying+1
            endif
            set index=index+1
        endloop
    endfunction
endscope

This is a vJass example but it can be easily adapted to jass.
 
Status
Not open for further replies.
Top