|
|
| (3 intermediate revisions by one other user not shown) |
| Line 1: |
Line 1: |
| __NOTOC__
| | #REDIRECT [[PT-BR/GivePlayerMoney]] |
| {{Server client function}}
| |
| Esta função soma uma certa quantia em dinheiro ao dinheiro já existente de um determinado [[player|jogador]]. Se quiser definir o dinheiro do jogador como um todo ao invés de adicionar ao já existente, consulte a função [[setPlayerMoney]].
| |
| | |
| {{Note|Usar esta função no lado cliente (não recomendado) não altera o dinheiro do jogador no lado servidor.}}
| |
| | |
| ==Sintaxe==
| |
| <section name="Server" class="server" show="true">
| |
| <syntaxhighlight lang="lua">bool givePlayerMoney ( player thePlayer, int amount )</syntaxhighlight>
| |
| {{OOP||[[player]]:giveMoney|money}}
| |
| | |
| ===Argumentos obrigatórios===
| |
| *'''thePlayer:''' o [[player|jogador]] o qual receberá o dinheiro.
| |
| *'''amount:''' um valor inteiro, positivo, representando a quantidade de dinheiro que será dada ao jogador.
| |
| </section>
| |
| <section name="Client" class="client" show="true">
| |
| <syntaxhighlight lang="lua">bool givePlayerMoney ( int amount )</syntaxhighlight>
| |
| {{OOP||[[Player]].giveMoney}}
| |
| | |
| ===Argumentos obrigatórios===
| |
| *'''amount:''' um valor inteiro, positivo, representando a quantidade de dinheiro que será dada ao jogador.
| |
| </section>
| |
| | |
| ===Retorno===
| |
| Retorna ''true'' se o dinheiro foi adicionado com sucesso, ou ''false'' caso algum parâmetro passado seja inválido.
| |
| | |
| ==Exemplo==
| |
| <section show="true" name="Example 1 - Client and Server" class="server">
| |
| Este exemplo dá ao jogador uma certa quantia de dinheiro quando este usar o comando "/givecash <quantidade>". Ao digitar "/givecash 5000", por exemplo, o jogador recebe 5.000.
| |
| <syntaxhighlight lang="lua">
| |
| -- Função chamada quando o comando "/givecash <quantidade>" é digitado
| |
| function consoleGiveCash ( thePlayer, command, amount )
| |
| | |
| -- Dá a quantidade informada no comando ao jogador que o digitou
| |
| givePlayerMoney ( thePlayer, amount )
| |
| end
| |
| | |
| -- Cria o comando "givecash" informando qual função deve ser chamada quando o comando for digitado
| |
| addCommandHandler ( "givecash", consoleGiveCash )
| |
| </syntaxhighlight>
| |
| </section>
| |
| | |
| <section show="true" name="Example 2 - Server" class="server">
| |
| Este exemplo dá ao jogador mil "dólares" como recompensa por matar outro jogador.
| |
| | |
| <syntaxhighlight lang="lua">
| |
| function rewardOnWasted ( ammo, killer, killerweapon, bodypart )
| |
|
| |
| -- Se existir um assassino, e o assassino não for o mesmo jogador que morreu
| |
| if ( killer ) and ( killer ~= source ) then
| |
| | |
| -- Dá ao assassino 1000 em dinheiro
| |
| givePlayerMoney ( killer, 1000 )
| |
| end
| |
| end
| |
| | |
| -- Aplica a função "#rewardOnWasted" ao evento "onPlayerWasted", que é emitido sempre que um jogador morre | |
| addEventHandler ( "onPlayerWasted", getRootElement(), rewardOnWasted )
| |
| </syntaxhighlight>
| |
| </section>
| |
| | |
| <section show="true" name="Example 3 - Server" class="server">
| |
| Este exemplo cria um coletável no chão que, ao ser coletado, dá 30.000 ao jogador.
| |
| | |
| <syntaxhighlight lang="lua">
| |
| -- Cria o coletável no chão
| |
| local money = createPickup (1896.4000244141, -1950.9000244141, 13, 3, 1274, 10000 )
| |
| | |
| -- Função chamada quando o evento "onPickupUse" é emitido
| |
| function pickupUse ( player )
| |
| givePlayerMoney ( player, 30000 )
| |
| end
| |
| | |
| -- Aplica a função "#pickupUse" ao evento "onPickupUse", que é emitido sempre que um jogador para em um coletável estando a pé
| |
| addEventHandler ( "onPickupUse", money, pickupUse )</syntaxhighlight>
| |
| </section>
| |
| | |
| ==Veja também==
| |
| {{Player functions}}
| |
| [[ru:GivePlayerMoney]]
| |