PtokaX forum

Development Section => Your Developing Problems => Topic started by: enema on 02 January, 2005, 18:01:50

Title: need help with timer
Post by: enema on 02 January, 2005, 18:01:50
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()
???
Title:
Post by: ??????Hawk?????? on 02 January, 2005, 18:49:25
hi m8  ..  it  depends on When you want to start the timer  ..


but  usually its started in the  Function Main()
Title:
Post by: bastya_elvtars on 02 January, 2005, 18:55:37
SetTimer(time_in_ms):everywhere

StartTimer(): where you wanna start it.
Title:
Post by: enema on 02 January, 2005, 20:03:05
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?
Title:
Post by: ??????Hawk?????? on 02 January, 2005, 20:57:45
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)
Title:
Post by: Typhoon on 02 January, 2005, 21:08:20
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?
Title:
Post by: VidFamne on 02 January, 2005, 21:45:43
Does it realy function?
For every user connect, the timer start all over again.
And there is only one timer in a script?
Title:
Post by: ??????Hawk?????? on 02 January, 2005, 21:52:59
easier to use the  


 tUsers[user.sName]=clock()


have the timer starting in main and  have a check against clock  every min  ...
Title:
Post by: bastya_elvtars on 02 January, 2005, 22:24:52
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
Title:
Post by: ??????Hawk?????? on 02 January, 2005, 22:29:57
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
Title:
Post by: bastya_elvtars on 02 January, 2005, 22:42:02
see MUTE part
Title:
Post by: Typhoon on 02 January, 2005, 22:55:55
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?
Title:
Post by: ??????Hawk?????? on 02 January, 2005, 23:14:41
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

Title:
Post by: enema on 03 January, 2005, 14:10:41
thank you guys, but I just notice, that script Im willing to make, is already made :D