GivePlayerMoney: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
This function adds money to a [[player]]'s current money amount.
This function adds money to a [[player]]'s current money amount.  To set absolute values, [[setPlayerMoney]] can be used.


==Syntax==  
==Syntax==  
Line 7: Line 7:
===Required Arguments===  
===Required Arguments===  
*'''thePlayer:''' the [[player]] to whom you are giving the money.
*'''thePlayer:''' the [[player]] to whom you are giving the money.
*'''amount:''' an integer number specifying the amount of money to give to the player.
*'''amount:''' a positive integer number specifying the amount of money to give to the player.


===Returns===
===Returns===
Line 13: Line 13:


==Example==   
==Example==   
This example gives a player money when he types "givecash" in console.
'''Example 1:''' This example gives a player money when he types "givecash" in console.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addCommandHandler ( "givecash", "giveCash" ) --add a handler function for the command "givecash"
function consoleGiveCash ( thePlayer, command, amount ) --when the givecash command is called
function giveCash ( thePlayer, command, amount ) --when the givecash command is called
givePlayerMoney ( thePlayer, amount ) --give the player money according to the amount
givePlayerMoney ( thePlayer, amount ) --give the player money according to the amount
end
end
addCommandHandler ( "givecash", consoleGiveCash  ) --add a handler function for the command "givecash"
</syntaxhighlight>
</syntaxhighlight>
'''Example 2:''' This example gives a player $1000 money as a reward for killing another player.
<syntaxhighlight lang="lua">
function onPlayerWasted ( ammo, killer, killerweapon, bodypart )
--if there is a killer, and that killer is not the same person as whoever died
if ( killer ) and ( killer ~= source ) then
givePlayerMoney ( killer, 1000 ) --reward the killer with 1000 cash.
end
end


==See Also==
==See Also==
{{Player functions}}
{{Player functions}}</syntaxhighlight>

Revision as of 15:11, 29 July 2007

This function adds money to a player's current money amount. To set absolute values, setPlayerMoney can be used.

Syntax

bool givePlayerMoney ( player thePlayer, int amount )

Required Arguments

  • thePlayer: the player to whom you are giving the money.
  • amount: a positive integer number specifying the amount of money to give to the player.

Returns

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

Example

Example 1: This example gives a player money when he types "givecash" in console.

function consoleGiveCash ( thePlayer, command, amount ) --when the givecash command is called
	givePlayerMoney ( thePlayer, amount ) --give the player money according to the amount
end
addCommandHandler ( "givecash", consoleGiveCash  ) --add a handler function for the command "givecash"

Example 2: This example gives a player $1000 money as a reward for killing another player.

function onPlayerWasted ( ammo, killer, killerweapon, bodypart )
	--if there is a killer, and that killer is not the same person as whoever died
	if ( killer ) and ( killer ~= source ) then 
		givePlayerMoney ( killer, 1000 ) --reward the killer with 1000 cash.
	end
end

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