PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: QuikThinker on 08 June, 2004, 03:44:48

Title: 2 scripts in to 1
Post by: QuikThinker on 08 June, 2004, 03:44:48
Hey guys,
I'm runnin 2 scripts exactly the same apart from just 2 differences (bot name & txt file).

bot = "PHH Hub Radio"
mins = 20
file = "MsgAll.txt"

function Main()
SetTimer(mins*60000)
StartTimer()
end

function OnTimer()
local handle = openfile(file, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
SendToAll(bot,line)
line = read(handle)
end
closefile(handle)
end
end
And.....

bot = "Pure Network"
mins = 58
file = "MsgAll2.txt"

function Main()
SetTimer(mins*60000)
StartTimer()
end

function OnTimer()
local handle = openfile(file, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
SendToAll(bot,line)
line = read(handle)
end
closefile(handle)
end
end
Just wondered if these could be made in 2 one script rather than runnin 2? Or would it make no real difference?

Thanx in advance,
Quik.
Title:
Post by: nErBoS on 08 June, 2004, 10:21:50
Hi,

Made some little changes, try out this one...

--Little changed by nErboS

bot = "PHH Hub Radio"

sec = 60
 
fMsgAll = "MsgAll.txt"
sMsgAll = ""

fMsgAll2 = "MsgAll2.txt"
sMsgAll2 = ""

tClock = {
["tMsgAll"] = clock() + 20*sec, -- Time to show in minutes
["tMsgAll2"] = clock() + 58*sec, -- Time to show in minutes
}

function Main()
sMsgAll = Readtext(fMsgAll)
sMsgAll2 = Readtext(fMsgAll2)
StartTimer()
end

function OnTimer()
if (tClock["tMsgAll"] <= clock() and sMsgAll~= "") then
tClock["tMsgAll"] = clock() + 20*sec
SendToAll(bot, sMsgAll)
end
if (tClock["tMsgAll2"] <= clock() and sMsgAll2~= "") then
tClock["tMsgAll2"] = clock() + 58*sec
SendToAll(bot, sMsgAll2)
end
end

function Readtext(file)
local sTmp = ""
if (readfrom(file) ~= nil) then
readfrom(file)
while 1 do
local sLine = read()
if (sLine == nil) then
break
else
sTmp = sTmp..sLine.."\r\n"
end
end
readfrom()
end
return sTmp
end

Best regards, nErBoS
Title:
Post by: QuikThinker on 08 June, 2004, 12:06:59
hmmmm nErBoS the only thing is the 2 bots have different names and u only accounted 4 one?
bot = "PHH Hub Radio"
bot = "Pure Network"

Or is that gonna be a problem havin 2 different named bots in the same script? :s
Title:
Post by: Herodes on 08 June, 2004, 16:39:45
QuoteOriginally posted by QuikThinker
hmmmm nErBoS the only thing is the 2 bots have different names and u only accounted 4 one?
bot = "PHH Hub Radio"
bot = "Pure Network"

Or is that gonna be a problem havin 2 different named bots in the same script? :s

It will be a problem ...
You can have as many variables as u want as long as they are not the same ...
botA =  "PHH Hub Radio"
botB = "Pure Network"

But I think u don't need them ,,,
Notice that the variable that nErBoS is using is used in the script in the following ...
Line 40 :  SendToAll(bot, sMsgAll)
Line 44: SendToAll(bot, sMsgAll2)
Title:
Post by: QuikThinker on 08 June, 2004, 17:26:57
The problem is tho that the bot name is not kept in msgall or msgall2, that info is in the script itself so surely even tho its being told 2 read 2 different txt files they will still have the same bot name "PHH Hub Radio" ?
Title:
Post by: Herodes on 08 June, 2004, 17:30:29
QuoteOriginally posted by QuikThinker
The problem is tho that the bot name is not kept in msgall or msgall2, that info is in the script itself so surely even tho its being told 2 read 2 different txt files they will still have the same bot name "PHH Hub Radio" ?
yes ... indeed ..
Title:
Post by: [UK]Madman on 08 June, 2004, 17:55:50
Slight ammendment .. 2 bot names.....


--Little changed by nErboS

bot = "PHH Hub Radio"
[B]bot2 = "Pure Network"[/B]
sec = 60
 
fMsgAll = "MsgAll.txt"
sMsgAll = ""

fMsgAll2 = "MsgAll2.txt"
sMsgAll2 = ""

tClock = {
["tMsgAll"] = clock() + 20*sec, -- Time to show in minutes
["tMsgAll2"] = clock() + 58*sec, -- Time to show in minutes
}

function Main()
sMsgAll = Readtext(fMsgAll)
sMsgAll2 = Readtext(fMsgAll2)
StartTimer()
end

function OnTimer()
if (tClock["tMsgAll"] <= clock() and sMsgAll~= "") then
tClock["tMsgAll"] = clock() + 20*sec
SendToAll(bot, sMsgAll)
end
if (tClock["tMsgAll2"] <= clock() and sMsgAll2~= "") then
tClock["tMsgAll2"] = clock() + 58*sec
[B]SendToAll(bot2, sMsgAll2)[/B]
end
end

function Readtext(file)
local sTmp = ""
if (readfrom(file) ~= nil) then
readfrom(file)
while 1 do
local sLine = read()
if (sLine == nil) then
break
else
sTmp = sTmp..sLine.."\r\n"
end
end
readfrom()
end
return sTmp
end

Title:
Post by: Herodes on 08 June, 2004, 18:07:04
Bravo Madman ,,,
I wanted to do that but I was a bit bored to ..  ;(
Sorry, lazy day  2day ...