this is my piece of code:
function NewUserConnected(user, data)
if user.iProfile == -1 then
user:SendPM(sBot, "you must kiss your mum in next 24h")
end
end
My question is: where do I have to place these:
SetTimer(min)
StartTimer()
???
hi m8 .. it depends on When you want to start the timer ..
but usually its started in the Function Main()
SetTimer(time_in_ms):everywhere
StartTimer(): where you wanna start it.
this is what I have
sec = 1000
min = 60*sec
hour = min*60
sBot = "Reggy"
function NewUserConnected(user, data)
if user.iProfile == -1 then
user:SendPM(sBot, "somekind of text will be here")
StartTimer()
SetTimer(min)
end
end
function OnTimer()
user:SendData(sBot, "bla bla bla")
end
And this is whats wrong: stack traceback:
1: function `OnTimer' at line 17 [file `...visi\Desktop\New Folder\testhub\scripts\cgz.lua']
How can I fix that?
hi m8
i think i under stand what your trying to Acchieve but you cant do it that way..
Take a look at this Thread ...
http://board.univ-angers.fr/thread.php?threadid=2253&boardid=11&sid=6aa40fabc83390d57f2992a69220f767 (http://board.univ-angers.fr/thread.php?threadid=2253&boardid=11&sid=6aa40fabc83390d57f2992a69220f767)
hi try this out
sec = 1000
min = 60*sec
hour = min*60
sBot = "Reggy"
Interval = 1 -- interval for timer message
tUsers = {}
function NewUserConnected(user, data)
if user.iProfile == -1 then
user:SendPM(sBot, "somekind of text will be here")
tUsers[user.sName]=1
StartTimer()
SetTimer(Interval*min)
end
end
function UserDisconnected(user)
if tUsers[user.sName] then
tUsers[user.sName]=nil
end
end
function OnTimer()
for i,v in tUsers do
local User = GetItemByName(i)
User:SendData(sBot, "bla bla bla")
end
end
Typhoon?
Does it realy function?
For every user connect, the timer start all over again.
And there is only one timer in a script?
easier to use the
tUsers[user.sName]=clock()
have the timer starting in main and have a check against clock every min ...
Idea from MiniMultiTimer by Phatty.
Every global variable's numeric value increases on timer. If a value reaches a certain level, something happens, and timer gets reset to 0.
This is rather a HOWTO but... hope you can use it.
NB: timer is set to 1 secs.
The code will be optimized (before Nightlitch or plop see this i write it down) just forgot 2 rewrite it ;)
function OnTimer()
if tmr<60 then
tmr=tmr+1
else
if floor(tonumber((date("%H")/2)))==tonumber(date("%H")/2) and date("%M")=="00" then
botversion(nil,"MAIN",nil) tmr=0
end
tmr=0
end
for a,b in MUTE do
b=b+1
if b==mutetime*60 then
MUTE[a]=nil -- every muted user has a unique timer
end
end
if timer<3600 then
timer=timer+1
else
parsestats() -- 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
no need for multi timer...
see my last post Store the clock value with the user name in a table..
then use the on timer to check each of the table values against the current clock.
and make the script act accordingly
see MUTE part
yep mine resets the timer every user connect ..
and the clock() part i didn't think of hehe .. ( almost bedtime )
@ VidFamne , but it worked on my test only 1 user :o)
Typhoon?
untested but on the right lines ...
sec = 1000
min = 60*sec
hour = min*60
sBot = "Reggy"
Interval = 1 -- interval for timer message
MessageSendTime = 20 --// mins
tUsers = {}
function main()
SetTimer(Interval*min)
StartTimer()
end
function NewUserConnected(user, data)
if user.iProfile == -1 then
user:SendPM(sBot, "somekind of text will be here")
tUsers[user.sName]=clock()
end
end
function UserDisconnected(user)
if tUsers[user.sName] then
tUsers[user.sName]=nil
end
end
function OnTimer()
local FixTime = clock()
for i,v in tUsers do
if tonumber(FixTime)-tonumber(tUsers[i]) >= MessageSendTime then
local User = GetItemByName(i)
User:SendData(sBot, "bla bla bla")
tUsers[User.sName]=nil
end
end
end
thank you guys, but I just notice, that script Im willing to make, is already made :D