Multitimer lua5
 

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

Multitimer lua5

Started by Dessamator, 22 March, 2005, 13:15:42

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dessamator

--lua5 version by Dessamator
-- 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*Sec
botname=  frmHub:GetHubBotName() -- bot name
------------------------------MAIN FUNCTION ------------------------ 
function Main()  
frmHub:RegBot(botname)


--timerS
	RegTimer(Trig1, 1*Min)
	RegTimer(Trig2, 2*Min)
	SetTimer(TmrFreq)
	StartTimer()
--
end  
----------------------------------------------------------------------
--Timer Functions--
function Trig1()
	SendToAll("txt")

end
function Trig2()
	SendToAll("txt2")
	
end

function OnTimer()
	for i in ipairs(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
	table.insert(tabTimers, Timer)
end

-- Timer Functions--------

Ignorance is Bliss.

plop

for i in pairs(tabTimers) do

pairs = loop an array.
ipairs = loop a table.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Dessamator

QuoteOriginally posted by plop
for i in pairs(tabTimers) do

pairs = loop an array.
ipairs = loop a table.

plop

Done  !
Ignorance is Bliss.

Dessamator

-- by OpiumVolage (19/06/2003)
-- Ideas taken from tezlo's retrobot
-- Lua5 version by Dessamator
-- MultiTimer v1.1
-- added trig to view timers 
-- added trig to remove timer

tabTimers = {n=0}

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

TmrFreq = 1*Sec
botname=  frmHub:GetHubBotName() -- bot name
------------------------------MAIN FUNCTION ------------------------ 
function Main()  
frmHub:RegBot(botname)


--timerS
	RegTimer(Trig1, 1*Min,"trig1")
	RegTimer(Trig2, 2*Min,"trig2")
	SetTimer(TmrFreq)
	StartTimer()
--
end  
----------------------------------------------------------------------
--Timer Functions--
function Trig1()
	SendToAll("txt")

end
function Trig2()
	SendToAll("txt2")
	
end

function OnTimer()
	for i in ipairs(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,name)
	local tmpTrig = Interval / TmrFreq
	assert(Interval >= TmrFreq , "RegTimer(): Please Adjust TmrFreq")
	local Timer = {n=0}
	Timer.name=name
	Timer.func=f
	Timer.trig=tmpTrig
	Timer.count=1
	table.insert(tabTimers, Timer)
end

-- Timer Functions--------

function ChatArrival(user,data)
data = string.sub(data,1,-2)
local temp="\r\n\t\These are the timers in you script :\r\n"
local _,_,timername = string.find(data,"%b<>%s+%S+%s+(%S+)")
local s,e,cmd = string.find(data,"%b<>%s+(%S+)")
	if cmd=="!tremove" then
		for i in ipairs(tabTimers) do
			if tabTimers[i].name == timername then
				table.remove(tabTimers,i)
				status="Timer Removed"
			elseif not (tabTimers[i].name==timername) then
				status="That Timer doesnt exist"
			end
		end
	user:SendData(botname,status)
	return 1
	elseif cmd=="!tview" then
		for i in ipairs(tabTimers) do
			temp=temp.."\t\t•"..tabTimers[i].name.."\r\n"
		end
	user:SendData(botname,temp)
	return 1
	end
end
Ignorance is Bliss.

SMF spam blocked by CleanTalk