PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: BeeR on 15 March, 2005, 17:10:11

Title: Another nice talkbot !!
Post by: BeeR on 15 March, 2005, 17:10:11
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 =((
Title:
Post by: Pothead on 15 March, 2005, 17:12:39
It's in LUA 4 , maybe.
Title:
Post by: Herodes on 15 March, 2005, 17:15:18
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
Title:
Post by: jiten on 15 March, 2005, 17:19:24
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
Title:
Post by: BeeR on 15 March, 2005, 17:59:16
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)
Title:
Post by: Herodes on 15 March, 2005, 18:23:21
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 ..
Title:
Post by: BeeR on 15 March, 2005, 18:46:43
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 :]
Title:
Post by: Herodes on 15 March, 2005, 18:49:57
QuoteOriginally posted by BeeR
works perfect now
cheers :]
yw Beer :)
Title:
Post by: jiten on 16 March, 2005, 16:15:56
sorted out mine too... there was more than one "table" ;)