how to check variable is maximum
#1

how to check variable is maximum

ex.

for(new i; i=0; i++)
{
if(dmscore[i] is maximum)
{
getplayername(i,name)
SendClientMessagetoall(Winner Is name)
Reply
#2

I'm assuming you want to check who has the highest score on the server, no? If so, the following code can help you.
pawn Код:
GetHighestDMScore()
{
   new highscore, highcount, highID = INVALID_PLAYER_ID;
   for( new i = 0; i < MAX_PLAYERS; i ++ )
   {
      if( dmscore[ i ] > highscore )
      {
         highscore = dmscore[ i ];
         highID = i;
         highcount = 0;
      }
      else if( dmscore[ i ] == highscore )
      {
         highcount++;
         highID = INVALID_PLAYER_ID;
      }
   }

   if( count > 0 )
   {
      // Someone else, or more, had the same highest score
   }
   else if( highID == INVALID_PLAYER_ID )
   {
      // No one had a high score, or no players connected (most likely outcome)
   }
   else
   {
      // Person with the highest score is in the variable 'highID'
   }
}
Read the comments to determine where to put the code that you wish. Please note that this is also not tested, so you will be responsible for doing so.
Reply
#3

Sorry i didnt really get that, can u please be moar clear, thx.
Reply
#4

1st score
2nd score
3nd score please
Reply
#5

That would be more complicated, but not necessarily hard. I gave you a base code, so build off of it - You will be required to use your personal knowledge here.

You will need to make so the highscore variable is an array, of three slots. Then check if the score of the current player id is above any of them. If the first, move down the other two, second, move down the last, etc. It's all more if statements and math.
Reply
#6

thank man !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)