Hi,
I have a question: How can I put something for about 5 minutes in a table... I use this:
userlist = {}
...
if userlist[sUser.sName] ~= 1 then
>>ACTION<<
if userlist[sUser.sName] == nil then
userlist[sUser.sName] = 1
end
I want to have something like:
userlist = {}
...
if userlist[sUser.sName] ~= 1 then
>>ACTION<<
if userlist[sUser.sName] == nil then
userlist[sUser.sName] = 1
>> ?? put sUser.sName in table for 5 min ?? <<
end
So, the only thing I need is a function that keeps a user in this table for 5 minutes, and then it will be removed from the table...
You assign values the userlist keys and increase the number OnTimer() and if it reaches the value representing 5 mins you remove user or do anything you like. Gonna make example tomorrow.
thanx bastya! :D
SetTimer(60000) -- 1 minute
StartTimer()
-- add users this way on MYINFOArrival or NewUserConnected:
userlist[user.sName]=0
function OnTimer()
for a,b in userlist do
if b~=5 then
b=b+1
else
a=nil
end
end
end
Hi,
I can't get it work... This is maybe because there is already a timer running...:
-- Temp Tables --
warned = {}
warned02 = {}
tTimer = {}
tTimer02 = {}
userlist = {}
-- Main --
function Main()
frmHub:RegBot(bot)
RegTimer(SearchForBadFiles, 20 * 1000, "ActiveBadFileSearch")
SetTimer(1000)
StartTimer()
end
-- Action --
if userlist[sUser.sName] == nil then
>> warn
if userlist[sUser.sName] == nil then
userlist[sUser.sName] = 1
end
end
-- Timers --
RegTimer = function(Function,Interval,str)
local tmpTrig = Interval / 1000
table.insert(tTimer,{Function,tmpTrig,1,str})
end
function OnTimer()
for i=1,table.getn(tTimer) do
tTimer[i][3] = tTimer[i][3] + 1
if tTimer[i][3] > tTimer[i][2] then
tTimer[i][3]=1
tTimer[i][1]()
end
end
for a,b in userlist do
if b~=300 then
b=b+1
else
a=nil
end
end
end
This is indeed a piece of the code from NightLitch : Advanced BadFile Active Search // Stripped from Thor 6
I'm kind of optimizing it :) Do you (bastya), or others have suggestions to make it work?
Quoteif userlist[sUser.sName] == nil then
>> warn
if userlist[sUser.sName] == nil then
userlist[sUser.sName] = 1
end
end
i dont get that part if something is nil, and if something is nil???, whats the repetition for?, evaluate that, mayb thats the prob !!!
and the table tTimer, is always nil, as far as i can c
Explaination:
if userlist[sUser.sName] == nil then
>> if in table userlist username = nil then
>> warn (this is just an action) When action is done, in the table the user will be given the number 1:
if userlist[sUser.sName] == nil then
userlist[sUser.sName] = 1
end
So, first table is empty. When the whole function starts, it checks if the user has given the number 0 (when it is empty, table with user is 0). If it is 0, then it will warn (action)...
This is what I think it means, correct me if I'm wrong!
its useless to check if twice, on the same function, just write it like this::
if userlist[sUser.sName] == nil then
--warn
--userlist[sUser.sName] = 1
end
u r right :D
It still doesn't work right..
someone who can help me out with this? ?(
thanx
you don't need a timer
just look up the time of the elements everytime you access them, and remove the old (>5mins) crap
hmm, sedulus , i think he needs an example to learn from !!!
after a pm with TTB from dc dev i made the next script.
sBot = "warner_bross"
tDelay = {}
function Main()
SetTimer(60* 1000)
StartTimer()
end
function ChatArrival(user, data)
data = string.sub(data, 1, (string.len(data) - 1))
local s,e,sCmd,sVictem,sReason = string.find(Data, "%b<>%s+%p(%S+)%s*(%S*)%s*(%S*)")
if sCmd and sCmd == "warn" then
if sVictem ~= "" then
local oVictem = GetItemByName(sVictem)
if oVictem then
if not tDelay[oVictem.sName] then
if sReason == "" then
sReason = "no reason given"
end
tDelay[oVictem.sName] = 0
oVictem:SendData(sBot, "--WARNING-- "..sReason.." --WARNING-- ")
end
else
user:SendData(sBot, sVictem.." is a unknown user!")
end
else
user:SendData(sBot, "no username given!")
end
end
end
function OnTimer()
for user,timer in pairs(tDelay) do
if timer ~= 5 then
tDelay[user] = tDelay[user] + 1
else
tDelay[user] = nil
end
end
end
and here's 1 to the idea of sedules (no timer used)
sBot = "warner_bross"
iDelay = 5 * 60 -- (mins)
tDelay = {}
function ChatArrival(user, data)
data = string.sub(data, 1, (string.len(data) - 1))
local s,e,sCmd,sVictem,sReason = string.find(Data, "%b<>%s+%p(%S+)%s*(%S*)%s*(%S*)")
if sCmd and sCmd == "warn" then
if sVictem ~= "" then
local oVictem = GetItemByName(sVictem)
if oVictem then
if not tDelay[oVictem.sName] or ( (os.clock() / 60) - iDelay ) > tDelay[oVictem.sName] then
Warn(oVictem, sReason)
end
else
user:SendData(sBot, sVictem.." is a unknown user!")
end
else
user:SendData(sBot, "no username given!")
end
end
end
function Warn(oVictem, sReason)
if sReason == "" then
sReason = "no reason given"
end
tDelay[oVictem.sName] = os.clock()
oVictem:SendData(sBot, "--WARNING-- "..sReason.." --WARNING-- ")
end
both scripts aren't tested, it's up 2 TTB 2 debug it.
plop
Hi, first of all... PLOP thanx for your great help!
Secondly... tiny mini mistake made by you:
function ChatArrival(user, data)
will give:
local s,e,sCmd,sVictem,sReason = string.find(data, "%b<>%s+%p(%S+)%s*(%S*)%s*(%S*)")
so no uppercase in Data.
Well.. The script by bastya seems to be almost right. I had to use this:
for user,timer in pairs(userlist) do
if timer ~= time01 then
userlist[user] = userlist[user] + 1
else
userlist[user] = nil
end
end
time01 is defined by myself.
Thanx all ppl for helping me out! Now I can move on with this script...
Credits to be given: I got the idea from MiniMultiTimer by Phatty, just made it a bit more solid. Here is my timer function from LawMaker:
function OnTimer()
if (tmr < 60) then tmr = tmr + 1;
else
local h = tonumber((os.date("%H")/2)) -- is it time to remember every1 what the bot is called?
if ( (math.floor(h) == h) and (tonumber(os.date("%M")) == 0) ) then botversion();end;
tmr=0;
end
-- take care of our disabled people
for a,b in MUTE do b=b+1; if (b==mutetime*60) then MUTE[a] = nil;end;end;
if timer<3600 then
timer=timer+1
else
Statistics_Refresh() -- parse the stats every hour
timer=0
Clear()
end
if ahm<900 then
ahm=ahm+1
else
ahm=0
antihammer=nil
Clear()
antihammer={}
end
end
Nice info :]
It goes step by step to learn this wonderful language...
also check my texter 4.5 for a more advanced multitimer system.
plop