• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

player:getStringStorage & player:setStringStorage

Xtr3m3

Member
Joined
May 14, 2009
Messages
131
Reaction score
11
Hi guys, anyone can help me?

I need a c++ function, similar to player:getStorageValue and player:setStorageValue, but this can accept string values, like:
player:getStringStorage(key)
player:setStringStorage(key, value)

I have this database:
Code:
CREATE TABLE IF NOT EXISTS `string_storage` (
  `id` int(11) NOT NULL DEFAULT '0',
  `key` int(10) unsigned NOT NULL DEFAULT '0',
  `value` varchar(255) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`,`key`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

@Lordfire or @WibbenZ, you are experts in this area, any can help me?
Thanks a lot.
 
Last edited:
good idea ... to work better with the quests without to see what storage not are used ...
if they make this I'll use :3
 
Not tested because I don't have servers running :)
If your going to use this as an extra table in your database
Code:
CREATE TABLE IF NOT EXISTS `string_storage` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `player_id` int(11) NOT NULL DEFAULT '0',
  `key` int(10) unsigned NOT NULL DEFAULT '0',
  `value` varchar(255) DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

Add this to players.lua
Code:
function Player.getStringStorage(key)
   local id = self:getAccountId()
   local value = db.query("SELECT `value` FROM `string_storage` WHERE `player_id` == "..id.." AND `key` == "..key..";")
   return value ~= nil and value or nil
end

function Player.setStringStorage(key, value)
   local id = self:getAccountId()
   if key == nil then -- this just lets you know your key has no value
     self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, " key is nil")
   end
   if value == nil then -- this just lets you know your value has no value
     self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, " value is nil")
   end
   if key ~= nil and value ~= nil then
     db.query("INSERT INTO `string_storage` (`id`, `player_id`, `key`, `value`) VALUES (","..id..", "..key..", "..value..");")
   end
end

And then you can call it like you want

Code:
player:getStringStorage(key)
player:setStringStorage(key, value)
 
Last edited:
works this?
Not tested because I don't have servers running :)
If your going to use this as an extra table in your database
Code:
CREATE TABLE IF NOT EXISTS `string_storage` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `player_id` int(11) NOT NULL DEFAULT '0',
  `key` int(10) unsigned NOT NULL DEFAULT '0',
  `value` varchar(255) DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

Add this to players.lua
Code:
function Player.getStringStorage(key)
   local id = self:getAccountId()
   local value = db.query("SELECT `value` FROM `string_storage` WHERE `player_id` == "..id.." AND `key` == "..key..";")
   return value ~= nil and value or nil
end

function Player.setStringStorage(key, value)
   local id = self:getAccountId()
   if key == nil then -- this just lets you know your key has no value
     self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, " key is nil")
   end
   if value == nil then -- this just lets you know your value has no value
     self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, " value is nil")
   end
   if key ~= nil and value ~= nil then
     db.query("INSERT INTO `string_storage` (`id`, `player_id`, `key`, `value`) VALUES (","..id..", "..key..", "..value..");")
   end
end

And then you can call it like you want

Code:
player:getStringStorage(key)
player:setStringStorage(key, value)
 
i use:
player:getStorageValue(SV.deerTask)
In other words, keep all your in-game storage values inside an table.
 
Why even use string, when they are alot slower than int values. There are like 4294967295 storage ids to use, use them.
 
Why even use string, when they are alot slower than int values. There are like 4294967295 storage ids to use, use them.

One of the pros I can think of is that you don't need to have a huge lib file listing the storages (or a list / remember the id).
Ex. player:getStorageValue("isDHQFinished") == 1 :p

only 4294966672 left here.
You could always use higher integer types, ex. uint64_t.
But that would ofc require a source edit :)
 
Back
Top