another script i'd like to have converted to lua 5
 

another script i'd like to have converted to lua 5

Started by slick, 19 September, 2005, 02:56:58

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

slick

hi ummmm I hope I don't annoy anybody but i have  a few scripts I'd like converted to lua 5 here it is





--OnHub Time Logger V.1.63
--27.9.03 by c h i l l e r
--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 :
--27.9.03 Added Serialisation.

-- Name this bot to what you want
bot="-= Hub Time recorder =-"

--Name the commands to what you like
cmd1 = "+up"
cmd2 = "+topusers"
cmd3 = "+totalup"

--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 = 30
--This number stands for time in minutes, a user must be online till he is saved to the file.
Max2 = 10
---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------

File1 = "UserHubTime.txt"

sec = 1000
min = 60 * sec

var1 = 0

assert(dofile("txt/"..File1), "txt/"..File1.." for HubTime-V.163.lua not found")

function Main()
   SetTimer(1 * min)
   StartTimer()
end

function OnTimer()
   for i,v in UserHubTime do
      if GetItemByName(i) or i=="HubUpTime" then
         v=v+1
         UserHubTime=v
      end
   end
   var1 = var1 + 1
   if var1 == Max1 then
      WriteFile(UserHubTime, "UserHubTime", File1)
      var1 = 0
   end
end

function NewUserConnected(curUser)
   if UserHubTime[curUser.sName]==nil then
      UserHubTime[curUser.sName]=0
   end
end

function OpConnected(curUser)
   if UserHubTime[curUser.sName]==nil then
      UserHubTime[curUser.sName]=0
   end
end

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]
         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/UserHubTime["HubUpTime"]*100).." % of the total HubUpTime.")
         return 1

      elseif (cmd and strlower(cmd) == strlower(cmd2)) then
         curUser:SendData(bot, "   -= The Top "..Max.." Campers =-\r\n"..
         GetUserMaxTime().."\r\n")
         return 1

      elseif (cmd and strlower(cmd) == strlower(cmd3)) then
         local tmp = UserHubTime["HubUpTime"]
         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("txt/"..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, "}");
     closefile(handle)
end
----------------------------------------------------------------------------------------------------------
function GetUserMaxTime()
   local TCopy={}
   for i,v in UserHubTime do
      if i~="HubUpTime" then
         tinsert( TCopy, { tonumber(v),i } )
      end
   end
   sort( TCopy, function(a, b) return (a[1] > b[1]) end)
   local msg ="\r\n"
   for i = 1,Max do
      if TCopy then
         local months, days, hours, minutes = floor(TCopy[1]/43200), floor(mod(TCopy[1]/1440, 30)), floor(mod(TCopy[1]/60, 24)), floor(mod(TCopy[1]/1, 60))
         msg = msg.."\t\t# "..i.."  -  "..TCopy[2].."\t::\t"..months.." Months, "..days.." Days, "..hours.." Hours, "..minutes.." Min ( "..TCopy[1].." min ).\r\n"
      end
   end
   local TCopy={}
   return msg
end
----------------------------------------------------------------------------------------------------------


t/y in advance


slick

slick

t/y very much for your time

bastya_elvtars

#2
QuoteOriginally posted by Mutor
Dont be afraid of the search  button, it no longer causes infertility in males 16-50.
Side effects may include:
  • Finding existing script(s).
  • Avoid redundant efforts.
  • A slight yet marked increase in general LUA knowledge.

PMSL  :D
Everything could have been anything else and it would have just as much meaning.

bastya_elvtars

QuoteOriginally posted by Mutor
QuotePMSL   :D

It's the little things in life that keeps one going.   :P

If only you knew how I miss you and the others from my DC++ chat window, alongside with my DC connectivity and all its benefits.  ;(
Everything could have been anything else and it would have just as much meaning.

SMF spam blocked by CleanTalk