Hey list,

In my mod I want the winner of a round to be announced with a hud print 
center and print console.
This will work by score(mind you, score is seperated from the frags 
already).

I don't really have any experience when it comes to selecting the 
highest score out of multiple objects(players in this case)
With the help of a example I could remember from a C++ guide, I cooked 
up the following:

void CHL2MPRules::DecideRoundWinner2( void )
{
#ifndef CLIENT_DLL
    if ( g_fGameOver )
      return;

    int previouswinner = 0;

    // count players, leave out spectators
    for ( int i = 0; i < MAX_PLAYERS; i++ )
    {
        CBasePlayer *pPlayer = UTIL_PlayerByIndex( i );
        CBasePlayer *pPreviousPlayer = UTIL_PlayerByIndex( previouswinner );

        if ( !pPlayer || pPlayer->GetTeamNumber() == TEAM_SPECTATOR  )
            continue;

        // should only be initialized once in the loop
        static int iHighestScore = 0;

        // if this player's score is higher then the previous highest 
then set current player as the winner
        if( pPlayer->GetPlayerScore() > iHighestScore )
        {
            // change the highest score so it can be compared again next 
time this loops
            iHighestScore = pPlayer->GetPlayerScore();
            // mark this player as (potential) winner
            pPlayer->SetRoundWinner( true );

            // if i is not 0, then there is likely a previous player 
with a lower score
            if( i )
                pPreviousPlayer->SetRoundWinner( false );

            // mark this player so he can be recognized as the previous 
winner if needed
            previouswinner = i;
        }
    }

    // second player counter loop, cycles through the players, then 
displays a message when it's found the winner
    for ( int j = 0; j < MAX_PLAYERS; j++ )
    {
        CBasePlayer *pPlayer = UTIL_PlayerByIndex( j );

        if ( !pPlayer )
            continue;

        // did the loop find the winner? if so display the message and 
break the loop
        if ( pPlayer->IsRoundWinner() )
        {
            UTIL_ClientPrintAll( HUD_PRINTCENTERCONSOLE, "Player '%s1' 
Wins", pPlayer->GetPlayerName() );
            break;
        }
    }
#endif
}

-------

As far as I know it should work, but may not be very efficient.
Also I do realize that players with the same score will not be counted 
as winners, I first want to know if this way of finding the winner is 
correct and works, once I know that I can fiddle with it so players with 
the same score won't be left out. Which brings me to my next question: 
Does printcenter and/or printconsole, support newlines?

Thanks in advance

_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to