Scripting/Squirrel/Functions/Players/Cash

From VC-MP Wiki

Jump to: navigation, search

This instance variable returns or sets player's cash.

Syntax

int player.Cash

player.Cash = newCash

Example 1. Returning

This command gives player's cash when someone types '/c cash playername'.

function onPlayerCommand( player, cmd, text )
{
     if ( cmd == "cash" )
     {
          local plr = FindPlayer( text );
          
          if ( !plr ) MessagePlayer( "Error: Player '" + text + "' is not online.", player );
          else MessagePlayer( plr.Name + "'s cash: $" + plr.Cash, player );
     }
}

Notes

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


Example 2. Setting

This command gives $1000000 to the player who types '/c richman'.

function onPlayerCommand( player, cmd, text )
{
     if ( cmd == "richman" )
     {
          player.Cash += 1000000;
     }
}

Notes

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


Related Functions

Personal tools
squirrel scripting