PT-BR/takeNumFromElementData: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Non-existent function removed from list)
m (Changed template to Portuguese version.)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Useful Function}}
{{BR/Useful_Function}}
Esta função é utilizada para subtrair o numero de uma determinada [[PT-BR/Element_data|ElementData]].  
Esta função é utilizada para subtrair o numero de uma determinada [[PT-BR/Element_data|ElementData]].  
'''NOTA:''' Só pode ser usado em [[PT-BR/Element_data|ElementData]].
'''NOTA:''' Só pode ser usado em [[PT-BR/Element_data|ElementData]].

Revision as of 18:15, 21 January 2021

Template:BR/Useful Function Esta função é utilizada para subtrair o numero de uma determinada ElementData. NOTA: Só pode ser usado em ElementData.

Syntax

bool takeNumFromElementData( player thePlayer, int amount, string key )

Argumentos obrigatórios

  • thePlayer: Caso seja em server-side, caso seja em client-side use: getLocalPlayer().
  • amount: O valor que deseja subtrair.
  • key: O nome do ElementData a qual você deseja subtrair o valor.

Returns

Se esta função retorna arg.3 quer dizer que o elemento citado não exista ou não tem valor atribuido, arg.2 caso não determine o valor(lembrando deve ser um número !).

Código

Click to collapse [-]
Funcao compartilhada - Shared
function takeNumFromElementData( thePlayer, amount, key)
    if tonumber ( amount )  then
        if ( getElementData( thePlayer, tostring ( key ) ) ) then
            return setElementData ( thePlayer, key, ( getElementData( thePlayer, tonumber( key ) ) - tonumber(amount) ) )
        else
            outputDebugString ( "Error: arg.3", 3, 255, 0, 0, 0 )
        end
    else
        outputDebugString ( "Error: arg.2", 3, 255, 0, 0, 0 )
    end
  	return false
end

Author: Hiroshi Nagaza


Exemplo

Click to collapse [-]
Server

Este exemplo subtrair o número de um ElementData, chamado: "HR_LEVEL".

function RemoverLevels( thePlayer, command, amount, key )
   takeNumFromElementData(thePlayer, amount, key )
end
addEventHandler ( "takelevels", RemoverLevels) -- no caso o comando seria: /takelevels 20 HR_LEVEL

Veja Também