• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Set and get player storage

trollebror

Developer
Joined
Aug 8, 2009
Messages
362
Reaction score
58
Location
Sweden, Linköping
Hello,
I will share these two scripts because they're so extremely useful. I'm sure that something similar already have been posted but here is my version of it. :)

I'm using TFS 1.1.

What does it do?
It allows you to set and get any online player storage with talkactions.

Usage examples
!setstorage God Trollebror, 25000, 1
!getstorage God Trollebror, 25000

Code
global.lua
Code:
function string.trim(self)
  return (self:gsub("^%s*(.-)%s*$", "%1"))
end

talkactions.xml
Code:
<talkaction words="!setstorage" separator=" " script="set_storage.lua"/>
<talkaction words="!getstorage" separator=" " script="get_storage.lua"/>

set_storage.lua
Code:
function onSay(player, words, param, type)
    if 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 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
    local storageValue = tonumber(parameters[3]) 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

    -- Set specified storage value on player.
    checkedPlayer:setStorageValue(storageKey, storageValue)

    -- Print the message in Local Chat in orange (only self can see).
    player:sendTextMessage(MESSAGE_EVENT_ORANGE, string.format("Storage key '%s' was set to '%s' for player '%s'.", storageKey, storageValue, checkedPlayer:getName()))

    player:getPosition():sendMagicEffect(CONST_ME_BUBBLES)
end

get_storage.lua
Code:
function onSay(player, words, param, type)
    if 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 parameters[2] == nil then
        player:sendCancelMessage("Insufficient parameters, usage: !getstorage playerName, key")
        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

    -- Get specified storage value from player.
    local storageValue = checkedPlayer:getStorageValue(storageKey)

    -- Print the message in Local Chat in orange (only self can see).
    player:sendTextMessage(MESSAGE_EVENT_ORANGE, string.format("Storage key '%s' is currently set to '%d' for player '%s'.", storageKey, storageValue, checkedPlayer:getName()))

    player:getPosition():sendMagicEffect(CONST_ME_BUBBLES)
end
 
Nice work ;)

Maybe it can be updated that it would be possible to change the storage for all online players. :)
 
Huh?
Code:
function onSay(cid, words, param, channel)
   local t = string.explode(param, ",")
   if(not t[2]) then
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid param specified.")
     return true
   end

   local tid = getPlayerByNameWildcard(t[1])
   if(not tid or (isPlayerGhost(tid) and getPlayerGhostAccess(tid) > getPlayerGhostAccess(cid))) then
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. t[1] .. " not found.")
     return true
   end

   if(not t[3]) then
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, " [" .. t[1] .. " - " .. t[2] .. "] = " .. getPlayerStorageValue(tid, t[2]))
   else
     setPlayerStorageValue(tid, t[2], t[3])
   end

   return true
end

This one comes with TFS 0.4 and works like:
/storage PlayerName,Storage,Amount (example: /storage Galana,4068,1)
 
Back
Top