PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Ron_Doe on 23 October, 2003, 18:32:20

Title: Chat Bot problems
Post by: Ron_Doe on 23 October, 2003, 18:32:20
Getting a error message when i am using  this script : Syntax Error bad argument #1 to `strlen (string expected, got nil)

Can anybody help me with this  ??
-----------------------------------------------------
-- Chat Bot v3.5 Coded by   [aXs] Wellx   01/09-03
-- Formerly known as the Developer-Chat for TIC50
-- Based on the idea VIPChat from Piglja
-- Thx goes to Piglja & aMutex for Ideas and Help
-----------------------------------------------------

ChatBot = "[ChatRum]" -- Chat Bot Name
CanUseCommands = { -1 , 0 , 1 , 2 , 3 } -- Can Use Chat Bot Commands Lvl ( 0 = Master ~~ 1 = Operators ~~ 2 = VIPs ~~ 3 = Reg ~~ etc.)

ChatArray={}
ChatFile = "Chatters.tbl"

function Main()
frmHub:RegBot(ChatBot)
ChatArray = LoadFromFile(ChatFile)
end

--========================================================    DataArrival:    =========================================================--

function DataArrival(user, data)
if (strsub(data, 1, 1) == "<" ) then
data=strsub(data,1,strlen(data)-1)
_,_,cmd=strfind(data, "%b<>%s+(%S+)")
local Commands = (DeveloperCommands(user, data, cmd))
return Commands
elseif strsub(data, 1, 5) == "$To: " then
local s, e, to = strfind(data, "$To: (%S+)")
if to ~= ChatBot then
return 0
else
if to == ChatBot then
local data=strsub(data,1,strlen(data)-1)  
local s,e,from,msg = strfind(data,"From:%s+(%S+)%s+$%b<>%s+(.+)")  
if ChatArray[user.sName] ~= nil then
ChatArray[user.sName] = nil
for i,v in ChatArray do
Developer=GetItemByName(i)
if (Developer~=nil) then
Developer:SendData("$To: "..i.." From: "..ChatBot.." $<"..user.sName.."> "..msg.."|")
end
end
ChatArray[user.sName] = user.sName
else
user:SendPM(ChatBot,"You do not have permission to write inhere (Join or Talk to a Operator if you need permission)")
end
local _,_,cmd = strfind(data,"$%b<>%s+(%S+)")
local Commands = (DeveloperCommands(user, data, cmd))
end
end
end
end

--=====================================================      Chat Commands:      ======================================================--

function DeveloperCommands(user, data, cmd)
if tfind(CanUseCommands, user.iProfile) then
if (cmd == "+chathelp") then
DevHelp(user)
return 1
elseif (cmd == "+chat") then
local s,e,cmd,ChatName = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
if (ChatName == nil) then
ChatName = user.sName
end
if ChatArray[ChatName] == nil then
ChatArray[ChatName] = ChatName
for index, value in ChatArray do
SendPmToNick(index, ChatBot, "  "..ChatName.." Has joined the "..ChatBot)
end
else
for index, value in ChatArray do
SendPmToNick(index, ChatBot, "  "..ChatName.." Has left the "..ChatBot)
end
ChatArray[ChatName] = nil
end
SaveToFile(ChatName,ChatFile,ChatArray)
return 1
elseif (cmd == "+showchatters") then
function DevList()
local DevList = ""
for index, value in ChatArray do
local line = index
if GetItemByName(index) then
if (strlen(index) <= 10) then
DevList = DevList.." ? "..line.."\t\t\t~ On-line ~\r\n"
else
DevList = DevList.." ? "..line.."\t\t~ On-line ~\r\n"
end
else
if (strlen(index) <= 10) then
DevList = DevList.." ? "..line.."\t\t\t? Off-Line ?\r\n"
else
DevList = DevList.." ? "..line.."\t\t? Off-Line ?\r\n"
end
end
end
return DevList
end
user:SendPM(ChatBot, "\r\n\r\n(? ?.??.->      "..ChatBot.." Chatters      <-.??.???) \r\n\r\n"..DevList())
return 1
end
else user:SendData("You don't have permission to use the commands to the "..ChatBot.." ask a Operator for permission !!") return 0 end
end

