MysBot = "botname"
Mode = 1
function Main()
end
Count = 0
Comments = {
"bla bla bla",
}
function DataArrival(curUser,sdata)
if Mode == 1 then
if string.sub(sdata,1,1) == "<" then
Count = Count+1
if Count == 5 then
index = random(1,table.getn(Comments))
SendToAll(MysBot, Comments[index])
Count = 0
end
end
end
if string.sub(sdata,1,1) == "<" then
sdata = string.sub(sdata,1,-2)
local _,_, command = string.find(sdata,"%b<>%s+(%S+)")
if command =="+"..MysBot.."" and curUser.bOperator then
local _,_, command,Modes = string.find(sdata,"%b<>%s+(%S+)%s+(%S+)")
if Modes == nil then
curUser:SendData(MysBot,"Commandet ?r +(Your name on the bot) . ")
return 1
end
if Modes == "on" then Mode = 1
elseif Modes == "off" then Mode = 0 end
curUser:SendData(MysBot,"Mode on comments sett to "..Modes)
return 1
end
end
end
Does any1 see whats wrong in this code - i dont =((
It's in LUA 4 , maybe.
The "DataArrival" way of handling user input is decaprecated in the newest Ptxs ... The Scripting-Interface.txt says we must do it in another way .. .
Try the one below ...
MysBot = "botname"
Mode = 1
Count = 0
Comments = {
"bla bla bla",
}
function ChatArrival( user, data )
if Mode == 1 then
Count = Count+1
if Count == 5 then
index =
SendToAll(MysBot, Comments[math.random(1,table.getn(Comments))])
Count = 0
end
end
sdata = string.sub( data , 1, -2)
local _,_, command = string.find( data, "%b<>%s+(%S+)")
if command =="+"..MysBot.."" and user.bOperator then
local _,_, command,Modes = string.find( data, "%b<>%s+(%S+)%s+(%S+)")
if Modes == nil then
user:SendData(MysBot,"Commandet ?r +"..MysBot.." . ")
return 1
end
if Modes == "on" then Mode = 1
elseif Modes == "off" then Mode = 0
end
user:SendData(MysBot,"Mode on comments sett to "..Modes)
return 1
end
end
Try this:
--Converted to LUA 5 by jiten
MysBot = "botname"
Mode = 1
function Main()
end
Count = 0
Comments = {
"bla bla bla",
}
function ChatArrival(curUser,sdata)
if Mode == 1 then
if string.sub(sdata,1,1) == "<" then
Count = Count+1
if Count == 5 then
index = math.random(1,table.getn(Comments))
SendToAll(MysBot, Comments[index])
Count = 0
end
end
end
if string.sub(sdata,1,1) == "<" then
sdata = string.sub(sdata,1,-2)
local _,_, command = string.find(sdata,"%b<>%s+(%S+)")
if command =="+"..MysBot.."" and curUser.bOperator then
local _,_, command,Modes = string.find(sdata,"%b<>%s+(%S+)%s+(%S+)")
if Modes == nil then
curUser:SendData(MysBot,"Commandet ?r +(Your name on the bot) . ")
return 1
end
if Modes == "on" then Mode = 1
elseif Modes == "off" then Mode = 0 end
curUser:SendData(MysBot,"Mode on comments sett to "..Modes)
return 1
end
end
end
QuoteOriginally posted by Pothead
It's in LUA 4 , maybe.
_________________________________________
tnx for the quick answer
Pothead it was converted to LUA5 :]
it seems to give me some error jiten
scripts\talkbot.lua:23: attempt to index field `table' (a nil value)
and on Herodes:
scripts\talkbot.lua:15: attempt to call global `random' (a nil value)
QuoteOriginally posted by BeeR and on Herodes:
scripts\talkbot.lua:15: attempt to call global `random' (a nil value)
sorted.... script in my post edited ..
QuoteOriginally posted by Herodes
QuoteOriginally posted by BeeR and on Herodes:
scripts\talkbot.lua:15: attempt to call global `random' (a nil value)
sorted.... script in my post edited ..
works perfect now
cheers :]
QuoteOriginally posted by BeeR
works perfect now
cheers :]
yw Beer :)
sorted out mine too... there was more than one "table" ;)