SetPlayerMoney: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
(38 intermediate revisions by 24 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__
Sets a player's money to a certain value. This will NOT adjust money to different amounts. It will only set money to one specific amount. Use [[givePlayerMoney]] and [[takePlayerMoney]] to adjust money levels of players. Using either of them with this function will ignore the set money value and add or subtract the amount specified from $0.
{{Server client function}}
Sets a player's money to a certain value, regardless of current player money. It should be noted that setting negative values does not work and in fact gives the player large amounts of money.
{{Note|Using this function client side (not recommended) will not change a players money server side.}}


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">setPlayerMoney ( player, money ) </syntaxhighlight>  
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
bool setPlayerMoney ( player thePlayer, int amount [, bool instant = false ] ) </syntaxhighlight>  
{{OOP||[[player]]:setMoney|money|getPlayerMoney}}
===Required Arguments===
*'''thePlayer:''' Which player to set the money of.
*'''amount:''' A whole integer specifying the new amount of money the player will have.


===Optional Arguments===
{{OptionalArg}}
{{New items|3.0140|1.4|
*'''instant:''' If set to ''true'' money will be set instantly without counting up/down like in singleplayer.}}
</section>
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
bool setPlayerMoney ( int amount [, bool instant = false ] ) </syntaxhighlight>
{{OOP||[[Player]].setMoney||getPlayerMoney}}
===Required Arguments===  
===Required Arguments===  
*'''Player:''' Tells the function to give money to a player
*'''amount:''' A whole integer specifying the new amount of money the local player will have.
*'''Money:''' A whole integer specifying the amount of money to give to the player
 
===Optional Arguments===
{{OptionalArg}}
{{New items|3.0140|1.4|
*'''instant:''' If set to ''true'' money will be set instantly without counting up/down like in singleplayer.}}
</section>
 
===Returns===
Returns ''true'' if the money was added, or ''false'' if invalid parameters were passed.


==Example==   
==Example==   
<syntaxhighlight lang="lua">addEventHandler ( "onPlayerConsole", root, "onConsole" )
'''Example 1:''' This example sets the player's money to the desired amount when he types "setcash" in console.
function onConsole ( message )
<syntaxhighlight lang="lua">
if gettok(message, 1, 32) == "!makemerich" then --if the player types !makemerich in the console
function setCash(thePlayer, command, amount)       -- when the setcash function is called
setPlayerMoney ( source, 1000000 ) --change player's money to $1,000,000
    setPlayerMoney(thePlayer, tonumber(amount))   -- change player's money to the desired amount
elseif gettok(message, 1, 32) == "!makemepoor" then --if the player types !makemepoor in the console
end
setPlayerMoney ( source, 0 ) --change player's money to $0
addCommandHandler("setcash", setCash)           -- add a command handler for setcash
end
</syntaxhighlight>
end</syntaxhighlight>
'''Example 2:''' This sets all players the amount of 1337 money when "leet" is typed in console.
<syntaxhighlight lang="lua">
function leetmoney()
setPlayerMoney(root, 1337)
end
addCommandHandler("leet", leetmoney)
</syntaxhighlight>
 
==See Also==
{{Player functions}}
 
[[pt-br:SetPlayerMoney]]
[[ru:setPlayerMoney]]

Revision as of 18:44, 6 August 2020

Sets a player's money to a certain value, regardless of current player money. It should be noted that setting negative values does not work and in fact gives the player large amounts of money.

[[{{{image}}}|link=|]] Note: Using this function client side (not recommended) will not change a players money server side.

Syntax

Click to collapse [-]
Server
bool setPlayerMoney ( player thePlayer, int amount [, bool instant = false ] ) 

OOP Syntax Help! I don't understand this!

Method: player:setMoney(...)
Variable: .money
Counterpart: getPlayerMoney


Required Arguments

  • thePlayer: Which player to set the money of.
  • amount: A whole integer specifying the new amount of money the player will have.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • instant: If set to true money will be set instantly without counting up/down like in singleplayer.
Click to collapse [-]
Client
bool setPlayerMoney ( int amount [, bool instant = false ] ) 

OOP Syntax Help! I don't understand this!

Method: Player.setMoney(...)
Counterpart: getPlayerMoney


Required Arguments

  • amount: A whole integer specifying the new amount of money the local player will have.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • instant: If set to true money will be set instantly without counting up/down like in singleplayer.

Returns

Returns true if the money was added, or false if invalid parameters were passed.

Example

Example 1: This example sets the player's money to the desired amount when he types "setcash" in console.

function setCash(thePlayer, command, amount)       -- when the setcash function is called
    setPlayerMoney(thePlayer, tonumber(amount))    -- change player's money to the desired amount
end
addCommandHandler("setcash", setCash)           -- add a command handler for setcash

Example 2: This sets all players the amount of 1337 money when "leet" is typed in console.

function leetmoney()
	setPlayerMoney(root, 1337)
end
addCommandHandler("leet", leetmoney)

See Also