function DevHelp (user)
local disp = "\r\n\r\n"
disp = disp.."~~ Scripted DeveloperChat Commands: ~~\r\n\r\n"
disp = disp.."   +chat - Add or part a user to the list of people that can chat in the "..ChatBot.."\r\n"
disp = disp.."   +showchatters - See witch users that can chat in the "..ChatBot.."\r\n"
disp = disp.."\r\n"
user:SendPM(ChatBot, disp)
end

--========================================================    Functions:    ===========================================================--

function SaveToFile(arg,file,table)
local aString = pickle(table)
writeto(file)
write(aString)
writeto()
end

function LoadFromFile(file)
readfrom(file)
local aString = read("*all")
return  unpickle(aString)
end

function tfind(table, key)
return foreachi(table, function(id, tmp) return (tmp == %key) and id end)
end

----------------------------------------------
-- Pickle.lua
-- An table serialization utility for lua
-- Steve Dekorte, http://www.dekorte.com, Apr 2000
-- Freeware
----------------------------------------------
function pickle(t)
return Pickle:clone():pickle_(t)
end

Pickle = {
clone = function (t) local nt={}; for i, v in t do nt[i]=v end return nt end
}

function Pickle:pickle_(root)
if type(root) ~= "table" then
error("can only pickle tables, not ".. type(root).."s")
end
self._tableToRef = {}
self._refToTable = {}
local savecount = 0
self:ref_(root)
local s = ""
while getn(self._refToTable) > savecount do
savecount = savecount + 1
local t = self._refToTable[savecount]
s = s.."{\n"
for i, v in t do
s = format("%s[%s]=%s,\n", s, self:value_(i), self:value_(v))
end
s = s.."},\n"
end
return format("{%s}", s)
end

function Pickle:value_(v)
local vtype = type(v)
if vtype == "string" then return format("%q", v)
elseif vtype == "number" then return v
elseif vtype == "table" then return "{"..self:ref_(v).."}"
else --error("pickle a "..type(v).." is not supported")
end  
end

function Pickle:ref_(t)
local ref = self._tableToRef[t]
if not ref then
if t == self then error("can't pickle the pickle class") end
tinsert(self._refToTable, t)
ref = getn(self._refToTable)
self._tableToRef[t] = ref
end
return ref
end

----------------------------------------------
-- unpickle
----------------------------------------------

function unpickle(s)
if type(s) ~= "string" then
error("can't unpickle a "..type(s)..", only strings")
end
local tables = dostring("return "..s)
for tnum = 1, getn(tables) do
local t = tables[tnum]
local tcopy = {}; for i, v in t do tcopy[i] = v end
for i, v in tcopy do
local ni, nv
if type(i) == "table" then ni = tables[i[1]] else ni = i end
if type(v) == "table" then nv = tables[v[1]] else nv = v end
t[ni] = nv
end
end
return tables[1]
end



Ron
Title:
Post by: BlazeXxX on 23 October, 2003, 19:00:23
Create a File called Chatters.tbl in the same directory as this script is running ...

There is no file called Chatters.tbl , thats why its giving u that error...

Once u created it, restart the scripts and see :)
Title:
Post by: Alexei on 23 October, 2003, 19:09:39
Well its supposed to creat it itself... as far as i know.... ?(
Title:
Post by: BlazeXxX on 23 October, 2003, 19:11:55
Nope... I remember piglja saying, to create manually .. Cuz i got the same pbm wen i tried it...
Title:
Post by: raz on 23 October, 2003, 19:16:43
in ur script u r missing ) which ends the string dats y i have added them in but i am new at this myself. if there is a mistake just tell and will try 2 fix it.

-----------------------------------------------------
-- Chat Bot v3.5 Coded by   [aXs] Wellx   01/09-03
-- Formerly known as the Developer-Chat for TIC50
-- Based on the idea VIPChat from Piglja
-- Thx goes to Piglja & aMutex for Ideas and Help
-----------------------------------------------------

