I need a script to register the uptime of users in my hub, something like that:
1 - toxic :: 0 Months, 1 Days, 3 Hours, 4 Min ( 1624 min ).
2 - NeverMind:: 0 Months, 1 Days, 2 Hours, 35 Min ( 1595 min ).
3 - Just :: 0 Months, 1 Days, 1 Hours, 52 Min ( 1552 min ).
4 - hey :: 0 Months, 1 Days, 1 Hours, 46 Min ( 1546 min ).
and with option to activate/desactivate this command to the users
Hi,
You want to register the time that they have been in the HUB if connected or all the time of the users in the HUB ??
Best regards, nErBoS
i only want the time they are conected in the hub.
-everytime the user conect the hub ...the script start the count....and save in a txt file the value,(because when this user connect to the hub again not to start the count from begining, but start from the last value)
- when the user is offline don`t count for the statist, but must show the uptime of the users that are off in the hub in that moment because the resault was saved in a txt. file.
The idea is to see when (we execute the command) who are the users that are more time conected in the hub even if some users are offline of the hub in that moment their uptime values must appear in results.
and also a option in the script to choose how many results we want to appear
uptimeusers=50 (in this case only appear the first 50 users with more uptime)
is something like that, that i want, i wope you understand.
sorry my bad English . thanks.
Hi,
Ok i will try out to do at night if i have time.
Best regards, nErBoS
aha I know that script :), and it is even on this board somewhere, but true I am also to lazy to search I coded it ages ago...
With a maximum of Mem usage cause we have enough of it, for max performance and min IO
--OnHub Time Logger V.1.65 by CHILL INC.
--thx to tezlo for the nice calculation from minutes to months, days, etc., and to Nagini, and to RabidWombat
--Create a "txt" Folder in the PtokaX scripts Folder, like this /scripts/txt/
--ChangeLog :
--5.12.03 Some Fixes.
--27.9.03 Added Serialisation.
--28.11.03 Rewriten Timer
-- Name this bot to what you want
bot="-= Hub Time =-"
--Name the commands to what you like
cmd1 = "+myhubtime"
cmd2 = "+allhubtime"
cmd3 = "+hubtime"
--This number stands for the maximum of displayed users, set it to what U like
Max = 40
--This number is for the timespan between each data saving in minutes.
Max1 = 30
--This number stands for time in minutes, a user must be online till he is saved to the file.
Max2 = 10
---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------
HTFolder = "txt"
File1 = "UserHubTime.txt"
sec = 1000
min = 60 * sec
var1 = 0
SHT = 0
HubUpTime = HubUpTime or 0
UserHubTime = {}
UserSessionTime = {}
dofile(HTFolder.."/"..File1)
function Main()
SetTimer(1 * min)
StartTimer()
foreach(UserHubTime, function(i,_)
if GetItemByName(i) then
UserSessionTime[i] = 0
end
end)
TopOnliners = GetUserMaxTime()
UpdateTime = "Updated: "..date("%d/%m/%y at %H:%M:%S")
end
function OnTimer()
SHT = SHT + 1
foreach(UserSessionTime, function(i,_)
if GetItemByName(i) then
UserSessionTime[i] = UserSessionTime[i] + 1
end
end)
var1 = var1 + 1
if var1 >= Max1 then
foreach(UserSessionTime, function (a,_)
UserHubTime[a] = UserHubTime[a] + UserSessionTime[a]
UserSessionTime[a] = 0
if not GetItemByName(a) then
UserSessionTime[a] = nil
end
end)
HubUpTime = HubUpTime + SHT
WriteFile(UserHubTime, "UserHubTime", File1)
var1 = 0
SHT = 0
TopOnliners = GetUserMaxTime()
UpdateTime = "Updated: "..date("%d/%m/%y at %H:%M:%S")
end
end
function OnExit()
foreach(UserSessionTime, function (a,_)
UserHubTime[a] = UserHubTime[a] + UserSessionTime[a]
UserSessionTime[a] = 0
if not GetItemByName(a) then
UserSessionTime[a] = nil
end
end)
HubUpTime = HubUpTime + SHT
WriteFile(UserHubTime, "UserHubTime", File1)
end
function NewUserConnected(curUser)
if UserHubTime[curUser.sName]==nil then
UserHubTime[curUser.sName]=0
end
UserSessionTime[curUser.sName]=0
end
OpConnected = NewUserConnected
function DataArrival(curUser,data)
if (strsub(data, 1, 1) == "<") then
data = strsub(data,1,strlen(data)-1)
local _,_,cmd = strfind( data, "%b<>%s+(%S+)" )
if (cmd and strlower(cmd) == strlower(cmd1) and UserHubTime[curUser.sName]) then
local tmp = UserHubTime[curUser.sName] + UserSessionTime[curUser.sName]
local months, days, hours, minutes = floor(tmp/43200), floor(mod(tmp/1440, 30)), floor(mod(tmp/60, 24)), floor(mod(tmp/1, 60))
curUser:SendData(bot, "You have been online : "..months.." months, "..days.." days, "..hours.." hours, "..minutes.." minutes ( "..tmp.." min ). That is "..format("%.2f",tmp/HubUpTime*100).." % of the total HubUpTime.")
return 1
elseif (cmd and strlower(cmd) == strlower(cmd2)) then
local tmp = HubUpTime + SHT
local months, days, hours, minutes = floor(tmp/43200), floor(mod(tmp/1440, 30)), floor(mod(tmp/60, 24)), floor(mod(tmp/1, 60))
curUser:SendData(bot, " -= The Top "..Max.." Campers, "..UpdateTime.." =-\r\n\r\n"..
"\tHub's Online Time : "..months.." months, "..days.." days, "..hours.." hours, "..minutes.." minutes ( "..tmp.." min ).\r\n"..
TopOnliners.."\r\n")
return 1
elseif (cmd and strlower(cmd) == strlower(cmd3)) then
local tmp = HubUpTime + SHT
local months, days, hours, minutes = floor(tmp/43200), floor(mod(tmp/1440, 30)), floor(mod(tmp/60, 24)), floor(mod(tmp/1, 60))
curUser:SendData(bot, "The hub has now been online : "..months.." months, "..days.." days, "..hours.." hours, "..minutes.." minutes ( "..tmp.." min ).")
return 1
end
end
end
----------------------------------------------------------------------------------------------------------
function WriteFile(table, tablename, file)
local handle = openfile(HTFolder.."/"..file, "w")
write(handle, tablename.." = {\n" )
for key, value in table do
if value >= Max2 then
write(handle, "\t"..format("[%q]",key).." = "..value..",\n")
end
end
write(handle, "}");
write(handle,"\r\nHubUpTime = "..HubUpTime)
closefile(handle)
end
----------------------------------------------------------------------------------------------------------
function GetUserMaxTime()
local TCopy={}
for i,v in UserHubTime do
tinsert( TCopy, { tonumber(v),i } )
end
sort( TCopy, function(a, b) return (a[1] > b[1]) end)
local msg ="\r\n"
for i = 1,Max do
if TCopy[i] then
local months, days, hours, minutes = floor(TCopy[i][1]/43200), floor(mod(TCopy[i][1]/1440, 30)), floor(mod(TCopy[i][1]/60, 24)), floor(mod(TCopy[i][1]/1, 60))
msg = msg.."\t# "..i.."\t - "..TCopy[i][2].." :: "..months.." Months, "..days.." Days, "..hours.." Hours, "..minutes.." Min ( "..TCopy[i][1].." min ).\r\n"
end
end
local TCopy={}
return msg
end
----------------------------------------------------------------------------------------------------------
Yes chill , is this that I looking for.
After instal you script i detect one problem, is if i restar the script in hub i loose ( minutes) in usersuptime.
[22:13:00] <-= Hub Time =-> -= The Top 100 Campers =-
# 1 - TOXIC :: 0 Months, 0 Days, 1 Hours, 29 Min ( 89 min ).
[22:13:11] Scripts are being restarted !
[22:13:21] <-= Hub Time =-> -= The Top 100 Campers =-
# 1 - TOXIC :: 0 Months, 0 Days, 0 Hours, 14 Min ( 14 min ).
so, i supose this hapen because during some minutes the values don`t be saved, and to change that i went to the script and change this:
--This number stands for the maximum of displayed users, set it to what U like
Max = 100
--This number is for the timespan between each data saving in minutes.
Max1 = 1
--This number stands for time in minutes, a user must be online till he is saved to the file.
Max2 = 1
but didn`t solve the problem .
my question is what i need to change in the script to save the values minute after minute?
thanks.
Yepp TOXIC these should be the correct settings,
actually you only need to do
Max2 = 1 or = 0,
cause Max1 = 1 writes to disk every minute.
Only bug I found is better change
HubUpTime = HubUpTime or 0
to
HubUpTime = HubUpTime or 1
I really don't know where the script is going wrong,
keep trying mate.
i find this script .....
-- A Kick-Counter By VidFamne, with lot of help by tezlo's code
-- Just type +TopKicker in main, and you get the best Kickers in your staff :-)
-- Added save- and load-function, with help of DirtyFinger's code and Steve Dekorte's code
-- Added a OP-Chat-Counter by VidFamne ( 23.05.2003 ) Just type +TopChatter in main.
-- Guibs added Top-Banner, thanx :)
-- Added TopOnliner (exprimental) By VidFamne ( 08.06.2003 ) Just type +TopOnliner in main.
-- and get the current TopOnliner in your Hub. :)
-- Added MyTime :) Just type +MyTime and get your current time spent in hub ( 09.06.2003 ) by VidFamne
-- Optimized a bit ( 09.06.2003 ) by VidFamne
-- Added Modified Julian day(minute) number function. Create 2 textfiles called Kickers.txt and Timer.txt
-- and put them in the same folder as your script.
-- Optimized a bit and add autosave and autoload, by VidFamne ( 21.06.2003 )
Tlist = {["Onliners"]={["login"]={}, ["Time"]={}}}
list = {["Kickers"]={}, ["Chatters"]={}, ["Banners"]={}}
nr = 80 --<-------Numbers of "Toppers" You want to show
limit = 15 --<-------Limitter for Time-counter, to filter away "short-time" visitors.Set in minutes.
Timefile = "Timer.txt"
Kickerfile = "Kickers.txt"
function Main()
Tlist = loadTableFromFile(Timefile)
list=loadTableFromFile(Kickerfile)
end
function DataArrival(curUser, sData)
if ( strsub(sData, 1, 5) == "$Kick" ) then
list.Kickers[curUser.sName] = list.Kickers[curUser.sName] or 0
list.Kickers[curUser.sName] = list.Kickers[curUser.sName]+1
saveTableToFile(Kickerfile,list)
elseif( strsub(sData, 1, 1) == "<" ) then
list.Chatters[curUser.sName] = list.Chatters[curUser.sName] or 0
list.Chatters[curUser.sName] = list.Chatters[curUser.sName]+1
saveTableToFile(Kickerfile,list)
end
if( strsub(sData, 1, 1) == "<" ) then
sData=strsub(sData,1,strlen(sData)-1)
s,e,cmd = strfind( sData, "%b<>%s+(%S+)" )
if (cmd=="!nickban") or (cmd=="!ban") then
list.Banners[curUser.sName] = list.Banners[curUser.sName] or 0
list.Banners[curUser.sName] = list.Banners[curUser.sName]+1
saveTableToFile(Kickerfile,list)
elseif (cmd=="+TopKicker") and (curUser.bOperator) then
local curtime = date()
SendToNick(curUser.sName,"\r\n\tTOP KICKER\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")
local Index = sorting(list.Kickers)
for i = 1, Index.n do
local key = Index
SendToNick(curUser.sName, "**** "..i.." [ "..key.." ]\t\t=>\t"..list.Kickers[key])
SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------")
if i>=nr then break end
end
return 1
elseif (cmd=="+TopChatter") then
local curtime = date()
SendToNick(curUser.sName,"\r\n\tTOP CHATTER\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")
local Index = sorting(list.Chatters)
for i = 1, Index.n do
local key = Index
SendToNick(curUser.sName, "**** "..i.." [ "..key.." ]\t\t=>\t"..list.Chatters[key])
SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------")
if i>=nr then break end
end
return 1
elseif (cmd=="+TopBanner") and (curUser.bOperator) then
local curtime = date()
SendToNick(curUser.sName,"\r\n\tTOP BANNER\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")
local Index = sorting(list.Banners)
for i = 1, Index.n do
local key = Index
SendToNick(curUser.sName, "**** "..i.." [ "..key.." ]\t\t=>\t"..list.Banners[key])
SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------")
if i>=nr then break end
end
return 1
elseif (cmd=="+TopOnliner") then
local curtime = date()
local now = Calc(Tlist.Onliners.login, Tlist.Onliners.Time)
SendToNick(curUser.sName,"\r\n\tTOP ONLINER\t\t\t\t("..curtime..")\r\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n")
local Index = sorting(now)
for i = 1, Index.n do
local key = Index
local days, hrs, min = Timemess(now[key])
SendToNick(curUser.sName, "**** "..i.." [ "..key.." ] has been here for; "..days.." days, "..hrs.." hours and "..min.." minutes")
SendToNick(curUser.sName,"-----------------------------------------------------------------------------------------------------------------------------------------------")
if i>=nr then break end
end
return 1
elseif (cmd=="+MyTime") then
local curtime = date()
usrtime = MyTime(Tlist.Onliners.login, Tlist.Onliners.Time, curUser)
local days, hrs, min = Timemess(usrtime)
SendToNick(curUser.sName,"*** You have been here for "..days.." days, "..hrs.." hours and "..min.." minutes in this hub \t( "..curtime.." )" )
return 1
end
end
end
function sorting(table)
local index = {n=0}
foreach(table, function(key, value) tinsert(%index, key) end)
local func = function(a, b) return %table[a] > %table end
sort(index, func) return index
end
function loadTableFromFile(file)
readfrom(file)
local aString = read("*all")
return unpickle(aString)
end
function saveTableToFile(file,table)
local aString = pickle(table)
writeto(file)
write(aString)
writeto()
end
function NewUserConnected(curUser)
local minute = Jmn(a)
Tlist.Onliners.login[curUser.sName] = Tlist.Onliners.login[curUser.sName] or 0
Tlist.Onliners.login[curUser.sName] = tonumber(minute)
Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0
Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])
saveTableToFile(Timefile,Tlist)
end
function UserDisconnected(curUser)
local minute = Jmn(a)
if Tlist.Onliners.login[curUser.sName] == nil then
Tlist.Onliners.Time[curUser.sName] = nil
else
Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0
Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])
if Tlist.Onliners.Time[curUser.sName] <= limit then
Tlist.Onliners.Time[curUser.sName] = nil
Tlist.Onliners.login[curUser.sName] = nil
else
Tlist.Onliners.login[curUser.sName] = nil
saveTableToFile(Timefile,Tlist)
end
end
end
function OpConnected(curUser)
local minute = Jmn(a)
Tlist.Onliners.login[curUser.sName] = Tlist.Onliners.login[curUser.sName] or 0
Tlist.Onliners.login[curUser.sName] = tonumber(minute)
Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0
Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])
saveTableToFile(Timefile,Tlist)
end
function OpDisconnected(curUser)
local minute = Jmn(a)
if Tlist.Onliners.login[curUser.sName] == nil then
Tlist.Onliners.Time[curUser.sName] = nil
else
Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] or 0
Tlist.Onliners.Time[curUser.sName] = Tlist.Onliners.Time[curUser.sName] + tonumber(minute) - tonumber(Tlist.Onliners.login[curUser.sName])
if Tlist.Onliners.Time[curUser.sName] <= limit then
Tlist.Onliners.Time[curUser.sName] = nil
Tlist.Onliners.login[curUser.sName] = nil
else
Tlist.Onliners.login[curUser.sName] = nil
saveTableToFile(Timefile,Tlist)
end
end
end
function Calc(a, c)
local indeX = {}
foreach(a, function(key,value)
for key, value in %a do
for key2, value2 in %c do
if (key == key2) then
local minute = Jmn()
local diff = tonumber(value2) + minute - tonumber(value)
rawset(%indeX, key, diff) end end end end)
return indeX
end
function MyTime(a, c, curUser)
local minute = Jmn()
local onTime =""
for key, value in a do
for key2, value2 in c do
if key == curUser.sName
and key2 == curUser.sName then
onTime = tonumber(value2) + minute - tonumber(value)
return onTime
end
end
end
end
function Jmn() --(Modified Julian "minute" number. This restricts the algorithm to 1900 Mar 01 until 2100 Feb 28)
D = tonumber(date("%d"))
H = tonumber(date("%H"))
minutE = tonumber(date("%M"))
Y = tonumber(date("%Y"))
M = tonumber(date("%m"))
if M <= 2 then
M = M + 12
Y=Y-1
end
mn = 1440*(floor(Y*365,25) + floor((M+1)*30,6) + D -428) + H*60 + minutE
return mn
end
function Timemess(T)
local min = tonumber(T)
local days = floor(min/1440)
local hrs = floor((min-(days*1440))/60)
min = floor(min-(days*1440)-(hrs*60))
return days, hrs, min
end
----------------------------------------------
-- Pickle.lua
-- An table serialization utility for lua
-- Steve Dekorte, Apr 2000
-- Freeware
----------------------------------------------
function pickle(t)
return Pickle:clone():pickle_(t)
end
Pickle = {
clone = function (t) local nt={}; for i, v in t do nt=v end return nt end
}
function Pickle:pickle_(root)
if type(root) ~= "table" then
error("can only pickle tables, not ".. type(root).."s")
end
self._tableToRef = {}
self._refToTable = {}
local savecount = 0
self:ref_(root)
local s = ""
while getn(self._refToTable) > savecount do
savecount = savecount + 1
local t = self._refToTable[savecount]
s = s.."{\n"
for i, v in t do
s = format("%s[%s]=%s,\n", s, self:value_(i), self:value_(v))
end
s = s.."},\n"
end
return format("{%s}", s)
end
function Pickle:value_(v)
local vtype = type(v)
if vtype == "string" then return format("%q", v)
elseif vtype == "number" then return v
elseif vtype == "table" then return "{"..self:ref_(v).."}"
else --error("pickle a "..type(v).." is not supported")
end
end
function Pickle:ref_(t)
local ref = self._tableToRef[t]
if not ref then
if t == self then error("can't pickle the pickle class") end
tinsert(self._refToTable, t)
ref = getn(self._refToTable)
self._tableToRef[t] = ref
end
return ref
end
----------------------------------------------
-- unpickle
----------------------------------------------
function unpickle(s)
if type(s) ~= "string" then
error("can't unpickle a "..type(s)..", only strings")
end
local tables = dostring("return "..s)
for tnum = 1, getn(tables) do
local t = tables[tnum]
local tcopy = {}; for i, v in t do tcopy = v end
for i, v in tcopy do
local ni, nv
if type(i) == "table" then ni = tables[i[1]] else ni = i end
if type(v) == "table" then nv = tables[v[1]] else nv = v end
t[ni] = nv
end
end
return tables[1]
end
but give this errors:
stack traceback:
1: function `write' [C]
2: function `Serialize' at line 108 [file `...rograms net\Ptokax\scripts\stats.lua']
3: function `WriteTable' at line 102 [file `...rograms net\Ptokaxscripts\stats.lua']
4: function `OnTimer' at line 39 [file `...rograms net\Ptokax\scripts\stats.lua']
Syntax error: bad argument #1 to `write' (string expected, got nil)
stack traceback:
1: function `write' [C]
2: function `Serialize' at line 108 [file `...rograms net\Ptokax\scripts\stats.lua']
3: function `WriteTable' at line 102 [file `...rograms net\Ptokax\scripts\stats.lua']
4: function `OnTimer' at line 39 [file `...rograms net\Ptokax\scripts\stats.lua']
Syntax error: bad argument #1 to `write' (string expected, got nil)
stack traceback:
1: function `write' [C]
2: function `Serialize' at line 108 [file `...rograms net\Ptokax\scripts\stats.lua']
3: function `WriteTable' at line 102 [file `...rograms net\Ptokax\scripts\stats.lua']
4: function `OnTimer' at line 39 [file `...rograms net\Ptokax\scripts\stats.lua']
Its possible to fix this?