Ir para conteúdo

TFS[1.X] Account Storage Value


Furabio

Posts Recomendados

Essa é uma função que criei a uns meses já.

 

Primeiro vá ao seu phpmyadmin e execute essa query na 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;

Agora só usar nos scripts ou na lib :

function getAccountStorageValue(accid, key)
	local resultId = db.storeQuery("SELECT `account_id`, `key` FROM `account_storage` WHERE `account_id` = " .. accid .. " and `key` = " .. key)
	if resultId ~= false then
		return result.getNumber(resultId, 'key')
	else
		return -1
	end
	return resultId:free()
end

function setAccountStorageValue(accid, key, value)
	local resultId = db.storeQuery("SELECT `value` FROM `account_storage` WHERE `account_id` = " .. accid .. " and `key` = " .. key)
	if resultId ~= false then
		db.query("UPDATE `account_storage` SET `value` = " .. accid .. " WHERE `key`=" .. key .. " LIMIT 1');")
	else
		db.query("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES (" .. accid .. ", " .. key .. ", '"..value.."');")
	end
	return true
end

Modo de uso :

function onLogin(player)
	local storage = 545465
	local pid = player:getGuid()
	local query = db.storeQuery("SELECT `account_id` FROM `players` WHERE `id` = ".. pid)
	local value = result.getNumber(query, 'account_id')

	if getAccountStorageValue(value, storage) < 1 then
		player:addPremiumDays(3)
		setAccountStorageValue(value, storage, 1)
	end
	return true
end

Script original veio do teckman, eu adaptei pras novas versões.

You see!~

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...