GivePlayerMoney: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(→‎Syntax: OOP syntax added)
(add client oop syntax)
Line 7: Line 7:
<section name="Server" class="server" show="true">
<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>  
{{OOP||[[player]]:giveMoney|money|}}
{{OOP||[[player]]:giveMoney|money}}
===Required Arguments===  
===Required Arguments===  
*'''thePlayer:''' the [[player]] you are giving the money to.
*'''thePlayer:''' the [[player]] you are giving the money to.
Line 14: Line 14:
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">bool givePlayerMoney ( int amount )</syntaxhighlight>  
<syntaxhighlight lang="lua">bool givePlayerMoney ( int amount )</syntaxhighlight>  
 
{{OOP||[[Player]].giveMoney|money}}
===Required Arguments===  
===Required Arguments===  
*'''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.

Revision as of 23:19, 28 December 2014

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

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

Syntax

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

OOP Syntax Help! I don't understand this!

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


Required Arguments

  • thePlayer: the player you are giving the money to.
  • amount: a positive integer number specifying the amount of money to give to the player.
Click to collapse [-]
Client
bool givePlayerMoney ( int amount )

OOP Syntax Help! I don't understand this!

Method: Player.giveMoney(...)
Variable: .money


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

Click to collapse [-]
Example 1 - Client and Server

This example gives a player money when using "givecash" command.

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"
Click to collapse [-]
Example 2 - Server

This example gives a player one thousand dollars, 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