ChatBot = "[ChatRum]"   -- Chat Bot Name
CanUseCommands = { -1 , 0 , 1 , 2 , 3 }   -- Can Use Chat Bot Commands Lvl ( 0 = Master ~~ 1 = Operators ~~ 2 = VIPs ~~ 3 = Reg ~~ etc.)

ChatArray={}
ChatFile = "Chatters.tbl"

function Main()
frmHub:RegBot(ChatBot)
ChatArray = LoadFromFile(ChatFile)
end

--========================================================    DataArrival:    =========================================================--

function DataArrival(user, data)
   if (strsub(data, 1, 1) == "<" ) then
   data=strsub(data,1,strlen(data)-1)
   _,_,cmd=strfind(data, "%b<>%s+(%S+)")
   local Commands = (DeveloperCommands(user, data, cmd))
   return Commands
   elseif strsub(data, 1, 5) == "$To: " then
      local s, e, to = strfind(data, "$To: (%S+)")
      if to ~= ChatBot then
         return 0
      else
         if to == ChatBot then
         local data=strsub(data,1,strlen(data)-1)  
         local s,e,from,msg = strfind(data,"From:%s+(%S+)%s+$%b<>%s+(.+)")  
            if ChatArray[user.sName] ~= nil then
            ChatArray[user.sName] = nil
               for i,v in ChatArray do
               Developer=GetItemByName(i)
                  if (Developer~=nil) then
                  Developer:SendData("$To: "..i.." From: "..ChatBot.." $<"..user.sName.."> "..msg.."|")
                  end
               end
            ChatArray[user.sName] = user.sName
            else
            user:SendPM(ChatBot,"You do not have permission to write inhere (Join or Talk to a Operator if you need permission)")
            end
         local _,_,cmd = strfind(data,"$%b<>%s+(%S+)")
         local Commands = (DeveloperCommands(user, data, cmd))
         end
      end
   end
end

--=====================================================      Chat Commands:      ======================================================--

function DeveloperCommands(user, data, cmd)
   if tfind(CanUseCommands, user.iProfile)then
      if (cmd == "+chathelp") then
      DevHelp(user)
      return 1
      elseif (cmd == "+chat") then
      local s,e,cmd,ChatName = strfind( data, "%b<>%s+(%S+)%s+(.*)")
         if (ChatName == nil) then
         ChatName = user.sName
         end
         if ChatArray[ChatName] == nil then
         ChatArray[ChatName] = ChatName
            for index, value in ChatArray do
            SendPmToNick(index, ChatBot, "  "..ChatName.." Has joined the "..ChatBot)
            end
         else
            for index, value in ChatArray do
            SendPmToNick(index, ChatBot, "  "..ChatName.." Has left the "..ChatBot)
            end
         ChatArray[ChatName] = nil
         end
         SaveToFile(ChatName,ChatFile,ChatArray)
         return 1
      elseif (cmd == "+showchatters") then
         function DevList()
         local DevList = ""
            for index, value in ChatArray do
            local line = index
               if GetItemByName(index) then
                  if (strlen(index) <= 10) then
                  DevList = DevList.." ? "..line.."\t\t\t~ On-line ~\r\n"
                  else
                  DevList = DevList.." ? "..line.."\t\t~ On-line ~\r\n"
                  end
               else
                  if (strlen(index) <= 10) then
                  DevList = DevList.." ? "..line.."\t\t\t? Off-Line ?\r\n"
                  else
                  DevList = DevList.." ? "..line.."\t\t? Off-Line ?\r\n"
                  end
               end
            end
            return DevList
         end
         user:SendPM(ChatBot, "\r\n\r\n(? ?.??.->      "..ChatBot.." Chatters      <-.??.???) \r\n\r\n"..DevList())
         return 1
      end
   else user:SendData("You don't have permission to use the commands to the "..ChatBot.." ask a Operator for permission !!") return 0 end
end

function DevHelp (user)
   local disp = "\r\n\r\n"
   disp = disp.."~~ Scripted DeveloperChat Commands: ~~\r\n\r\n"
   disp = disp.."   +chat       -   Add or part a user to the list of people that can chat in the "..ChatBot.."\r\n"
   disp = disp.."   +showchatters      -   See witch users that can chat in the "..ChatBot.."\r\n"
   disp = disp.."\r\n"
   user:SendPM(ChatBot, disp)
