Scripting/Squirrel/Functions/Players/Score

From VC-MP Wiki

Jump to: navigation, search

This instance variable returns or sets player's score.

Syntax

int player.Score

player.Score = newScore


Example 1. Returning

This command gives the player with highest score when someone types '/c mostdangerous'.

function onPlayerCommand( player, cmd, text )
{
     if ( cmd == "mostdangerous" )
     {
          local highestScore = 0, mostDangerous;
          
          for ( local i = 0; i < GetMaxPlayers(); i++ )
          {
               local p = FindPlayer( text );
               if ( p )
               {
                    if ( p.Score > highestScore )
                    {
                         mostDangerous = p;
                         highestScore = p.Score;
                    }
               }
          }
          
          if ( highestScore == 0 ) MessagePlayer( "Nobody has a positive score, so everybody is a loser!", player );
          else MessagePlayer( "The most dangerous player is " + mostDangerous.Name + " with a score of " + mostDangerous.Score + ".", player );
     }
}

Notes

The functions MessagePlayer, FindPlayer, player.Name, GetMaxPlayers and call onPlayerCommand were used in in this example. More info about them in corresponding pages.


Example 2. Setting

This example increases player score if they kill someone.

function onPlayerKill( killer, killed, weapon )
{
     killer.Score++;
}

Notes

The call onPlayerKill was used in in this example. More info about it in the corresponding page.

Related Functions

Personal tools
squirrel scripting