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

Solved Global Storage + TFS 1.2

Status
Not open for further replies.

kito2

www.masteria.net
Joined
Mar 9, 2009
Messages
3,766
Solutions
1
Reaction score
225
Location
Chile, Santiago
I have been testing some things over TFS 1.2 and Game.setStorageValue(key, value) restarts after closing the server.

How it could be possible now to get global storage?

A friend told me to create a character a manage it's storages as global storage... But can you operate having the player offline, how to do so?

What I am facing right now is doing the respawn of Sight of Surrender at roshamuul depending the amount of piece of mouth horn used on the wall.

So actually I could save the amount used for each player and when the server start up check all storage id regarding this amount, sum them all and then summon the monsters and reset all the values to 0 again... Is this possible to do this? How to?
 
Last edited by a moderator:
Please stop making multiple posts and edit your last post instead. Unlike in old TFS 0.2 and 0.3, Global storages in TFS 1.x series are stored in RAM and get erased whenever server shuts down or restarts. You would have to create a table in your database and change the way global storages are handled, so they become permanent. You can achieve this via C++ (server-save queries) or LUA (real-time queries).
 
to get the storage
Code:
Game.getStorageValue(key)

I know that, but it is not a persistent value, it get reseted.

Please stop making multiple posts and edit your last post instead. Unlike in old TFS 0.2 and 0.3, Global storages in TFS 1.x series are stored in RAM and get erased whenever server shuts down or restarts. You would have to create a table in your database and change the way global storages are handled, so they become permanent. You can achieve this via C++ or LUA.

I can't edit any post I do, that's why Otherwise I could edited the main post. I don't know why.

I would like to manage it by LUA but how to do it? I remember some old functions like:

Code:
db.executeQuery("UPDATE  `player_intstorage` SET  `value` =  '".. killedMonsters .."' WHERE  `player_intstorage`.`player_id` = ".. getPlayerGUID(cid) .." AND  `player_intstorage`.`key` =  '3501682';")

As TFS 1.2 has changed its operation, how this would be possible to be done.
 
I would like to manage it by LUA but how to do it? I remember some old functions like:

Code:
db.executeQuery("UPDATE  `player_intstorage` SET  `value` =  '".. killedMonsters .."' WHERE  `player_intstorage`.`player_id` = ".. getPlayerGUID(cid) .." AND  `player_intstorage`.`key` =  '3501682';")

As TFS 1.2 has changed its operation, how this would be possible to be done.

database
SQL:
CREATE TABLE `global_storage`
(
    `key` INT UNSIGNED NOT NULL,
    `value` VARCHAR(255) NOT NULL DEFAULT '0',
    UNIQUE  (`key`)
) ENGINE = InnoDB;

replace those two functions in your compat.lua for these ones
Lua:
function getGlobalStorageValue(key)
    local query = db.storeQuery("SELECT `value` FROM `global_storage` WHERE `key` = " .. key .. ";")
    if query ~= false then
        local val = result.getDataString(query, "value")
        result.free(query)
        return val
    end
    return -1
end

function setGlobalStorageValue(key, value)
    db.query("INSERT INTO `global_storage` (`key`, `value`) VALUES (".. key ..", ".. value ..") ON DUPLICATE KEY UPDATE `value` = ".. value ..";")
    return true
end
 
Last edited:
database
SQL:
CREATE TABLE `global_storage`
(
    `key` INT UNSIGNED NOT NULL,
    `value` VARCHAR(255) NOT NULL DEFAULT '0',
    UNIQUE  (`key`)
) ENGINE = InnoDB;

replace those two functions in your compat.lua for these ones
Lua:
function getGlobalStorageValue(key)
    local result = db.getResult("SELECT `value` FROM `global_storage` WHERE `key` = " .. key .. ";")
    if result:getID() ~= -1 then
        local val = result:getDataString("value")
        result:free()
        return val
    end
    return -1
end

function setGlobalStorageValue(key, value)
    db.executeQuery("INSERT INTO `global_storage` (`key`, `value`) VALUES (".. key ..", ".. value ..") ON DUPLICATE KEY UPDATE `value` = ".. value ..";")
end

Thanks, this would work if I change the name of the function to like "getGlobalStorageValueDB(key)"? Or there is a proper code linked to C++?

-----------
 
Last edited:
it will still work
.
Thanks.

Tried it and now

I am getting an error

8f61c04e336543da88427ed27db30834.png


The line with the consult is
Code:
    if (getGlobalStorageValueDB(20204) < 200) then

Also having using the setGlobalStorageDB(key)

Have this error

dbb9d84d38f84b0582422f713631c58e.png
 
did you reload your global? what did you do? lol

Put everything was told to do so, restarted server and all.

The set global code was
Code:
setGlobalStorageValueDB(20204, 1)

