GetPlayerMoney: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
 
(44 intermediate revisions by 18 users not shown)
Line 1: Line 1:
hour, min = getTime ()serverChat ( "The current time is ", hour, ":", min )
__NOTOC__  
__NOTOC__  
Returns the money level of a player
{{Server client function}}
Returns the amount of money a player currently has.
{{Note|The amount may vary between the server and client, you shouldn't trust the client side value to always be accurate.}}


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">getPlayerMoney ( player )</syntaxhighlight>  
<section show="true" name="Server" class="server">
<syntaxhighlight lang="lua">int getPlayerMoney ( player thePlayer )</syntaxhighlight>
{{OOP||[[player]]:getMoney|money|setPlayerMoney}}
===Required Arguments===
*'''thePlayer:''' The player you wish the retrieve the amount of money from.
 
===Returns===
Returns an integer with the amount of money the specified player has, ''false'' if the player is invalid.
</section>


===Required Arguments===  
<section show="true" name="Client" class="client">
*'''Player:''' Tells the function to give money to a player
<syntaxhighlight lang="lua">int getPlayerMoney ( )</syntaxhighlight>
{{OOP||[[Player]].getMoney||setPlayerMoney}}
===Returns===
Returns an integer with the amount of money the local player has.
</section>


==Example==
==Example==
<syntaxhighlight lang="lua">addEventHandler ( "onPlayerConsole", root, "onConsole" )
<section show="true" name="Server" class="server">
function onConsole ( message )
When a player types '/checkMoney' this example retrieves the player's money and outputs a message according to the value.
if gettok(message, 1, 32) == "!checkcash" then --when the player types !checkcash in the console
<syntaxhighlight lang="lua">
local playermoney = getPlayerMoney ( source ) --set playermoney varible to player's current cash
function checkMoney(thePlayer, command)
serverChat ( "Your cash: ".. playermoney ) --display their current cash in the chatbox
local money = getPlayerMoney(thePlayer)                               -- get the amount of money from the player who entered the command
if (money > 1000) then                                                -- if money is more than 1000
outputChatBox("You are rich: " .. tostring(money), thePlayer)  -- output this message together with the money
else
outputChatBox("Poor guy...", thePlayer)                        -- and else, output this message
end
end
end</syntaxhighlight>
end
addCommandHandler("checkMoney", checkMoney)                                    -- add the console command
</syntaxhighlight>
</section>
 
==See Also==
{{Player functions}}
 
[[pt-br:getPlayerMoney]]
[[ru:getPlayerMoney]]
[[tr:getPlayerMoney]]

Latest revision as of 03:55, 11 August 2019

Returns the amount of money a player currently has.

[[{{{image}}}|link=|]] Note: The amount may vary between the server and client, you shouldn't trust the client side value to always be accurate.

Syntax

Click to collapse [-]
Server
int getPlayerMoney ( player thePlayer )

OOP Syntax Help! I don't understand this!

Method: player:getMoney(...)
Variable: .money
Counterpart: setPlayerMoney


Required Arguments

  • thePlayer: The player you wish the retrieve the amount of money from.

Returns

Returns an integer with the amount of money the specified player has, false if the player is invalid.

Click to collapse [-]
Client
int getPlayerMoney ( )

OOP Syntax Help! I don't understand this!

Method: Player.getMoney(...)
Counterpart: setPlayerMoney


Returns

Returns an integer with the amount of money the local player has.

Example

Click to collapse [-]
Server

When a player types '/checkMoney' this example retrieves the player's money and outputs a message according to the value.

function checkMoney(thePlayer, command)
	local money = getPlayerMoney(thePlayer)                                -- get the amount of money from the player who entered the command
	if (money > 1000) then                                                 -- if money is more than 1000
		outputChatBox("You are rich: " .. tostring(money), thePlayer)  -- output this message together with the money
 	else
		outputChatBox("Poor guy...", thePlayer)                        -- and else, output this message
	end
end
addCommandHandler("checkMoney", checkMoney)                                    -- add the console command

See Also