Ir para conteúdo
Entre para seguir isso  
Elwyn

[TFS 1.X] Get/Set storage value de um jogador

Recommended Posts

Elwyn    106
Elwyn

Crie um arquivo em talkactions/scripts chamado storage.lua e ponha o seguinte código:

function onSay(cid, words, param, type)
    local player = Player(cid)
    if not player or not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GAMEMASTER then
        return false
    end

    -- Extract the specified parameters.
    local parameters = param:split(",")

    if words == "/getstorage" and parameters[2] == nil then
        player:sendCancelMessage("Insufficient parameters, usage: !getstorage playerName, key")
        return false
    end

    if words == "/setstorage" and parameters[3] == nil then
        player:sendCancelMessage("Insufficient parameters, usage: !setstorage playerName, key, value")
        return false
    end

    -- Remove trailing/leading white spaces from parameters.
    local playerName = (parameters[1] or ""):trim()
    local storageKey = tonumber(parameters[2]) or 0

    -- Get meta player.
    local checkedPlayer = Player(playerName)
    if not checkedPlayer then
        player:sendCancelMessage(string.format("Could not find player '%s'.", playerName))
        player:getPosition():sendMagicEffect(CONST_ME_BUBBLES)

        return false
    end

    local storageValue = tonumber(parameters[3]) or checkedPlayer:getStorageValue(storageKey)
    local msg = string.format("Storage key '%s' %s set to '%d' for player '%s'.", storageKey, "%s", storageValue, checkedPlayer:getName())
    if words == "/setstorage" then
        -- Set specified storage value on player.
        checkedPlayer:setStorageValue(storageKey, storageValue)
        msg = string.format(msg, "is now")
    else
        -- Get specified storage value from player.
        msg = string.format(msg, "is currently")
    end

    -- Print the message in Local Chat in orange (only self can see).
    player:sendTextMessage(MESSAGE_EVENT_ORANGE, msg)
    player:getPosition():sendMagicEffect(CONST_ME_BUBBLES)
end

Em talkactions.xml ponha as seguintes tags:

    <talkaction words="/getstorage" separator=" " script="storage.lua"/>
    <talkaction words="/setstorage" separator=" " script="storage.lua"/>

Compartilhar este post


Link para o post
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  
  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×