• 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!

account storage value

Azi

Banned User
Joined
Aug 12, 2007
Messages
1,167
Reaction score
53
Location
Włocławek
i made easy function - getAccountStorageValue(accid, key) and setAccountStorageValue(accid, key, value). : )
I'm using it in friend ots to events - one event per account ; )
Function for tfs 0.3b2

data/lib/function.lua
PHP:
 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

and to database:
PHP:
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;

Your,
azi.
 
Last edited:
Great idea ;) now we can do better protection on server and better quests per account :)

Good job ; ]
 
Could be a nice plugin to TFSCMS.

~Auction System, at the internet page~.
 
Looks nice!
But how a add to database?
in phpmyadmin, go em sql and copy that code?
i did that and came this error

#1072 - Key column 'player_id' doesn't exist in table
 
Nice the database worked!
But something is wrong with the functions, when i pasted then in functions.lua appears this error in console

"data/lib/function.lua:511 'end' expected < to close 'if' at line 509> near 'value'
Warning: [LuaScriptInterface::initState] Can not loaddata/lib/data.lua

I think is relacioned to this script

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")
value:free()
else
return -1
end

end
 
if the result will be -1 then "value:free()" will give error
 
if the result will be -1 then "value:free()" will give error

What you meant?:p There is 'if' before ;>

Code:
if(value:getID() ~= -1) then
return value:getDataInt("value")
value:free()

So value won't be -1 ? Am I right?:D Or I am just the only one who don't understood ;p
 
What you meant?:p There is 'if' before ;>

Code:
if(value:getID() ~= -1) then
return value:getDataInt("value")
value:free()

So value won't be -1 ? Am I right?:D Or I am just the only one who don't understood ;p

Colandus was reffering to Azis script.

Also the one in your 'quote' will probably not event work, since you are already returning <something> and then you do value:free().
 
Is there anybody gonna fix this function?

Code:
function getAccountStorageValue(accountId, key)
	local result = db.getResult("SELECT `value` FROM `account_storage` WHERE `account_id` = " .. accountId .. " and `key` = " .. key .. " LIMIT 1;")
	if(result:getID() == -1) then
		return -1
	end

	local value = result:getDataInt("value")
	result:free()
	return value
end

function setAccountStorageValue(accountId, key, value)
	if(tonumber(value) == -1) then
		db.executeQuery("DELETE FROM `account_storage` WHERE `account_id` = " .. accountId .. " and `key` = " .. key .. " LIMIT 1;")
	else
		if(getAccountStorageValue(accountId, key) ~= -1) then
			db.executeQuery("UPDATE `account_storage` SET `value` = " .. accountId .. " WHERE `key` = " .. key .. " LIMIT 1');")
		else
			db.executeQuery("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES (" .. accountId .. ", " .. key .. ", '" .. value .. "');")
		end
	end

	return TRUE
end
doAccountSetStorageValue = setAccountStorageValue

(not tested)
 
Last edited:
Error ejecutando consulta: near "unsigned": syntax error
<simple query executor>
 
Sorry, posted in the wrong thread
 
Last edited:
Back
Top