PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: Skynet on 02 March, 2005, 03:04:47

Title: artbot txt style
Post by: Skynet on 02 March, 2005, 03:04:47
hi can some tell me why i cant get this to work .what have i done wrong

botname = "-(LOK-BOT-LUA5)-"
lokbot = "add.txt"

function ChatArrival(user,data)
   if string.sub(data, 1, 1) == "<" then
   local data=string.sub(data,1,string.len(data)-1)
   local s,e,cmd = string.find(data, "%b<>%s+(%S+)")

      if cmd == "!add" and (user.bOperator) then
      readfrom(lokbot)
      while 1 do
         line = read()
         if line == nil then break end
         user:SendPM(botname,line)
         end
      readfrom()
      return 1
      end
   end
end

getting this error
\new hub\scripts\art.lua:10: attempt to call global `readfrom' (a nil value)
i got folder name lokbot with add.txt in it hellp
Title:
Post by: ??????Hawk?????? on 02 March, 2005, 03:29:48
try this m8




botname = "-(LOK-BOT-LUA5)-"

function ChatArrival(user,data)
if string.sub(data, 1, 1) == "<" then
local data=string.sub(data,1,string.len(data)-1)
local s,e,cmd = string.find(data, "%b<>%s+(%S+)")
if cmd == "!add" and (user.bOperator) then
AddMessage(user)
end
return 1
end
end

function AddMessage(user)  
local f,e = io.open("add.txt","r")
local message = ""
while 1 do
local line = f:read("*l")  
if line == nil then break
else
message = message..line.."\r\n"
end
end
f:close(f)
user:SendPM(botname,message)
end







??????Hawk??????
Title: wooohoo
Post by: Skynet on 02 March, 2005, 12:54:30
Thx Hawk  works well what would it need to send to main chat sorry i am still learning lua5 after geting use to lua4
Title:
Post by: bolamix on 02 March, 2005, 13:26:34
QuoteOriginally posted by Skynet
Thx Hawk  works well what would it need to send to main chat sorry i am still learning lua5 after geting use to lua4
To send to main chat, change this:user:SendPM(botname,message)to this:user:SendData(botname, message)

I think...
Title: Thx guys
Post by: Skynet on 02 March, 2005, 13:34:59
thank you so much works now simple as that lol i had wording wrong best  i start working on ascii art and adds for the hub  thankyou again :)
Skynet
land of karaoke
Title: one problem
Post by: Skynet on 02 March, 2005, 17:30:11
found one problem with it  no one can type in main chat  tryed a few things but not worked  also made a bit tidy
by adding txt to a folder :>
function AddMessage(user)  
         local f,e = io.open("images/add.txt","r")
any one out now why no one and type in main its got me
Title:
Post by: bastya_elvtars on 02 March, 2005, 17:59:29
It blocked mainchat by default. :P

Fixed (hopefully).

-- fixed by bastya_elvtars

botname = "-(LOK-BOT-LUA5)-"

function ChatArrival(user,data)
local data=string.sub(data,1,string.len(data)-1)
local s,e,cmd = string.find(data, "%b<>%s+(%S+)")
if cmd == "!add" and (user.bOperator) then
AddMessage(user)
return 1
end
end



function AddMessage(user)  
local f,e = io.open("add.txt","r")
local message = "" while 1 do
local line = f:read("*l")  
if line == nil then break
else
message = message..line.."\r\n" end
end
f:close(f)
user:SendPM(botname,message)
end
Title:
Post by: bolamix on 02 March, 2005, 18:06:46
Hiya,
To allow typing in mainchat, changefunction ChatArrival(user,data)
if string.sub(data, 1, 1) == "<" then
local data=string.sub(data,1,string.len(data)-1)
local s,e,cmd = string.find(data, "%b<>%s+(%S+)")
if cmd == "!add" and (user.bOperator) then
AddMessage(user)
end
return 1
end
end
tofunction ChatArrival(user,data)
if string.sub(data, 1, 1) == "<" then
local data=string.sub(data,1,string.len(data)-1)
local s,e,cmd = string.find(data, "%b<>%s+(%S+)")
if cmd == "!add" and (user.bOperator) then
AddMessage(user)
return 1
end
end
end
and btw the script doesn't need to check whether the 1st character is "<" since we're in ChatArrival so...function ChatArrival(user,data)
local data=string.sub(data,1,string.len(data)-1)
local s,e,cmd = string.find(data, "%b<>%s+(%S+)")
if cmd == "!add" and (user.bOperator) then
AddMessage(user)
return 1
end
end
should work even better ;)
Title:
Post by: bolamix on 02 March, 2005, 18:09:19
Oops took me longer than it did Bast... hardly surprising ^^ :D
Title: working :)
Post by: Skynet on 02 March, 2005, 18:16:14
thx great is working :)

if i am being a pain tell me tryed to edit abit more thought  i had it working and jumped the gun :>

botname = "-(LOK-BOT-LUA5)-"
LOKFolder = "images"

function ChatArrival(user,data)
local data=string.sub(data,1,string.len(data)-1)
local s,e,cmd = string.find(data, "%b<>%s+(%S+)")
cmd = string.sub(cmd, 1,string.len(cmd))
        if io.open(LOKFolder.."/"..cmd..".txt",r) ~= nil then
           AddMessage(user.cmd)
           return 1
end
end



function AddMessage(user)  
local f,e = io.open(LOKFolder.."/"..cmd..".txt","r")
local message = "" while 1 do
local line = f:read("*l")  
if line == nil then break
else
message = message..line.."\r\n" end
end
f:close(f)
user:SendPM(botname,message)
end
 

i am trying to get a folder of txt fill eg add gun etc etc to go to main for all to view like below
 
.
.                                              
.                                                         \ \ ~ ~ //
.                                                            ( 0-0 )
.                                      ----------oOO-------(_)---------------------------
.                                      
.                                      ---------------------------------oOO---------------
.                                                           I__I__I
.                                                            I I   I I
.                                                         ooO Ooo
.
.
.

Error i have now is :>
 Syntax ...nd Settings\Owner\Desktop\new hub\scripts\tester.lua:19: attempt to concatenate global `cmd' (a nil value)
Title: ascii
Post by: Skynet on 04 March, 2005, 13:07:26
sorted script to send to main for all to see posted in finish scripts for all