PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Conversion Requests => Topic started by: Annie on 18 March, 2008, 13:12:57

Title: timebot
Post by: Annie on 18 March, 2008, 13:12:57
Hiya i got a little timebot for extra adds for main and i was wondering if somebody could convert it for me please :)

Code: [Select]
--Timebot for LUA 5
--
-- To main chat by blackwings
--Little changed by nErboS
--
-- Converted to LUA 5 by Mutor 2/28/2005
--

bot = "info bot"
name1 = "Hub Info"
name2 = "Hub message"


sec = 60


fMsgAll = "MsgAll.txt"
sMsgAll = ""

fMsgAll2 = "MsgAll2.txt"
sMsgAll2 = ""

tClock = {
["tMsgAll"] = os.clock() + 1*sec, -- Time to show in math.minutes
["tMsgAll2"] = os.clock() + 1*sec, -- Time to show in math.minutes
}

function Main()
frmHub:RegBot(bot)
sMsgAll = Readtext(fMsgAll)
sMsgAll2 = Readtext(fMsgAll2)
StartTimer()
end

function OnTimer()
if (tClock["tMsgAll"] <= os.clock() and sMsgAll~= "") then
tClock["tMsgAll"] = os.clock() + 150*sec
SendToAll(bot, sMsgAll)
end
if (tClock["tMsgAll2"] <= os.clock() and sMsgAll2~= "") then
tClock["tMsgAll2"] = os.clock() + 220*sec
SendToAll(name2, sMsgAll2)
end
end


function Readtext(file)
local sTmp="\r\n\r\n"
    for line in io.lines(file) do
        sTmp = sTmp..line.."\r\n"
    end
    return sTmp
end


thank you :D
Title: Re: timebot
Post by: Madman on 18 March, 2008, 20:11:46
Code: [Select]
--Timebot for LUA 5
--
-- To main chat by blackwings
--Little changed by nErboS
--
-- Converted to LUA 5 by Mutor 2/28/2005
--
-- Converted to API 2 by Madman, 18.03.08

bot = "info bot"
name1 = "Hub Info"
name2 = "Hub message"

sec = 60

fMsgAll = "MsgAll.txt"
sMsgAll = ""

fMsgAll2 = "MsgAll2.txt"
sMsgAll2 = ""

tClock = {
["tMsgAll"] = os.clock() + 1*sec, -- Time to show in math.minutes
["tMsgAll2"] = os.clock() + 1*sec, -- Time to show in math.minutes
}

function OnStartup()
Core.RegBot(bot,"","",true)
sMsgAll = Readtext(fMsgAll)
sMsgAll2 = Readtext(fMsgAll2)
tID = TmrMan.AddTimer(1*sec)
end

function OnTimer(ID)
if tID then
if (tClock["tMsgAll"] <= os.clock() and sMsgAll~= "") then
tClock["tMsgAll"] = os.clock() + 150*sec
Core.SendToAll("<"..bot.."> ".. sMsgAll)
end
if (tClock["tMsgAll2"] <= os.clock() and sMsgAll2~= "") then
tClock["tMsgAll2"] = os.clock() + 220*sec
Core.SendToAll("<"..name2.."> ".. sMsgAll2)
end
end
end


function Readtext(file)
local sTmp="\r\n\r\n"
for line in io.lines(file) do
sTmp = sTmp..line.."\r\n"
end
return sTmp
end

That should do it...
It's untested tho..
Title: Re: timebot
Post by: Annie on 18 March, 2008, 20:36:56
It works great thank you Madman :D
Title: Re: timebot
Post by: Annie on 20 January, 2009, 14:45:45
Ive changed the hub now to ptokax 4.1.1  and now the time bot has an error

this is the error I get scripts\timebot.lua:50: bad argument #1 to 'lines' (MsgAll.txt: No such file or directory)

worked fine on the 4.0.0e hub

I was wondering can somebody fix it please  :D
Title: Re: timebot
Post by: Annie on 21 January, 2009, 13:11:42
Yes the files were there. Its working great now  thanks Mutor :D