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

TFS 1.X+ Powergamer stats - Restart every 24h

alekzg

New Member
Joined
Jul 20, 2010
Messages
26
Reaction score
3
Hey,

I have a small problem with powergamers statistics. Statistics work properly and reset every 24 hours (at 0:00). The problem is that every time the server restarts, the statistics skip for one day. Does anyone know what to do to make the statistics reset and jump one day in the table only after the day's end? (and resetting the server should not affect the change in statistics?) i got tfs 1.2

globalevents.xml
XML:
    <globalevent name="history" interval="60" script="history.lua"/>

history.lua
Lua:
function onThink(interval, lastExecution)
    if (tonumber(os.date("%d")) ~= getGlobalStorageValue(23456)) then
        setGlobalStorageValue(23456, (tonumber(os.date("%d"))))
        db.query("UPDATE `players` SET `exphist7`=players.exphist6, `exphist6`=players.exphist5, `exphist5`=players.exphist4, `exphist4`=players.exphist3, `exphist3`=players.exphist2, `exphist2`=players.exphist1, `exphist1`=players.experience-players.exphist_lastexp, `exphist_lastexp`=players.experience;")
    end
    return TRUE
end

35957
 
Solution
Okay. I did as it was written and does not reset after restarting the server. I will test and come back with information if it works.

globalevents.xml
XML:
<globalevent name="history" interval="60" script="history.lua"/>

history.lua
Lua:
function onThink(interval, lastExecution)
    if (tonumber(os.date("%d")) ~= getGlobalStorageValueDB(23456)) then
        setGlobalStorageValueDB(23456, (tonumber(os.date("%d"))))
        db.query("UPDATE `players` SET `exphist7`=players.exphist6, `exphist6`=players.exphist5, `exphist5`=players.exphist4, `exphist4`=players.exphist3, `exphist3`=players.exphist2, `exphist2`=players.exphist1, `exphist1`=players.experience-players.exphist_lastexp, `exphist_lastexp`=players.experience;")
    end
    return TRUE
end

On compat.lua
Find this:
Lua:
function getGlobalStorageValue(key)
    return Game.getStorageValue(key) or -1
end

function setGlobalStorageValue(key, value)
    Game.setStorageValue(key, value)
    return true
end

Replace to:
Lua:
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

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

Similar threads

Back
Top