• 🏆 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!

How do I detect how many players are in game?

Status
Not open for further replies.
Level 8
Joined
Jul 17, 2004
Messages
283
For hero selection at the start of my game I need some way of detecting when all players are finished choosing their heroes. How can I detect how many players are in-game, excluding computers?
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
  • Player Count
    • Events
    • Conditions
    • Actions
      • For each (Integer LoopIndex) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Player(LoopIndex)) controller) Equal to User
              • ((Player(LoopIndex)) slot status) Equal to Is playing
            • Then - Actions
              • Set Count = (Count + 1)
            • Else - Actions
Count is the number of valid map players in the map.
 
Level 8
Joined
Jul 17, 2004
Messages
283
Nice, thank you. But I just did this instead. :p

  • Set PlayerCount = (Number of players in (All players matching ((((Matching player) slot status) Equal to Is playing) and (((Matching player) controller) Equal to User))))
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Oh... my bad, no, it doesn't leak because it uses bj_AllPlayers, but it can be improved with some JASS, the thing is that both of the "Matching" thing creates additional functions... but it's not a big deal ;)

All Player never leaks.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
It does leak look at the players matching condition call.

JASS:
function GetPlayersByMapControl takes mapcontrol whichControl returns force
    local force f = CreateForce()
    local integer playerIndex
    local player  indexPlayer

    set playerIndex = 0
    loop
        set indexPlayer = Player(playerIndex)
        if GetPlayerController(indexPlayer) == whichControl then
            call ForceAddPlayer(f, indexPlayer)
        endif

        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYER_SLOTS
    endloop

    return f
endfunction

doing what doomlord suggested is both faster and more efficient and leakless.
 
Level 8
Joined
Jul 17, 2004
Messages
283
deathismyfriend, wouldn't this method be okay too?

  • Set PlayerCountGroup = (All players matching ((((Matching player) slot status) Equal to Is playing) and (((Matching player) controller) Equal to User)))
  • Set PlayerCount = (Number of players in PlayerCountGroup)
  • Custom script: call DestroyForce(udg_PlayerCountGroup)
 
Status
Not open for further replies.
Top