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

Lua How to set a account storage?

gnr

New Member
Joined
Dec 18, 2008
Messages
92
Reaction score
0
I would like to know, how to set a account storage..

I think that is this function:

PHP:
setGlobalStorageValue(valueid, newvalue)

But I am in doubt...

Can someone help me?
 
Well I didn't make these functions, but I forgot where I found them.

So, credits to the original maker!

First run this query in your database:
Code:
CREATE TABLE `account_storage`
(
	`account_id` INT NOT NULL DEFAULT 0,
	`key` INT UNSIGNED NOT NULL DEFAULT 0,
	`value` VARCHAR(255) NOT NULL DEFAULT '0',
	KEY (`account_id`), UNIQUE (`account_id`, `key`),
        FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE CASCADE
) ENGINE =MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=48 ;

And then go into data/lib/function.lua and add these functions:
PHP:
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
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
 
Well I didn't make these functions, but I forgot where I found them.

So, credits to the original maker!

First run this query in your database:
Code:
CREATE TABLE `account_storage`
(
    `account_id` INT NOT NULL DEFAULT 0,
    `key` INT UNSIGNED NOT NULL DEFAULT 0,
    `value` VARCHAR(255) NOT NULL DEFAULT '0',
    KEY (`account_id`), UNIQUE (`account_id`, `key`),
        FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE CASCADE
) ENGINE =MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=48 ;

And then go into data/lib/function.lua and add these functions:
PHP:
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
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

two things:

1. which database am I running that first part in on localhost? otserv database, I'm assuming?
2. I cant find data/lib/function.lua in my server files.

@Xikini
@Bintzer
 
Back
Top