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

GlobalEvent [TFS 1.x] Power Gamers and Online Time for Gesior2012/MyAAC

Gesior.pl

Mega Noob&LOL 2012
Senator
Joined
Sep 18, 2007
Messages
2,968
Solutions
99
Reaction score
3,384
Location
Poland
GitHub
gesior
Global event to track online time and exp gained each day (last 7 days) for pages:

Tested on TFS 1.4. Should work on any TFS 1.x.
Script includes 'database global storage' for TFS 1.x from Solved - Global Storage + TFS 1.2 (https://otland.net/threads/global-storage-tfs-1-2.245524/#post-2388322)

1. In data/globalevents/globalevents.xml add:
XML:
<globalevent name="powergamers" interval="60000" script="powergamers.lua"/>
2. Create file data/globalevents/scripts/powergamers.lua:
Lua:
--[[
Requires database schema:

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

]]

local 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

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

function onThink()
    if (tonumber(os.date("%d")) ~= getGlobalStorageValueDB(23456)) then
        setGlobalStorageValueDB(23456, (tonumber(os.date("%d"))))
        db.query("UPDATE `players` SET `onlinetime7`=`onlinetime6`, `onlinetime6`=`onlinetime5`, `onlinetime5`=`onlinetime4`, `onlinetime4`=`onlinetime3`, `onlinetime3`=`onlinetime2`, `onlinetime2`=`onlinetime1`, `onlinetime1`=`onlinetimetoday`, `onlinetimetoday`=0;")
        db.query("UPDATE `players` SET `exphist7`=`exphist6`, `exphist6`=`exphist5`, `exphist5`=`exphist4`, `exphist4`=`exphist3`, `exphist3`=`exphist2`, `exphist2`=`exphist1`, `exphist1`=`experience`-`exphist_lastexp`, `exphist_lastexp`=`experience`;")
    end
    
    db.query("UPDATE `players` INNER JOIN `players_online` ON `players`.`id` = `players_online`.`player_id` SET `onlinetimetoday`=`onlinetimetoday`+60, `onlinetimeall`=`onlinetimeall`+60")

    return true
end
 

Similar threads

Back
Top