PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: NightLitch on 10 August, 2004, 19:29:28

Title: *** Share Warning ***
Post by: NightLitch on 10 August, 2004, 19:29:28
A request Script I made to Juda, maybe more finds it usefull.

*CODE UPDATED*

--------------------------------------------------------
-- Share Warning - By: NightLitch - 2004/08/10
-- Request By: Juda
-- NOTE: NoShare Table is erased when Script is Restarted !!
-- Some Modification Done
-- Changed so it send in PM
--------------------------------------------------------
KB = 1024
MB = KB*KB
GB = KB*KB*KB
TB = KB*KB*KB*KB
Sec  = 1000
Min  = 60*Sec
Hour = 60*Min
TmrFreq = 1000
--------------------------------------------------------
--// Editable Part Start's Here \\--
--------------------------------------------------------
BotName = "-Share-Warning-" -- Set Botname

MinShareLimit = 500 -- Set Share Limit
MinShareUnit = MB -- Set Share Unit ( KB, MB, GB, TB )

NoShareTimeLimit = 24 -- Set Time Limit in hours for checking if share is more then 0 MB etc.
ShareUpdateTimeLimit = 12 -- Set Time Limit in hours for checking if share is updated after x hours
NoShareMessage = "You're welcome to stay in this hub, BUT you need to fill your Share with "..MinShareLimit.." MB within "..NoShareTimeLimit.." Hours to stay!"
--------------------------------------------------------
--// Code Starts Here \\--
--------------------------------------------------------
NoShare = {}
tTab = {n=0}

function Main()
frmHub:RegBot(BotName)
SetTimer(TmrFreq)
StartTimer()
RegTimer(NoShareCheck, 1*Sec)
RegTimer(ShareUpdatedCheck, 1*Sec)
end

function ShareUpdatedCheck()
for Nickname, Table in NoShare do
User = GetItemByName(Nickname)
if User then
local _,_,h,m,s = strfind(Table[2], "(%d+):(%d+):(%d+)")
h = h + ShareUpdateTimeLimit
if h..":"..m..":"..s == date("%T") then
local _,_,CurrentShare = strfind(User.sMyInfoString, "(%d+)%$%|$")
if tonumber(CurrentShare) <= tonumber(Table[1]) then
SendPmToNick(Nickname, BotName, "You haven't raised your share within "..ShareUpdateTimeLimit.." Hours and your share is still "..format("%.2f",Table[1]/1024/1024).." MB !!")
SendPmToNick(Nickname, BotName, "You are Disconnected!!")
User:Disconnect()
NoShare[Nickname] = nil
end
end
end
end
end

function NoShareCheck()
for Nickname, Share in NoShare do
if tonumber(Share) == 0 then
User = GetItemByName(Nickname)
if User then
local _,_,h,m,s = strfind(Table[2], "(%d+):(%d+):(%d+)")
h = h + NoShareTimeLimit
if h..":"..m..":"..s == date("%T") then
SendPmToNick(Nickname, BotName, "You have been online for "..NoShareTimeLimit.." Hours and your share is still "..format("%.2f",Share/1024/1024).." MB !!")
SendPmToNick(Nickname, BotName, "You are Disconnected!!")
User:Disconnect()
NoShare[Nickname] = nil
end
end
end
end
end

function UserDisconnect(sUser)
NoShare[sUser.sName] = nil
end

function DataArrival(sUser,sData)
if strsub(sData, 1,7) == "$MyINFO" then
local s,e,sShare = strfind(sData, "(%d+)%$%|$")
NoShare[sUser.sName] = {sShare,date("%T")}
if tonumber(sShare) == 0 then
SendPmToNick(sUser.sName, BotName, "\r\n\t -------==[ NOTICE !! ]===================================================-------")
SendPmToNick(sUser.sName, BotName, "\r\n\t "..NoShareMessage)
SendPmToNick(sUser.sName, BotName, "\r\n\t -------===============================================================-------\r\n\r\n")
end
end
end

function OnTimer()
for i=1, getn(tTab) do
tTab[i].count = tTab[i].count + 1
if tTab[i].count > tTab[i].trig then
tTab[i].count=1
tTab[i]:func()
end
end
end

function RegTimer(f, Interval)
local tmpTrig = Interval / TmrFreq
assert(Interval >= TmrFreq , "RegTimer(): Please Adjust TmrFreq")
local Timer = {n=0}
Timer.func=f
Timer.trig=tmpTrig
Timer.count=1
tinsert(tTab, Timer)
end

Enjoy / NightLitch