GivePlayerMoney: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 4: Line 4:


==Syntax==  
==Syntax==  
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">bool givePlayerMoney ( player thePlayer, int amount )</syntaxhighlight>  
<syntaxhighlight lang="lua">bool givePlayerMoney ( player thePlayer, int amount )</syntaxhighlight>  


Line 9: Line 10:
*'''thePlayer:''' the [[player]] to whom you are giving the money.
*'''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.
*'''amount:''' a positive integer number specifying the amount of money to give to the player.
</section>
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">bool givePlayerMoney ( int amount )</syntaxhighlight>
===Required Arguments===
*'''amount:''' a positive integer number specifying the amount of money to give to the player.
</section>


===Returns===
===Returns===

Revision as of 11:56, 6 November 2010

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

Syntax

Click to collapse [-]
Server
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.
Click to collapse [-]
Client
bool givePlayerMoney ( int amount )

Required Arguments

  • 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 rewardOnWasted ( 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
addEventHandler ( "onPlayerWasted", getRootElement(), rewardOnWasted ) --attach the rewardOnWasted function to the relevant event.

See Also