need help with timer
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

need help with timer

Started by enema, 02 January, 2005, 18:01:50

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

enema

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()
???

??????Hawk??????

hi m8  ..  it  depends on When you want to start the timer  ..


but  usually its started in the  Function Main()

bastya_elvtars

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.

enema

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?

??????Hawk??????

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

Typhoon

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?



VidFamne

Does it realy function?
For every user connect, the timer start all over again.
And there is only one timer in a script?

??????Hawk??????

easier to use the  


 tUsers[user.sName]=clock()


have the timer starting in main and  have a check against clock  every min  ...

bastya_elvtars

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

??????Hawk??????

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

bastya_elvtars

Everything could have been anything else and it would have just as much meaning.

Typhoon

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?



??????Hawk??????

#12
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

enema

thank you guys, but I just notice, that script Im willing to make, is already made :D

SMF spam blocked by CleanTalk