- Joined
- Feb 14, 2015
- Messages
- 5,643
- Solutions
- 559
- Reaction score
- 3,949
SQL Query:
data/lib/core/player.lua:
example:
SQL:
CREATE TABLE `account_storage` ( `account_id` INTEGER(4), `key` INTEGER(10), `value` INTEGER(10) )
data/lib/core/player.lua:
Lua:
function Player.getAccountStorageValue(self, key)
if type(key) ~= "number" then
return false
end
local query = db.storeQuery("SELECT `value` FROM `account_storage` WHERE `account_id` = ".. self:getAccountId() .." AND `key` = ".. key)
if not query then
return false
end
local value = result.getDataInt(query, "value")
result.free(query)
return value
end
function Player.setAccountStorageValue(self, key, value)
if type(key) ~= "number" then
return false
end
local query = ""
if self:getAccountStorageValue(key) then
query = ("UPDATE `account_storage` SET `value` = %d WHERE `account_id` = %d AND `key` = %d"):format(value, self:getAccountId(), key)
else
query = ("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES (%d, %d, %d)"):format(self:getAccountId(), key, value)
end
return db.query(query)
end
example:
Lua:
local player = Player("Xeraphus")
player:setAccountStorageValue(10000, 1)
print(player:getAccountStorageValue(10000)) -- prints 1
player:setAccountStorageValue(10000, 23487) -- update pre-existing storage
print(player:getAccountStorageValue(10000)) -- prints 23487