Author Topic: need help with timer  (Read 3814 times)

0 Members and 1 Guest are viewing this topic.

Offline enema

  • Lord
  • ***
  • Posts: 276
  • Karma: +1/-0
need help with timer
« on: 02 January, 2005, 18:01:50 »
this is my piece of code:
Code: [Select]
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:
Code: [Select]
SetTimer(min)
StartTimer()
???
8)  mitava.no-ip.org   8)

PtokaX forum

need help with timer
« on: 02 January, 2005, 18:01:50 »

Offline ??????Hawk??????

  • Emperor
  • **
  • Posts: 1 044
  • Karma: +12/-2
    • Leeds Laptop Repairs
(No subject)
« Reply #1 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()

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 744
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #2 on: 02 January, 2005, 18:55:37 »
SetTimer(time_in_ms):everywhere

StartTimer(): where you wanna start it.
Everything could have been anything else and it would have just as much meaning.

Offline enema

  • Lord
  • ***
  • Posts: 276
  • Karma: +1/-0
(No subject)
« Reply #3 on: 02 January, 2005, 20:03:05 »
this is what I have
Code: [Select]
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?
8)  mitava.no-ip.org   8)

Offline ??????Hawk??????

  • Emperor
  • **
  • Posts: 1 044
  • Karma: +12/-2
    • Leeds Laptop Repairs
(No subject)
« Reply #4 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

Offline Typhoon

  • Lord
  • ***
  • Posts: 397
  • Karma: +22/-3
  • PGE Developer
    • PGE Homepage
(No subject)
« Reply #5 on: 02 January, 2005, 21:08:20 »
hi try this out

Code: [Select]

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?



Offline VidFamne

  • Triple Ace
  • **
  • Posts: 173
  • Karma: +2/-0
(No subject)
« Reply #6 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?

Offline ??????Hawk??????

  • Emperor
  • **
  • Posts: 1 044
  • Karma: +12/-2
    • Leeds Laptop Repairs
(No subject)
« Reply #7 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  ...

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 744
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #8 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 ;)

Code: [Select]
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
Everything could have been anything else and it would have just as much meaning.

Offline ??????Hawk??????

  • Emperor
  • **
  • Posts: 1 044
  • Karma: +12/-2
    • Leeds Laptop Repairs
(No subject)
« Reply #9 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

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 744
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #10 on: 02 January, 2005, 22:42:02 »
see MUTE part
Everything could have been anything else and it would have just as much meaning.

Offline Typhoon

  • Lord
  • ***
  • Posts: 397
  • Karma: +22/-3
  • PGE Developer
    • PGE Homepage
(No subject)
« Reply #11 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?



Offline ??????Hawk??????

  • Emperor
  • **
  • Posts: 1 044
  • Karma: +12/-2
    • Leeds Laptop Repairs
(No subject)
« Reply #12 on: 02 January, 2005, 23:14:41 »
untested   but on the  right lines  ...

Code: [Select]
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

« Last Edit: 02 January, 2005, 23:15:00 by ??????Hawk?????? »

Offline enema

  • Lord
  • ***
  • Posts: 276
  • Karma: +1/-0
(No subject)
« Reply #13 on: 03 January, 2005, 14:10:41 »
thank you guys, but I just notice, that script Im willing to make, is already made :D
8)  mitava.no-ip.org   8)

PtokaX forum

(No subject)
« Reply #13 on: 03 January, 2005, 14:10:41 »