end

--========================================================    Functions:    ===========================================================--

function SaveToFile(arg,file,table)
   local aString = pickle(table)
   writeto(file)
   write(aString)
   writeto()
end

function LoadFromFile(file)
   readfrom(file)
   local aString = read("*all")
   return  unpickle(aString)
end

function tfind(table, key)
return foreachi(table, function(id, tmp) return (tmp == %key) and id end)
end

----------------------------------------------
-- Pickle.lua
-- An table serialization utility for lua
-- Steve Dekorte, http://www.dekorte.com, Apr 2000
-- Freeware
----------------------------------------------
function pickle(t)
return Pickle:clone():pickle_(t)
end

Pickle = {
clone = function (t) local nt={}; for i, v in t do nt=v end return nt end
}

function Pickle:pickle_(root)
   if type(root) ~= "table" then
   error("can only pickle tables, not ".. type(root).."s")
   end
   self._tableToRef = {}
   self._refToTable = {}
   local savecount = 0
   self:ref_(root)
   local s = ""
   while getn(self._refToTable) > savecount do
   savecount = savecount + 1
   local t = self._refToTable[savecount]
   s = s.."{\n"
      for i, v in t do
      s = format("%s[%s]=%s,\n", s, self:value_(i), self:value_(v))
      end
   s = s.."},\n"
   end
return format("{%s}", s)
end

function Pickle:value_(v)
local vtype = type(v)
   if vtype == "string" then return format("%q", v)
   elseif vtype == "number" then return v
   elseif vtype == "table" then return "{"..self:ref_(v).."}"
   else --error("pickle a "..type(v).." is not supported"
   end  
end

function Pickle:ref_(t)
local ref = self._tableToRef[t]
   if not ref then
      if t == self then error("can't pickle the pickle class") end
   tinsert(self._refToTable, t)
   ref = getn(self._refToTable)
   self._tableToRef[t] = ref
   end
return ref
end

----------------------------------------------
-- unpickle
----------------------------------------------

function unpickle(s)
   if type(s) ~= "string" then
   error("can't unpickle a "..type(s)..", only strings")
   end
   local tables = dostring("return "..s)
   for tnum = 1, getn(tables) do
   local t = tables[tnum]
   local tcopy = {}; for i, v in t do tcopy = v end
      for i, v in tcopy do
      local ni, nv
         if type(i) == "table" then ni = tables[i[1]] else ni = i end
         if type(v) == "table" then nv = tables[v[1]] else nv = v end
      t[ni] = nv
      end
   end
return tables[1]
end
Title:
Post by: raz on 23 October, 2003, 19:19:14
sorry i can't do code thing but the script works on my hub. u might need 2 make a table file but the script works fine. :D
Title:
Post by: BlazeXxX on 23 October, 2003, 19:21:13
Yup This version would work fine, if u create the tbl file manually..

It works fine for me :D
Title:
Post by: raz on 23 October, 2003, 19:28:43
this version creates a table file itself. i don't think u need 2 make 1 manually. cuz when i fixed the scirpt and put it on my hub 2 c if its right. it worked and said u need a table file but then a tbl file got created itself without the need of me making 1 manuaaly  and all i did was chat in the chatroom. so u don't need 2 with dis.
Title:
Post by: BlazeXxX on 23 October, 2003, 19:30:24
Ohhh I didn't know that :p I just did it manually :D
Title:
Post by: raz on 23 October, 2003, 19:32:51
r u using this script or a different 1. :D
Title:
Post by: Ron_Doe on 23 October, 2003, 20:03:51
It worked ok  for me too at the beginning    but keep a eye on the script editor   and look for the error message.
If the error message does not appear   i might just try another script...
... i just changed the name in the hub   +chat---> !dungeon   and so on     could this have something to do with the error message ??  


Ron
Title:
Post by: raz on 23 October, 2003, 20:17:10
ron  +chat is how u get added in to the chat room. when u do !dungeon do u still get added in to the chat room.
Title:
Post by: raz on 23 October, 2003, 20:17:52
anyway have u tried the 1 i posted up.
Title:
Post by: Ron_Doe on 23 October, 2003, 20:33:20
Yep    the !dungeon  worked     i got in the chat  ,  it worked fine  i just got error messages.

btw   the one you posted  is showing me everything 2 times   :-)