As you can see on the images posted with the problem the error is "getResult" and "executeQuery"

----

Here are the codes:

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   
    if (item.itemid == 22390 and target.actionid == 30160) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'A short blow, yet the deafening sound lingers and swells. You hold your ears as the noise shatters part of the wall before you.')
        item:remove()
        local inqui_gold = player:getStorageValue(20203)
        player:setStorageValue(20203, inqui_gold+100)
        local horns_used = Game.getStorageValue(20204)
        setGlobalStorageValueDB(20204, horns_used+1)
    end
   
    return true
end

Code:
function onStartup()
   
    if (getGlobalStorageValueDB(20204) < 200) then
        Game.createMonster('Sight of Surrender', Position(33514, 32471, 7), false, true)
        Game.createMonster('Sight of Surrender', Position(33585, 32459, 7), false, true)
        Game.createMonster('Sight of Surrender', Position(33625, 32490, 7), false, true)
        Game.createMonster('Sight of Surrender', Position(33670, 32485, 7), false, true)
        Game.createMonster('Sight of Surrender', Position(33659, 32540, 7), false, true)
        Game.createMonster('Sight of Surrender', Position(33607, 32536, 7), false, true)
        Game.setStorageValue(20204,0)
       
        print("Sight of Surrender summoned!")
       
        return true
    end
end

Code:
function getGlobalStorageValueDB(key)
    local result = db.getResult("SELECT `value` FROM `global_storage` WHERE `key` = " .. key .. ";")
    if result:getID() ~= -1 then
        local val = result:getDataString("value")
        result:free()
        return val
    end
    return -1
end

function setGlobalStorageValueDB(key, value)
    db.executeQuery("INSERT INTO `global_storage` (`key`, `value`) VALUES (".. key ..", ".. value ..") ON DUPLICATE KEY UPDATE `value` = ".. value ..";")
end

I am using TFS 1.2
 
Code:
function getGlobalStorageValueDB(key)
    local resultId = db.storeQuery("SELECT `value` FROM `global_storage` WHERE `key` = " .. key)
    if resultId ~= false then
        local val = result.getString(resultId, "value")
        result.free(resultId)
        return val
    end
    return -1
end

function setGlobalStorageValueDB(key, value)
    db.query("INSERT INTO `global_storage` (`key`, `value`) VALUES (".. key ..", ".. value ..") ON DUPLICATE KEY UPDATE `value` = ".. value)
end
 
Code:
function getGlobalStorageValueDB(key)
    local resultId = db.storeQuery("SELECT `value` FROM `global_storage` WHERE `key` = " .. key)
    if resultId ~= false then
        local val = result.getString(resultId, "value")
        result.free(resultId)
        return val
    end
    return -1
end

function setGlobalStorageValueDB(key, value)
    db.query("INSERT INTO `global_storage` (`key`, `value`) VALUES (".. key ..", ".. value ..") ON DUPLICATE KEY UPDATE `value` = ".. value)
end

Thanks, it worked the setGlobalStorageDB function, but the getGlobalStorageValueDB is throwing this error which compares a string with a number.

da7a5f7f4370486793bd7e994ca71848.png
 
Thanks, it worked the setGlobalStorageDB function, but the getGlobalStorageValueDB is throwing this error which compares a string with a number.

da7a5f7f4370486793bd7e994ca71848.png
It's only logical as it returns a string and not an integer. If you only intend to store integers, you might as well change the data type for the field 'value' to INT, and replace getString with getNumber. Or simply cast it to a numeric value with tonumber.
 
I don't think he will understand all that.
database
Code:
CREATE TABLE `global_storage`
(
    `key` int(10) unsigned NOT NULL DEFAULT '0',
    `value` int(11) NOT NULL DEFAULT '0',
    PRIMARY KEY (`key`)
) ENGINE = InnoDB;

Code:
function getGlobalStorageValueDB(key)
    local query = db.storeQuery("SELECT `value` FROM `global_storage` WHERE `key` = " .. key .. ";")
    if query ~= false then
        local val = result.getDataInt(query, "value")
        result.free(query)
        return val
    end
    return -1
end

function setGlobalStorageValueDB(key, value)
    db.query("INSERT INTO `global_storage` (`key`, `value`) VALUES (".. key ..", ".. value ..") ON DUPLICATE KEY UPDATE `value` = ".. value ..";")
    return true
end
 
It's only logical as it returns a string and not an integer. If you only intend to store integers, you might as well change the data type for the field 'value' to INT, and replace getString with getNumber. Or simply cast it to a numeric value with tonumber.

Thanks it worked.

I don't think he will understand all that.

What a nice opinion, so constructive, so objetive, so directly. If you work your day a day like that, uff.... Good luck bro.
 
Status
Not open for further replies.
Back
Top