GivePlayerMoney: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(example - onConsole -> command handlers)
Line 10: Line 10:


==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
This example gives a player money when he types "givecash" in console
<syntaxhighlight lang="lua">addEventHandler ( "onPlayerConsole", root, "onConsole" )
<syntaxhighlight lang="lua">addCommandHandler ( "givecash", "giveCash" ) --add the command "takecash"
function onConsole ( message )
function giveCash ( player, command, amount ) --when the takecash command is called
if gettok(message, 1, 32) == "!givecash" then --when the player types !givecash in the console
givePlayerMoney ( player, amount ) --take the player's money according to the amount
givePlayerMoney ( source, 100 ) --add $100 to player's money
end
end</syntaxhighlight>
end</syntaxhighlight>


==See Also==
==See Also==
{{Player functions}}
{{Player functions}}

Revision as of 23:54, 17 November 2006

Adds money to the player's current money amount.

Syntax

givePlayerMoney ( player, money )

Required Arguments

  • Player: Tells the function to give money to a player
  • Money: A whole integer specifying the amount of money to give to the player

Example

This example gives a player money when he types "givecash" in console

addCommandHandler ( "givecash", "giveCash" ) --add the command "takecash"
function giveCash ( player, command, amount ) --when the takecash command is called
	givePlayerMoney ( player, amount ) --take the player's money according to the amount
end

See Also