Author Topic: More that one time in a script  (Read 3733 times)

0 Members and 1 Guest are viewing this topic.

Offline OpiumVolage

  • Double Ace
  • *
  • Posts: 101
  • Karma: +1/-0
More that one time in a script
« on: 10 October, 2003, 23:45:54 »
Code: [Select]
-- MultiTimer by OpiumVolage (19/06/2003)
-- Ideas taken from tezlo's retrobot

tabTimers = {n=0}

-- Time Definition
Sec  = 1000
Min  = 60*Sec
Hour = 60*Min
Day  = 24*Hour

TmrFreq = 1*Min

function tmrtest()
-- SendToAll( "PtokaX", users.n )
end

function Main()
RegTimer(tmrtest, 1*Min)
SetTimer(TmrFreq)
StartTimer()
end

function OnTimer()
for i=1, getn(tabTimers) do
tabTimers[i].count = tabTimers[i].count + 1
if tabTimers[i].count > tabTimers[i].trig then
tabTimers[i].count=1
tabTimers[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(tabTimers, Timer)
end

PtokaX forum

More that one time in a script
« on: 10 October, 2003, 23:45:54 »

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
(No subject)
« Reply #1 on: 27 October, 2003, 18:54:30 »
Heh, good one :o)
Resistance is futile!

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #2 on: 30 October, 2003, 23:10:58 »
I must be dumb or I can't get it working with multi timers...

Plz give me an example off this...

I want one timer on 60000 and one on 20000 how would this look...

I am not so familiar with timers so plz help me understand...

Best Show'n with some examples....

/NightLitch
//NL

Offline OpiumVolage

  • Double Ace
  • *
  • Posts: 101
  • Karma: +1/-0
(No subject)
« Reply #3 on: 31 October, 2003, 00:06:12 »
Here you are 60000 is One minute and 20000 is 20 seconds:

It's almost the same code, i've just added one function (second timer), and adjusted the timer frequency to someting more adjusted.

Code: [Select]
-- MultiTimer by OpiumVolage (19/06/2003)
-- Ideas taken from tezlo's retrobot

tabTimers = {n=0}

-- Time Definition
Sec  = 1000
Min  = 60*Sec
Hour = 60*Min
Day  = 24*Hour

TmrFreq = 20*Sec

function tmrone()
SendToAll( "PtokaX", "First Timer")
end

function tmrtwo()
SendToAll( "PtokaX", "Second Timer" )
end

function Main()
RegTimer(tmrone, 1*Min)
RegTimer(tmrtwo, 20*Sec)
SetTimer(TmrFreq)
StartTimer()
end

function OnTimer()
for i=1, getn(tabTimers) do
tabTimers[i].count = tabTimers[i].count + 1
if tabTimers[i].count > tabTimers[i].trig then
tabTimers[i].count=1
tabTimers[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(tabTimers, Timer)
end

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #4 on: 31 October, 2003, 10:12:58 »
ThX OpiumVolage but how would this be done:

Code: [Select]
function Main()
frmHub:RegBot(BotName)
SetTimer(60000)
StartTimer()
end

function OnTimer()
for key, value in tabAdvert do
if (tabAdvert[key].iClock > clock()+60) then
tabAdvert[key]=nil
end
end
end

It's taken from Lucifer 6.6.6 I want to add this to my script so how would this look in your time-script...

Regards / NightLitch
//NL

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #5 on: 31 October, 2003, 10:57:34 »
No Need to Help I fixed it myself I think...

/NightLitch
//NL

Offline shipiz

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
(No subject)
« Reply #6 on: 20 January, 2004, 14:28:56 »
I get:

No syntax errors in script file timer.lua
Syntax error: attempt to perform arithmetic on global `Hub' (a nil value)
stack traceback:
   1:  method `func' at line 17 [file `F:\hub\scripts\timer.lua']
   2:  function `OnTimer' at line 31 [file `F:\hub\scripts\timer.lua']

« Last Edit: 20 January, 2004, 14:30:53 by shipiz »

Offline Madman

  • Scripter
  • Emperor
  • ******
  • Posts: 1 316
  • Karma: +75/-1
Re: More that one time in a script
« Reply #7 on: 04 November, 2006, 01:09:32 »
Code: [Select]
function RegTimer(F,Interval,Name)
local tmpTrig = Interval / TmrFreq
assert(Interval >= TmrFreq, "RegTimer(): Please Adjust TmrFreq")
local Timer = {n=0}
local Hit = nil
for I in ipairs(tabTimers) do
if tabTimers[I].Name == Name then
Hit = 1
end
end
if Hit then
-- Don't add...
else
Timer.Name = Name
Timer.Func = F
Timer.Trig = tmpTrig
Timer.count=1
table.insert(tabTimers, Timer)
end
end

function RemoveTimer(Name)
local count = 0
for I in ipairs(tabTimers) do
count = count+1
if string.find(tabTimers[I].Name, Name) then
Timer2Remove = count
break
end
end
table.remove(tabTimers, Timer2Remove)
end

Updated the code...
Now it can't add the same timer twice, and added a function to remover timers...
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

PtokaX forum

Re: More that one time in a script
« Reply #7 on: 04 November, 2006, 01:09:32 »