Achei essa função em outro forum e decidi postar aqui pq ela é muuito util. Antes de qualquer coisa execute essa query na sua db:
CREATE TABLE `account_storage` (
`account_id` int(11) NOT NULL default '0',
`key` int(10) unsigned NOT NULL default '0',
`value` varchar(255) NOT NULL default '0',
UNIQUE KEY `account_id_2` (`account_id`,`key`),
KEY `account_id` (`account_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
E no data/lib/050-function.lua adiciona o codigo
function getAccountStorageValue(accid, key)
local value = db.getResult("SELECT `value` FROM `account_storage` WHERE `account_id` = " .. accid .. " and `key` = " .. key .. " LIMIT 1;")
if(value:getID() ~= -1) then
return value:getDataInt("value")
else
return -1
end
value:free()
end
function setAccountStorageValue(accid, key, value)
local getvalue = db.getResult("SELECT `value` FROM `account_storage` WHERE `account_id` = " .. accid .. " and `key` = " .. key .. " LIMIT 1;")
if(getvalue:getID() ~= -1) then
db.executeQuery("UPDATE `account_storage` SET `value` = " .. accid .. " WHERE `key`=" .. key .. " LIMIT 1');")
getvalue:free()
return 1
else
db.executeQuery("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES (" .. accid .. ", " .. key .. ", '"..value.."');")
return 1
end
end
Modo de uso:
getAccountStorageValue(getPlayerAccountId(cid), key)
setAccountStorageValue(getPlayerAccountId(cid), key, value)
Os créditos são do teckman por criar a função e do Matheus por postar no outro fórum.