PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: frankyk on 13 March, 2004, 05:35:55

Title: User online time...need adjustment
Post by: frankyk on 13 March, 2004, 05:35:55
The following code displays online time by the quarter hour, is there anyway to adjust it so it shows total time by the minute instead of 15 minutes?

Top Ten Alltime          Alltime hub uptime: 1 hours 45 minutes
 _____________________________________________________________________________
/                                
   <1.>   [M]TritonTide
               100.00%   1 hours 45 minutes


Notice how it goes by quarter minute, what would I have to do to change it to something like:

   <1.>   [M]TritonTide
               98.00%   1 hours 37 minutes

or something like that?  The code is as follows:


--
-- USER UPTIME SCRIPT v1.00
-- By Pur

--   Commands
--   
--   !mystats         - shows your own stats
--   !show       - show other ppl stats
--   !top10alltime         - top 10 alltime user online
--   !top50alltime         - top 50 alltime user online
--   !top100alltime         - top 100 alltime user online
--   !top10now         - top 10 of users online atm
--   !top50now         - top 50 of users online atm
--   !top100now         - top 100 of users online atm
--   !help            - shows the commands
--


function Main()
   dofile("english.lan")         -- Change here your language file
   
   dofile("cmd.dat")         -- contains the commands edit this file too
                  -- change them
   
   dofile("hubs.dat")         -- Alltime hub uptime      
   dofile("table.dat")         -- Contains the uptime of every user

   msecs = 1000            -- Some time variables
   secs = 1*msecs
   min = secs * 60
   quarter = min * 15

   Bot = "Channel Bot"            -- Botname can be changed here   
   frmHub:RegBot(Bot)         

   tablenow={}            -- Table containing the uptime of all users
                  -- since last login

   hubs["now"] = 1            -- Set hub uptime too 1
      
   SetTimer(min)            -- Sets the timer (setting on quarter)
                  -- not wise the change timer settings
   StartTimer()            -- Starts the timer
end

function NewUserConnected(curUser)
   if table[curUser.sName] == nil then
      table[curUser.sName] = 1   
   end
   if tablenow[curUser.sName] == nil then
      tablenow[curUser.sName] = 1
   end
end

function UserDisconnected(curUser)
   tablenow[curUser.sName] = nil
   collectgarbage()
   flush()
end

OpDisconnected = UserDisconnected
OpConnected = NewUserConnected

function OnTimer()

   hubs["uptime"] = hubs["uptime"]+1
   hubs["now"] = hubs["now"]+1
   WriteFile(hubs,"hubs","hubs.dat")

   if tablenow == nil then
   else
      for i,v in tablenow do
         tablenow = tablenow + 1
      end
   end

   for i,v in table do
      ret = inhub(table)
      if (ret == true) then
         table = table + 1
      end
   end
   WriteFile(table,"table","table.dat")
end

function DataArrival(curUser,data)
   if strsub(data, 1, 1) == "<" then
      data=strsub(data,1,strlen(data)-1)
      local s,e,cmdr = strfind(data,"%b<>%s+(%S+)")
      _,_,arg = strfind(data,"%b<>%s+%S+%s+(%S+)")
      
      if (cmdr == cmd[1]) then
         curUser:SendPM(Bot,showstats(curUser.sName,1))
      elseif (cmdr == cmd[2]) then
         curUser:SendPM(Bot,showtable(tablenow,10,"\r\n"..lan[13].."\t\t\t Hub uptime: "..rs(hubs["now"]-1),"now"))
      elseif (cmdr == cmd[3]) then
         curUser:SendPM(Bot,showstats(arg,0))
      elseif (cmdr == cmd[4]) then      
         curUser:SendPM(Bot,showtable(table,10,"\r\n"..lan[12].."\t\t\t Alltime hub uptime: "..rs(hubs["uptime"]-1),"uptime"))
      elseif (cmdr == cmd[5]) then
         curUser:SendPM(Bot,showtable(table,50,"\r\n"..lan[12].."\t\t\t Alltime hub uptime: "..rs(hubs["uptime"]-1),"uptime"))
      elseif (cmdr == cmd[6]) then
         curUser:SendPM(Bot,showtable(table,100,"\r\n"..lan[12].."\t\t\t Alltime hub uptime: "..rs(hubs["uptime"]-1),"uptime"))
      elseif (cmdr == cmd[7]) then
         curUser:SendPM(Bot,showtable(tablenow,50,"\r\n"..lan[13].."\t\t\t Hub uptime: "..rs(hubs["now"]-1),"now"))
      elseif (cmdr == cmd[8]) then
         curUser:SendPM(Bot,showtable(tablenow,100,"\r\n"..lan[13].."\t\t\t Hub uptime: "..rs(hubs["now"]-1),"now"))
      elseif (cmdr == cmd[9]) then
         output = "\r\n Commands \r\n"
         for i,v in cmd do
            output = output.."\t\t"..cmd.."\r\n"
         end
         curUser:SendPM("Help",output)
      end
   
   end     
