I want the bot to tell the user the hub's uptime on login.
I also want to show the hub's total share.
I can't make it to work.
I have this at the moment:
function NewUserConnected(user)
BadWord[user.sName] = 0
user:SendData(Bot,"")
user:SendData(" ? Welcome "..user.sName.." to "..frmHub:GetHubName().." ?")
user:SendData(" ? Your IP is: "..user.sIP.." ?")
user:SendData(" ? Here is now "..frmHub:GetUsersCount().." of "..frmHub:GetMaxUsers().." users connected ?")
user:SendData(" ? Hubs current share is "..frmHub:GetMinShare().." GB ?")
user:SendData(" ? Remember to read hub rules by typing '"..prefix.."rules' in main chat ?")
user:SendData(" ? And other network hubs you can find by typing "..netw.." in main chat ?")
user:SendData(" ? Uptime = "..days.." days, "..hrs.." hrs. "..min.." min. and "..sec.." sec. ?")
user:SendData(Bot,"")
SendToAll(Bot,"Welcome our new guest "..user.sName..", enjoy your stay")
end
Thanks for any help
Hi,
Hope it helps..
--Requested by HiddenSniper
--Made by nErBoS
Bot = "Welcome-Bot"
prefix = "!"
function Main()
frmHub:RegBot(Bot)
end
function NewUserConnected(user, data)
local tmp = clock()
local days, hours, minutes = floor(tmp/86400), floor(mod(tmp/3600, 24)), floor(mod(tmp/60, 60))
local s,e,share = strfind(user.sMyInfoString, "%$%s*(%d+)%$")
share = frmHub:GetCurrentShareAmount() + share
local ttshare = format("%0.2f", tonumber(share)/(1024*1024*1024))
user:SendData(Bot,"")
user:SendData(" ? Welcome "..user.sName.." to "..frmHub:GetHubName().." ?")
user:SendData(" ? Your IP is: "..user.sIP.." ?")
user:SendData(" ? Here is now "..frmHub:GetUsersCount().." of "..frmHub:GetMaxUsers().." users connected ?")
user:SendData(" ? Hubs current share is "..frmHub:GetMinShare().." GB ?")
user:SendData(" ? Remember to read hub rules by typing '"..prefix.."rules' in main chat ?")
user:SendData(" ? And other network hubs you can find by typing "..prefix.."network in main chat ?")
user:SendData(" ? Total Share in the HUB = "..ttshare.." GB ?")
user:SendData(" ? Uptime = "..days.." days, "..hours.." hrs. and "..minutes.." min. ?")
user:SendData(Bot,"")
SendToAll(Bot,"Welcome our new guest "..user.sName..", enjoy your stay")
end
OpConnected = NewUserConnected
Best regards, nErBoS
local sec = clock()
local days = floor(sec/86400)
local hrs = floor((sec-(days*86400))/3600)
local min = floor((sec-(days*86400)-(hrs*3600))/60)
sec = floor(sec-(days*86400)-(hrs*3600)-(min*60))
user:SendData("uptime", "*** "..days.." days, "..hrs.." hours "..min.." minutes and "..sec.." seconds|")
plop
Can you guys explain what the the things in the code means?
local sec = clock()
local days = floor(sec/86400)
local hrs = floor((sec-(days*86400))/3600)
local min = floor((sec-(days*86400)-(hrs*3600))/60)
sec = floor(sec-(days*86400)-(hrs*3600)-(min*60))
What does floor mean? and why the odd numbers, where do you get 86400 from?
Why does it have to be local?
I haven't tried the code yet, will do it as soon as I quit for the day.
Thanks.
//HiddenSniper
you have locals and globals, globals are always kept in memory while local get dropped into the garbage bin as soon as there not needed anymore.
@ the end of a function 2 be precise.
local sec = clock()
this returns the uptime in seconds.
here's and example of 1186400 seconds.
it explains it all.
1186400 total seconds
------------------------------
1186400/86400
raw day's 13.73148148148148
floor days 13
left over seconds 63199.99999999996
------------------------------
1186400-(13*86400))/3600
raw hours 17.55555555555556
floor hours 17
left over seconds 2000.000000000006
------------------------------
1186400-(13*86400)-(17*3600))/60
raw mins 33.33333333333334
floor mins 33
left over seconds 20.00000000000014
------------------------------
1186400-(13*86400)-(17*3600)-(33*60)
raw mins 20
floor seconds 20
left over seconds 0
------------------------------
uptime *** 13 days, 17 hours 33 minutes and 20 seconds
and here's the matching script so you can play with it a bit.
use the lua command line 2 execute this script.
sec = 1186400
print(sec.." total seconds")
print( "------------------------------" )
print( sec.."/86400" )
rawdays = sec/86400
print( "raw day's "..rawdays)
days = floor(sec/86400)
print( "floor days "..days )
print( "left over seconds "..(rawdays-days)*86400 )
print( "------------------------------" )
print( sec.."-("..days.."*86400))/3600" )
rawhrs = (sec-(days*86400))/3600
print( "raw hours "..rawhrs )
hrs = floor((sec-(days*86400))/3600)
print( "floor hours "..hrs )
print( "left over seconds "..(rawhrs-hrs)*3600 )
print( "------------------------------" )
print( sec.."-("..days.."*86400)-("..hrs.."*3600))/60" )
rawmin = (sec-(days*86400)-(hrs*3600))/60
print( "raw mins "..rawmin )
min = floor((sec-(days*86400)-(hrs*3600))/60)
print( "floor mins "..min )
print( "left over seconds "..(rawmin-min)*60 )
print( "------------------------------" )
print(sec.."-("..days.."*86400)-("..hrs.."*3600)-("..min.."*60)" )
rawsec = sec-(days*86400)-(hrs*3600)-(min*60)
print( "raw mins "..rawsec )
sec = floor(sec-(days*86400)-(hrs*3600)-(min*60))
print( "floor seconds "..sec )
print( "left over seconds "..(rawsec-sec) )
print( "------------------------------" )
print( "uptime", "*** "..days.." days, "..hrs.." hours "..min.." minutes and "..sec.." seconds" )
plop