TakePlayerMoney: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
m (fix oop syntax 2)
 
(21 intermediate revisions by 14 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__
Subtracts money from the player's current money amount.
{{Server client function}}
This function subtracts money from a [[player]]'s current money amount.
{{Note|Using this function client side (not recommended) will not change a players money server side.}}


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">takePlayerMoney ( player, money )</syntaxhighlight>  
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
bool takePlayerMoney ( player thePlayer, int amount )
</syntaxhighlight>
{{OOP||[[player]]:takeMoney|money|}}
====Required Arguments====
*'''thePlayer:''' the [[player]] you are taking the money from.
*'''amount:''' an integer number specifying the amount of money to take from the player.
</section>
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
bool takePlayerMoney ( int amount )
</syntaxhighlight>
{{OOP||[[Player]].takeMoney}}
====Required Arguments====
*'''amount:''' an integer number specifying the amount of money to take from the player.
</section>


===Required Arguments===  
===Returns===
*'''Player:''' Tells the function to give money to a player
Returns ''true'' if the money was taken, or ''false'' if invalid parameters were passed.
*'''Money:''' A whole integer specifying the amount of money to give to the player


==Example==   
==Example==   
Note: Player is not defined in this function, so I used source to point to the player. You can read about using source on the [[LUA Tips and Tricks]] page
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">addEventHandler ( "onPlayerConsole", root, "onConsole" )
This example takes money from a player when he types "takecash ''number''" in the console.
function onConsole ( message )
<syntaxhighlight lang="lua">
if gettok(message, 1, 32) == "!takecash" then --when the player types !takecash
function takeCash ( thePlayer, command, amount )     -- when the takecash command is called
takePlayerMoney ( source, -100 ) --subtract $100 from player's money
    takePlayerMoney ( thePlayer, tonumber(amount) ) -- take the amount of money from the player
end
end
end</syntaxhighlight>
addCommandHandler ( "takecash", takeCash )          -- add a handler function for the command "takecash"
</syntaxhighlight>
</section>
 
==See Also==
{{Player functions}}
[[ru:takePlayerMoney]]

Latest revision as of 04:28, 29 December 2014

This function subtracts money from a player's current money amount.

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

Syntax

Click to collapse [-]
Server
bool takePlayerMoney ( player thePlayer, int amount )

OOP Syntax Help! I don't understand this!

Method: player:takeMoney(...)
Variable: .money


Required Arguments

  • thePlayer: the player you are taking the money from.
  • amount: an integer number specifying the amount of money to take from the player.
Click to collapse [-]
Client
bool takePlayerMoney ( int amount )

OOP Syntax Help! I don't understand this!

Method: Player.takeMoney(...)


Required Arguments

  • amount: an integer number specifying the amount of money to take from the player.

Returns

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

Example

Click to collapse [-]
Server

This example takes money from a player when he types "takecash number" in the console.

function takeCash ( thePlayer, command, amount )     -- when the takecash command is called
     takePlayerMoney ( thePlayer, tonumber(amount) ) -- take the amount of money from the player
end
addCommandHandler ( "takecash", takeCash )           -- add a handler function for the command "takecash"

See Also