end
function procent(num,field)
   if (hubs[field]) then
      oneprocent=(hubs[field]-1) / 100      
      ret = num / oneprocent
      ret= format("%0.2f",ret)      
   end
   return ret
end


function inhub(user)
   if tablenow[user] and tablenow[user] ~= 1 then
      ret = true
   else
      ret = false
   end
   return ret
end

function rs(num)
   out = ""

   years = mod(num,34944)
   years = (num - years)/34944
   if ( years > 0 ) then
      out = out..years..lan[1]
      num = num - (years * 34944)
   end

   weeks = mod(num,672)
   weeks = (num - weeks)/672
   if ( weeks > 0 ) then
      out = out..weeks..lan[2]
      num = num - (weeks * 672)
   end

   days = mod(num,96)
   days = (num - days) / 96
   if ( days > 0 ) then
      out = out..days..lan[3]
      num = num - (days * 96)
   end

   hours = mod(num, 4)
   hours = (num - hours) /4
   if ( hours > 0) then
      out = out..hours..lan[4]
      num = num - ( hours * 4)
   end

   if (num > 0) then
      quarters = num
      out = out..(quarters*15)..lan[5]
   end
   

   return ""..out
end


-- Screens


headerT = " _____________________________________________________________________________".."\r\n"
headerT = headerT.."/                                ".."\r\n"

footerT = " _____________________________________________________________________________/".."\r\n"

function showtable(showtable,tonum,title,field)
   output = "\r\n"..title.."\r\n"
   output = output..headerT

   local Index = sorting(showtable)
   for i = 1, Index.n do
      local key = Index
      if showtable[key] ~= 0 then
         output = output.."\t".."<"..i..".>".."\t"..key.."\r\n"                  
         output = output.."\t\t\t\t\t"..procent(showtable[key]-1,field).."%\t"..rs(showtable[key]-1).."\r\n"            
      end
      if (i >= tonum) then
         break
      end
   end

   output = output..footerT
   return output
end

function showstats(user)
      
   output = "\r\n".."\r\n"..lan[6].."\r\n"
   output = output..headerT      
         
   output = output.."\t"..lan[7]..user.."\r\n"  
         
   
   if (table[user] == nil) then   
      output = output.."\t"..lan[8]..lan[10].."\r\n"
   elseif (table[user]==1) then      
      output = output.."\t"..lan[8]..lan[11].."\r\n"
   else         
      output = output.."\t"..lan[8]..rs(table[user]-1).."\r\n"
   end

   if (tablenow[user] == nil) then   
      output = output.."\t"..lan[9]..lan[10].."\r\n"
   elseif (tablenow[user]==1) then      
      output = output.."\t"..lan[9]..lan[11].."\r\n"   
   else         
      output = output.."\t"..lan[9]..rs(tablenow[user]-1).."\r\n"
   end
      
   output = output..footerT
   return output
end

-- Table functions

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 Serialize(tTable,sTableName,hFile,sTab)
   sTab = sTab or "";
   write(hFile,sTab..sTableName.." = {\n");
   for key,value in tTable do
      local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);
      if(type(value) == "table") then
         Serialize(value,sKey,hFile,sTab.."\t");
      else
         local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
         write(hFile,sTab.."\t"..sKey.." = "..sValue);
      end
      write(hFile,",\n");
   end
   write(hFile,sTab.."}");
end

function WriteFile(table,tablename,file)
   local handle = openfile(file,"w")
   Serialize(table,tablename,handle)
     closefile(handle)
end
Title:
Post by: nErBoS on 13 March, 2004, 17:57:03
Hi,

Try this one..

http://board.univ-angers.fr/thread.php?threadid=1503&boardid=12&styleid=1&sid=cf331b82680f0e1a0a2c5e1f45c74b86

Best regards, nErBoS
Title:
Post by: pHaTTy on 13 March, 2004, 18:09:14
QuoteOriginally posted by nErBoS
Hi,

Try this one..

http://board.univ-angers.fr/thread.php?threadid=1503&boardid=12&styleid=1&sid=cf331b82680f0e1a0a2c5e1f45c74b86

Best regards, nErBoS


???  ?(
Title:
Post by: nErBoS on 13 March, 2004, 18:26:37
Hi,

Baaaa bad reading by me sorry :P

Best regards, nErBoS