E
Evil Puncker
Guest
Okay this is a followup to my other thread, but since this is another problem and that one was already solved, I thought it is better to open a new topic so here I am, the functions from the other thread, and the following script:
the issue:
the first print (using getaccountstoragevalue) prints 1585508212, thus making the if check not working as intended
the second print (using getstoragevalue) prints 51, which is right and makes the if check works great
the third print, prints 30115 1585508211
and I don't know what is wrong with these functions, they were supposed to work the same (print the same as the default getstoragevalue), but they print that big number instead, help me to figure this out
Lua:
local juiceSquizer = Action()
function juiceSquizer.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if (os.time() - player:getAccountStorageValue(30115)) >= 72000 then
player:addItem(22728, 1)
print(os.time() - player:getAccountStorageValue(30115))
print(os.time() - player:getStorageValue(30115))
player:setStorageValue(30115, os.time())
player:setAccountStorageValue(30115, os.time())
print(30115, os.time())
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found a tinder box.")
else
player:sendCancelMessage("The pile of bones is empty.")
end
return true
end
juiceSquizer:aid(6000)
juiceSquizer:register()
the issue:
the first print (using getaccountstoragevalue) prints 1585508212, thus making the if check not working as intended
the second print (using getstoragevalue) prints 51, which is right and makes the if check works great
the third print, prints 30115 1585508211
and I don't know what is wrong with these functions, they were supposed to work the same (print the same as the default getstoragevalue), but they print that big number instead, help me to figure this out
SQL:
CREATE TABLE IF NOT EXISTS `account_storage` (
`account_id` int(4) NOT NULL DEFAULT '0',
`key` int(10) unsigned NOT NULL DEFAULT '0',
`value` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`account_id`,`key`),
FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB;
--
-- Constraints for table `account_storage`
--
ALTER TABLE `account_storage`
ADD CONSTRAINT `account_storage_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
Lua:
function Player.getAccountStorageValue(self, key)
local toNumber = tonumber(key)
if not toNumber 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 -1
end
local value = result.getNumber(query, "value")
result.free(query)
return value
end
function Player.setAccountStorageValue(self, key, value)
local toNumber = tonumber(key)
if not toNumber then
return false
end
local query = ""
if self:getAccountStorageValue(key) then
query = ("UPDATE `account_storage` SET `value` = ".. value .." WHERE `account_id` = ".. self:getAccountId() .." AND `key` = "..key)
else
query = ("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES (".. self:getAccountId() ..", ".. key ..", ".. value ..")")
end
return db.query(query)
end
Last edited by a moderator: