• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

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

Gesior.pl

Mega Noob&LOL 2012
Senator
Joined
Sep 18, 2007
Messages
3,333
Solutions
120
Reaction score
4,130
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
 
I'm having some errors in myaac...


Undefined index: type: This error occurs because the $_REQUEST['type'] variable is not defined in some requests. To resolve this, you can define a default value for type if it is not present in the request.

Undefined variable: number_of_rows: This error occurs because the variable $number_of_rows was not initialized before being used. You must initialize it to a value, such as 0.

Uncaught Error: Call to undefined method Player::isPlayerOnline(): This error occurs because the isPlayerOnline() method does not exist in the Player class. You must ensure that this function is defined in the Player class or remove it if it is not needed.
 
I'm having some errors in myaac...


Undefined index: type: This error occurs because the $_REQUEST['type'] variable is not defined in some requests. To resolve this, you can define a default value for type if it is not present in the request.

Undefined variable: number_of_rows: This error occurs because the variable $number_of_rows was not initialized before being used. You must initialize it to a value, such as 0.

Uncaught Error: Call to undefined method Player::isPlayerOnline(): This error occurs because the isPlayerOnline() method does not exist in the Player class. You must ensure that this function is defined in the Player class or remove it if it is not needed.


Has anyone solved this?
 
I converted this script for myaac, if anyone needs.

I did only absolutely minimum so it only works, don't expect any code refactor.

system/pages/onlinetime.php


system/pages/powergamers.php

You still need to install SQL columns + Lua script, so read the first post how to do it.
 
Back
Top