Znote / ZnoteAAC

Developement repository for the Znote AAC project. A website portal to represent and manage your Open Tibia server.
MIT License
145 stars 127 forks source link

Powergame script not working on 1.x? #481

Closed EPuncker closed 2 years ago

EPuncker commented 3 years ago

Can someone confirm if the znote_players table is being populated with information from this script? It doesn't seem to work for me

the table is always empty

Znote commented 3 years ago

Try this, revscriptsys:

local powergamers = GlobalEvent("powergamers")
powergamers:interval(60 * 1000) -- 60 seconds

function powergamers.onThink(...)
    if tonumber(os.date("%d")) ~= getEternalStorage(23856) then
        setEternalStorage(23856, (tonumber(os.date("%d"))))
        db.query([[
            UPDATE `znote_players` 
            SET 
                `onlinetime7`=`onlinetime6`, 
                `onlinetime6`=`onlinetime5`, 
                `onlinetime5`=`onlinetime4`, 
                `onlinetime4`=`onlinetime3`, 
                `onlinetime3`=`onlinetime2`, 
                `onlinetime2`=`onlinetime1`, 
                `onlinetime1`=`onlinetimetoday`, 
                `onlinetimetoday`=0;
        ]])
        db.query([[
            UPDATE `znote_players` `z` 
            INNER JOIN `players` `p` 
                ON `p`.`id`=`z`.`player_id` 
            SET `z`.`exphist7`=`z`.`exphist6`, 
            `z`.`exphist6`=`z`.`exphist5`, 
            `z`.`exphist5`=`z`.`exphist4`, 
            `z`.`exphist4`=`z`.`exphist3`, 
            `z`.`exphist3`=`z`.`exphist2`, 
            `z`.`exphist2`=`z`.`exphist1`, 
            `z`.`exphist1`=`p`.`experience` - `z`.`exphist_lastexp`, 
            `z`.`exphist_lastexp`=`p`.`experience`;
        ]])
    end
    db.query([[
        UPDATE `znote_players` 
        SET 
            `onlinetimetoday` = `onlinetimetoday` + 60, 
            `onlinetimeall` = `onlinetimeall` + 60 
        WHERE `player_id` IN (
            SELECT `player_id` 
            FROM `players_online` 
            WHERE `players_online`.`player_id` = `znote_players`.`player_id`
        )
    ]])
    return true
end

powergamers:register()
BoozieII commented 3 years ago

I get this error in my console when i try this script:

2021-18-08 17:16:34.339] [error] Lua script error: /var/www/tibiaoceana/data/scripts/globalevents/powergamers.lua:callback [2021-18-08 17:16:34.339] [error] ...ww/tibiaoceana/data/scripts/globalevents/powergamers.lua:5: attempt to call global 'getEternalStorage' (a nil value) stack traceback: [C]: in function 'getEternalStorage' ...ww/tibiaoceana/data/scripts/globalevents/powergamers.lua:5: in function <...ww/tibiaoceana/data/scripts/globalevents/powergamers.lua:4> [2021-18-08 17:16:34.339] [error] [GlobalEvents::think] - Failed to execute event: powergamers

Do i need to define getEternalStorage(23856) somewhere??

EPuncker commented 3 years ago

I get this error in my console when i try this script:

2021-18-08 17:16:34.339] [error] Lua script error: /var/www/tibiaoceana/data/scripts/globalevents/powergamers.lua:callback [2021-18-08 17:16:34.339] [error] ...ww/tibiaoceana/data/scripts/globalevents/powergamers.lua:5: attempt to call global 'getEternalStorage' (a nil value) stack traceback: [C]: in function 'getEternalStorage' ...ww/tibiaoceana/data/scripts/globalevents/powergamers.lua:5: in function <...ww/tibiaoceana/data/scripts/globalevents/powergamers.lua:4> [2021-18-08 17:16:34.339] [error] [GlobalEvents::think] - Failed to execute event: powergamers

Do i need to define getEternalStorage(23856) somewhere??

you need these functions:

local function getEternalStorage(key, parser)
    local value = result.getString(db.storeQuery("SELECT `value` FROM `znote_global_storage` WHERE `key` = ".. key .. ";"), "value")
    if not value then
        if parser then
            return false
        else
            return -1
        end
    end
    result.free(value)
    return tonumber(value) or value
end

local function setEternalStorage(key, value)
    if getEternalStorage(key, true) then
        db.query("UPDATE `znote_global_storage` SET `value` = '".. value .. "' WHERE `key` = ".. key .. ";")
    else
        db.query("INSERT INTO `znote_global_storage` (`key`, `value`) VALUES (".. key ..", ".. value ..");")
    end
    return true
end
Znote commented 2 years ago

I have now created a revscriptsys that installs and maintains a player_history table, and rewritten powergamers.php: https://github.com/Znote/ZnoteAAC/commit/fb6c391925b47793ad065b670f2e2d47edc94d8b and made a top5 powergamers widget.

This is exclusively for TFS 1.x and currently only on the v2 branch https://github.com/Znote/ZnoteAAC/tree/v2

https://acidsot.com/powergamers.php image

The player_history table has much bigger potential though. It tracks every player session, and skill progression (not just level/experience).