(? ?.??.-> Dungeon Watchers <-.??.???)

 ? Mr.T         ~ On-line ~
 ? Ron_Doe         ~ On-line ~

[20:31]

(? ?.??.->      Dungeon Watchers      <-.??.???)

 ? Mr.T         ~ On-line ~
 ? Ron_Doe         ~ On-line ~

but as i write  i have not got a single error message      :D
Title:
Post by: raz on 23 October, 2003, 20:36:39
cool. i will try 2 fix it if i can. i am also a new person.i only joined this on 20th october. so i don't know alot but i will see if i can fix.
Title:
Post by: Ron_Doe on 23 October, 2003, 20:57:25
lol      i forgot to erase the old vip chat   that's why i got everything 2 times   lol

i am watching now  if the error message appear..
 
Ron


The only thing i can see different is that  i got ?  instead of  a little dot
Title:
Post by: raz on 23 October, 2003, 21:01:50
lolz i was wondering how come u were getting 2 instead of 1. no matter anyway i don't thing u r going 2 recieve any errors if u was going 2 then u would have already recieved dem.
Title: Chat Bot v3.5 Coded by [aXs] Wellx
Post by: [G-T-E]Gate? on 04 February, 2004, 09:37:03
Read the threads on this bot and saw that a chatter.tbl has to be created in the scripts folder where the script is.
A question to those that know the reply ,,
 How to make a chatter.tlb file Please?
 :(
Title:
Post by: [G-T-E]Gate? on 04 February, 2004, 09:42:28
Another thing just occured, Iam Master  and when I write !chathelp or !showchatters I get the following responce>>
<[G-T-E]Gate?> !chathelp
<[SFS][V??]ChatR??m> You do not have permission to write in here (Join or Talk to a Operator if you need permission)
<[SFS][V??]ChatR??m> rnrn~~ Scripted DeveloperChat Commands: ~~rnrn   !chat        -    Add or part a user to the list of people that can chat in the [SFS][V??]ChatR??mrn   !showchatters        -    See witch users that can chat in the [SFS][V??]ChatR??mrnrn
<[G-T-E]Gate?> !showchatters
<[SFS][V??]ChatR??m> You do not have permission to write in here (Join or Talk to a Operator if you need permission)
<[SFS][V??]ChatR??m> rnrn(? ?.??.->      [SFS][V??]ChatR??m Chatters      <-.??.???) rnrn

Tks again , [G-T-E]Gate?  ;)
Title: Need Help Please ChatBot
Post by: [G-T-E]Gate? on 04 February, 2004, 11:19:23
Can someone please tell me how to make a chatter.tbl file and why I get up the following when Iam Master i the hub ,,
<[G-T-E]Gate?> !chathelp
<[SFS][V??]ChatR??m> You do not have permission to write in here (Join or Talk to a Operator if you need permission)
 Tks ..
Title:
Post by: BlazeXxX on 04 February, 2004, 12:09:38
Hi there,
The chatter.tbl will be created automatically wen u type +chat in main chat. That msg came up since u are not logged into the chat system. Type +chat to join or part.

Hope that helps!

L8R,
BlazeXxX
Title:
Post by: [G-T-E]Gate? on 04 February, 2004, 12:11:52
Thanks Loads Blaze
Title: Syntex Error ChatBot
Post by: [G-T-E]Gate? on 04 February, 2004, 12:20:33
Iam getting a
Syntex Error bad argument #1 to `string?[string expected,got nil]
Any help please
Title:
Post by: BlazeXxX on 04 February, 2004, 12:22:29
Hi there,
Wen u type +chat for the first time, it will give u error i think. Restart ur Scripts (NOT UR HUB). and see if u still getting this error.

L8R