PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: Psycho_Chihuahua on 12 April, 2006, 16:18:12

Title: Need a little Help here - extending InfoBot by Mutor
Post by: Psycho_Chihuahua on 12 April, 2006, 16:18:12
Well i've run myself into a Dead End here (as i'm no scripter)

I'm trying to get the script to give out the Hub Uptime in Weeks/Days/Hours/Minutes instead of only Minutes...and tried a whole lot of different aproaches...
This is what i tried last (it started - but crashed as soon as i reconnected to the hub)
Error Message is
\scripts\InfoBot.lua:63: attempt to call global `frac' (a nil value)

for this script (now all scripters can have a good laugh ;))

--[[
InfoBot 1.0 LUA5

By Mutor        02/25/06

Show hub/user infor to new connections, (pulled from another script)
]]--
PtxVers = "f0 Lua 5.02"
LmVers = "v1.0 beta 2"
IPdbVers = "v3.00"
D2AFVers = "v5.31?"
RSSVers = "v2.3"


NewUserConnected = function(user)
name, ver = getHubVersion()
local _,W,D,H,M=minutestoh(frmHub:GetUpTime() / 60)
local HubOwner = "Psycho_Chihuahua"
local Greeting = "It's nice of you to stop by..."
local Prof
local Topic
Prof= GetProfileName(user.iProfile) or "Unregistered User"
Topic = frmHub:GetHubTopic() or "There is no current topic."
local art = string.rep("?",40).."\r\n"
local ul = string.rep("?",14).."\r\n"
local tmp = "\r\n\r\n\t"..art.."\tHub Information:\r\n\t"..ul..
"\tWelcome:\t"..user.sName..", "..GetEnable(Greeting).."\r\n"..
"\tHub Name: \t"..GetEnable(frmHub:GetHubName())..",  "..Topic.."\r\n"..
"\tHub Version: \t"..name.." "..ver.." "..PtxVers.."\r\n"..
"\tHub description:\t"..GetEnable(frmHub:GetHubDescr()).."\r\n"..
"\tHubOwner:\t"..GetEnable(HubOwner).."\r\n"..
"\tUptime:\t\t"..string.format("_,W,D,H,M",frmHub:GetUpTime() / 60).."\r\n"..
"\tPeak Users:\t"..GetEnable(frmHub:GetMaxUsersPeak()).."\r\n"..
"\tHub Share:\t"..string.format("%.2f Tb.",frmHub:GetCurrentShareAmount()/(1024 * 1024 * 1024 * 1024)).."\r\n"..
"\tThere Are Now:\t"..GetEnable(frmHub:GetUsersCount()).." of "..GetEnable(frmHub:GetMaxUsers()).." max users online.\r\n\r\n"..
"\t"..art.."\tYour Information:\r\n\t"..ul..
"\tUsername:\t"..user.sName.."\r\n"..
"\tUser Profile:\t"..Prof.."\r\n"..
"\tIP Address:\t"..GetEnable(user.sIP).."\r\n"..
"\tShare Size:\t"..string.format("%.2f Gb.",user.iShareSize/(1024 * 1024 * 1024)).."\r\n"..
"\tDC Tag:\t\t"..GetEnable(user.sTag).."\r\n"..
"\tDescription:\t"..GetEnable(user.sDescription).."\r\n"..
"\tEmail:\t\t"..GetEnable(user.sEmail).."\r\n"..
"\tConnection:\t"..GetEnable(user.sConnection).."\r\n\r\n"..
"\t"..art.."\tScript Information:\r\n\t"..ul..
"\tLawmaker:\t"..LmVers.."\r\n"..
"\tIPdbBot:\t\t"..IPdbVers.."\r\n"..
"\tDeath2Adult:\t"..D2AFVers.."\r\n"..
"\tRSS Bot:\t\t"..RSSVers.."\r\n"..
"\t? [ This information is only being shown to you ] ?\r\n\r\n\t"..art
user:SendData(tmp)
end
OpConnected = NewUserConnected

function GetEnable(enable)
if enable == nil or enable == "" or not enable then
enable = "not set"
end
return enable
end

function minutestoh(minutes) -- gets minutes as arguments, returns a string with formatted time and 4 numbers as units
    if frac(minutes) > 0.5 then minutes=math.ceil(minutes) else minutes=math.floor(minutes) end
      local weeks,days,hours,mins
      local msg=""
        local a1,a2,a3=math.mod(minutes,10080),math.mod(minutes,1440),math.mod(minutes,60)
        if a1==minutes then weeks=0 else weeks=math.floor(minutes/10080) end
        if a2==minutes then days=0 else days=math.floor(a1/1440) end
        if a3==minutes then hours=0 else hours=math.floor(a2/60) end
        mins=math.mod(minutes,60)
        local tmp=
            {
              [" weeks "]=weeks,
              [" days "]=days,
              [" hours "]=hours,
              [" minutes"]=mins
            }
            local tmp2={" weeks "," days "," hours "," minutes"}
        for a,b in ipairs(tmp2) do
          if tmp[b] > 0 then
            msg=msg..tmp[b]..b
          end
        end
        if msg=="" then msg="0" end
        return msg,weeks,days,hours,mins
      end


Like i said, i am no scripter and still try to get things working by trial and error. As for translations it is easy but this stuff is somewhat to high for me
Title: Re: Need a little Help here - extending InfoBot by Mutor
Post by: bastya_elvtars on 12 April, 2006, 16:22:52
Well, it's my fault. I sent you that minutestoh function, but forgot this:

function frac(num) -- returns fraction of a number (RabidWombat)
  return num - math.floor(num);
end
Title: Re: Need a little Help here - extending InfoBot by Mutor
Post by: Psycho_Chihuahua on 12 April, 2006, 16:34:16
Thanks to bastya it's finally working  ;D
now i just gotta find the right thread to post it in.


**Edit: It's here now --> http://forum.ptokax.org/index.php?topic=5752#msg59057 **