Hi all,

I'm just now getting in to source modding but have been programming for a
couple years now. I think there might be a problem where count is set to
less than 1 or null, just a thought. Also I think it might be more logical
to have iTotal in it's own if above iCount. Below is what I have hacked
together.


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;
}

if(iTotal > 1)
{
       //we have people playing so we should be here

       if(iCount == 1)
       {
            //player should win
       }else if( iCount == 0){
             //draw
       }else{
             //something is wrong, catch it and log it
       }
}

On Thu, Dec 11, 2008 at 5:16 AM, Willem Engel <[email protected]> wrote:

> 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
>
>
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to