powergamers.lua

main 65 lines · 3.2 KB Raw
Alex Alex Commit Initial commit 01/10/2026 09:20
1-- getEternalStorage and setEternalStorage
2-- can be added to data/global.lua if you want to use eternal storage for another purpose than this.
3-- Regular TFS global storage values get reset every time server reboots. This does not.
4local function getEternalStorage(key, parser)
5 local value = result.getString(db.storeQuery("SELECT `value` FROM `znote_global_storage` WHERE `key` = ".. key .. ";"), "value")
6 if not value then
7 if parser then
8 return false
9 else
10 return -1
11 end
12 end
13 result.free(value)
14 return tonumber(value) or value
15end
16
17local function setEternalStorage(key, value)
18 if getEternalStorage(key, true) then
19 db.query("UPDATE `znote_global_storage` SET `value` = '".. value .. "' WHERE `key` = ".. key .. ";")
20 else
21 db.query("INSERT INTO `znote_global_storage` (`key`, `value`) VALUES (".. key ..", ".. value ..");")
22 end
23 return true
24end
25
26-- SQL Query to execute: --
27--[[
28ALTER TABLE `znote_players` ADD `exphist_lastexp` BIGINT NOT NULL DEFAULT '0',
29ADD `exphist1` BIGINT NOT NULL DEFAULT '0',
30ADD `exphist2` BIGINT NOT NULL DEFAULT '0',
31ADD `exphist3` BIGINT NOT NULL DEFAULT '0',
32ADD `exphist4` BIGINT NOT NULL DEFAULT '0',
33ADD `exphist5` BIGINT NOT NULL DEFAULT '0',
34ADD `exphist6` BIGINT NOT NULL DEFAULT '0',
35ADD `exphist7` BIGINT NOT NULL DEFAULT '0',
36ADD `onlinetimetoday` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
37ADD `onlinetime1` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
38ADD `onlinetime2` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
39ADD `onlinetime3` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
40ADD `onlinetime4` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
41ADD `onlinetime5` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
42ADD `onlinetime6` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
43ADD `onlinetime7` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
44ADD `onlinetimeall` INT UNSIGNED NOT NULL DEFAULT '0';
45]]--
46
47-- after that execute: --
48--[[
49UPDATE `znote_players` AS `z` INNER JOIN `players` AS `p` ON `p`.`id`=`z`.`player_id` SET `z`.`exphist_lastexp`=`p`.`experience`;
50]]--
51
52-- TFS 1.X (data/globalevents.xml)
53-- <!-- Power Gamers -->
54-- <globalevent name="PowerGamers" interval="60000" script="powergamers.lua"/>
55
56function onThink(interval, lastExecution, thinkInterval)
57 if tonumber(os.date("%d")) ~= getEternalStorage(23856) then
58 setEternalStorage(23856, (tonumber(os.date("%d"))))
59 db.query("UPDATE `znote_players` SET `onlinetime7`=`onlinetime6`, `onlinetime6`=`onlinetime5`, `onlinetime5`=`onlinetime4`, `onlinetime4`=`onlinetime3`, `onlinetime3`=`onlinetime2`, `onlinetime2`=`onlinetime1`, `onlinetime1`=`onlinetimetoday`, `onlinetimetoday`=0;")
60 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`;")
61 end
62 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`)")
63 return true
64end
65
Top