Yes. I'm using the following setup in my gamerules:
for ( int i = 1; i <= gpGlobals->maxClients; i++ )
{
pPlayer = ToModPlayer( UTIL_PlayerByIndex( i ) );
if ( pPlayer )
{
// Count total players
iTotal++;
// Count alive players
if ( pPlayer->GetPlayerLives() > 0)
iCount++;
}
// No need to count more than 2 alive players, we know enough now!
if ( iCount > 1 )
break;
}
Then I can access iTotal and iCount to see wheter round should end.
Yorg Kuijs wrote:
> The whole thing is in a for loop:
> for ( int i = 1; i <= gpGlobals->maxClients; i++ )
> so for every player it adds 1 to playercounter or playercountertotal.
>
> and you mean something like this then?:
> if ( pPlayer )
> playercountertotal++;
> if( pPlayer && ToHL2MPPlayer(pPlayer) &&
> ToHL2MPPlayer(pPlayer)->GetPlayerLives()>0)
> playercounter++;
>
> Nuno Silva wrote:
>> I'm no pro at Source Modding, but this piece of code looks kind of weird.
>> Please notice that i dont do any Source SDK work, so i might be wrong.
>>
>> How are you getting pPlayer? Because it feels irrational that
>> playercounter++ would be >= 2.
>>
>> Also, what Willem Engel means is that you should do something like this:
>>
>> if ( pPlayer && ToHL2MPPlayer(pPlayer) &&
>> ToHL2MPPlayer(pPlayer)->GetPlayerLives()>= 0 )
>>
>> Because if ToHL2MPPlayer fails, you'll probably be accessing a null pointer,
>> though that may not be the case since you dont mention any crashes.
>>
>> Also, shouldnt it be > instead of >=?
>>
>> Sorry if this reply doesnt help much. As i said, i dont code on the SDK
>> nowadays. Good luck.
>>
>
> _______________________________________________
> To unsubscribe, edit your list preferences, or view the list archives, please
> visit:
> http://list.valvesoftware.com/mailman/listinfo/hlcoders
>
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders