PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Themaster on 24 September, 2004, 01:25:15

Title: need help to my DataArrival
Post by: Themaster on 24 September, 2004, 01:25:15
this function work

function DataArrival(user,data)
      if (strsub(data,1,7) == "$MyINFO") then
Tag,Speed,Share = Parse(data)
TagCheck(Tag,Speed,Share,user)
      end

if (strsub(data, 1, 1) == "<" ) and user.bOperator then

data=strsub(data,1,strlen(data)-1)
_,_,cmd=strfind(data, "%b<>%s+(%S+)")
if not cmd then cmd = "0" end
cmd = strlower(cmd)
cmdprefix = strsub(cmd, 1,1)
if cmdprefix == "!" or cmdprefix == "+" or cmdprefix == "#" or cmdprefix == "?" then
cmd = strsub(cmd, 2,strlen(cmd))
if cmd == "say" then
_,_,as,message = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(.+)")
SendToAll(as, message)
return 1
end
end
this function not work

function DataArrival(user, data)
if (strsub(data, 1, 1) == "<" ) then
local data=strsub(data,1,strlen(data)-1)
local _,_,cmd=strfind(data, "%b<>%s+(%S+)")
local Commands = (UserCommands(user, data, cmd) or OpCommands(user, data, cmd) or MasterCommands(user, data, cmd))
return Commands
elseif (strsub(data, 1, 12) == "$OpForceMove") or (strsub(data, 1, 10) == "$ForceMove") and (user.iProfile < 0 or user.iProfile > 0)then
return 1
elseif strsub(data, 1, 5) == "$To: " then
local s, e, to = strfind(data, "$To: (%S+)")
if to ~= BotName and to ~= OpChat then
return 0
else
if to == BotName then
local data=strsub(data,1,strlen(data)-1)
local _,_,cmd = strfind(data,"$%b<>%s+(%S+)")
if user.iProfile == 1 or user.iProfile == 0 then
local Commands = (UserCommands(user, data, cmd) or OpCommands(user, data, cmd) or MasterCommands(user, data, cmd))
return Commands
end
      end
   end
   
         elseif to == OpChatName then
           if user.iProfile == 0 or user.iProfile == 1 then
            local s,e,msg = strfind(arg,"^%b<>%s+(.+)")
            OpChatRoom(user,msg)
end
      end

if (strsub(data, 1, 1) == "<" ) then
data=strsub(data,1,strlen(data)-1)
_,_,cmd=strfind(data, "%b<>%s+(%S+)")
if not cmd then cmd = "0" end
cmd = strlower(cmd)
cmdprefix = strsub(cmd, 1,1)
if cmdprefix == "!" or cmdprefix == "+" or cmdprefix == "#" or cmdprefix == "?" then
cmd = strsub(cmd, 2,strlen(cmd))
if cmd == "say" then
_,_,as,message = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(.+)")
SendToAll(as, message)
return 1
end
      end
   end
   
if (strsub(data,1,7) == "$MyINFO") then
Tag,Speed,Share = Parse(data)
TagCheck(Tag,Speed,Share,user)
end
end
i have create a command fil but it do not work :s

plz i need all the help i can get
Title:
Post by: Herodes on 24 September, 2004, 01:39:35
hey USE the  [ c o d e ] code in here [ / c o d e ]
pls keep it tidy in here we like it as much as u do  ...
Title:
Post by: Themaster on 24 September, 2004, 01:47:00
k then...can you see what i have an error on it ....

i still don't what i do wrong :s
Title:
Post by: Herodes on 24 September, 2004, 01:53:53
what is the file u are getting from like ?

is it layed out as variables ?

I mean is it like this :
acmd = "!you"
bcmd = "!can"
ccmd = "!edit"
dcmd = "!your"
ecmd = "!posts"
...?


btw it is l8 over here .. so I am off to bed ..

I am holding a friends gathering for bbq, lots of drinks and such in my house ..

any1 invited details about my location in my profile  ( lol )
Title:
Post by: Themaster on 24 September, 2004, 01:57:54
he he ok then
Title:
Post by: Herodes on 24 September, 2004, 14:28:21
what are the contents of ur commands.lua ?
Title:
Post by: Themaster on 24 September, 2004, 14:33:50
need a little help with my Commands.lua....this is not working :s...what is wrong i can't get it right
plz help me

and here are my  assert file
assert(dofile("blade/Commands.lua"))

this is my DataArrival
function DataArrival(user,data)
   if (strsub(data,1,7) == "$MyINFO") then
      Tag,Speed,Share = Parse(data)
      TagCheck(Tag,Speed,Share,user)
   end

      if (strsub(data, 1, 1) == "<" ) then
         data=strsub(data,1,strlen(data)-1)
         _,_,cmd=strfind(data, "%b<>%s+(%S+)")
         if not cmd then cmd = "0" end
         cmd = strlower(cmd)
         cmdprefix = strsub(cmd, 1,1)
         if cmdprefix == "!" or cmdprefix == "+" or cmdprefix == "#" or cmdprefix == "?" then
            cmd = strsub(cmd, 2,strlen(cmd))
            if cmd == "say" then
               _,_,as,message = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(.+)")
               SendToAll(as, message)
               return 1
            end
         end
      end

   if strsub(data, 1, 5) == "$To: " then
      local s,e,to,from,text = strfind(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s$(.*)$")
         if to == OpChat then
            if user.bOperator then
               local s,e,msg = strfind(text,"^%b<>%s+(.+)")
               OpChatRoom(user,msg)
            end
         end
      end

    if (strsub(data, 1, 1) == "<" ) then
data=strsub(data,1,strlen(data)-1)
_,_,cmd=strfind(data, "%b<>%s+(%S+)")
s,e,arg = strfind(data,"%b<>%s+%S+%s+(%S+)")
local Commands = (UserCommands(user, data, cmd) or OpCommands(user, data, cmd) or MasterCommands(user, data, cmd))
return Command
end
   end


and this is my Commands.lue

function UserCommands(user, arg, cmd)

      if cmd == "myip" then
        SendToUser(BotName, "Your IP is *** "..user.sIP)
         return 1
      elseif cmd == "version" then
         SendToAll("The Script ", "  "..Version ..Build .. Creators)
         return 1
      end
   end

function OpCommands(user,arg, cmd)

-----------------------------------------------------------------------------------------------------------------------------------------------
-- only [OPERATORS] and [MASTERS] can do the following commands

if user.iProfile == 0 or user.iProfile == 1 then
   end
end

function MasterCommands(user, arg, cmd)

-------------------------------------------------------------------------------------------------------------------------------------------------
-- only [MASTERS] can do the following commands

if user.iProfile == 0 then
   end
end


plz help me....:)
Title: still need help and try agian off it
Post by: Themaster on 26 September, 2004, 12:57:24
i can't get my command function to work.
i need some help i'm stuck on it now:s


assert(dofile("blade/Commands.lua"), "blade/Commands.lua not found")

this are in my DataArrival

  if (strsub(data,1,1) == "<") then
      data=strsub(data,1,strlen(data)-1)
      local s,v, cmd = strfind(data, "%b<>%s+(%S+)")
local Commands = (UserCommands(user, data, cmd) or OpCommands(user, data, cmd) or MasterCommands(user, data, cmd))
return Command
end
   end

and here are my Command.lua function
function UserCommands(user, arg, cmd)

      if cmd == "myip" then
        user:SendData(BotName, "Your IP is *** "..user.sIP)
         return 1
      elseif cmd == "version" then
         user:SendData("The Script ", "  "..Version ..Build .. Creators)
         return 1
      end
   end
Title:
Post by: plop on 26 September, 2004, 17:36:10
you have 2x.
if (strsub(data, 1, 1) == "<" ) thenclean up dataarival 1st, then it becomes easyer 2 see whats going wrong.

plop
Title:
Post by: Themaster on 26 September, 2004, 17:44:46
i don't that now.. and it still not working

function DataArrival(user,data)
   if (strsub(data,1,7) == "$MyINFO") then
      Tag,Speed,Share = Parse(data)
      TagCheck(Tag,Speed,Share,user)
   end

   if (strsub(data, 1, 1) == "<" ) then
      data=strsub(data,1,strlen(data)-1)
         local Commands = (UserCommands(user, data, cmd) or OpCommands(user, data, cmd) or MasterCommands(user, data, cmd))
         return Command
      else
      local s,v, cmd = strfind(data, "%b<>%s+(%S+)")
      _,_,cmd=strfind(data, "%b<>%s+(%S+)")
      if not cmd then cmd = "0" end
      cmd = strlower(cmd)
      cmdprefix = strsub(cmd, 1,1)
      if cmdprefix == "!" or cmdprefix == "+" or cmdprefix == "#" or cmdprefix == "?" then
         cmd = strsub(cmd, 2,strlen(cmd))
            if cmd == "say" then
            _,_,as,message = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(.+)")
            SendToAll(as, message)
            return 1
         end
      end
   end

   if strsub(data, 1, 5) == "$To: " then
      local s,e,to,from,text = strfind(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s$(.*)$")
         if to == OpChat then
            if user.bOperator then
               local s,e,msg = strfind(text,"^%b<>%s+(.+)")
               OpChatRoom(user,msg)
            end
         end
      end
   end
   
Title:
Post by: plop on 26 September, 2004, 19:07:13
check closely what you are doing here, added comments to help you.
  if (strsub(data, 1, 1) == "<" ) then -- if this is a mainchat msg then do the next
      data=strsub(data,1,strlen(data)-1)
      local Commands = (UserCommands(user, data, cmd) or OpCommands(user, data, cmd) or MasterCommands(user, data, cmd))
      return Command
   else -- if it's not a main chat msg then do the next
      local s,v, cmd = strfind(data, "%b<>%s+(%S+)")
      _,_,cmd=strfind(data, "%b<>%s+(%S+)") -- this line does the same as the line above
      if not cmd then
         cmd = "0"
      end
      cmd = strlower(cmd)
      cmdprefix = strsub(cmd, 1,1)
      if cmdprefix == "!" or cmdprefix == "+" or cmdprefix == "#" or cmdprefix == "?" then
         cmd = strsub(cmd, 2,strlen(cmd))
         if cmd == "say" then
            _,_,as,message = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(.+)")
            SendToAll(as, message)
            return 1
         end
      end
   end

plop
Title:
Post by: Themaster on 26 September, 2004, 19:20:29
Ok...but i still don't now what i miss on it now...It still not working..i tried anything now and i still miss something on it
Title:
Post by: Herodes on 26 September, 2004, 23:18:58
  if (strsub(data, 1, 1) == "<" ) then
      data=strsub(data,1,strlen(data)-1)
         local Commands = (UserCommands(user, data, cmd) or OpCommands(user, data, cmd) or MasterCommands(user, data, cmd))
         return Command
      else
the ' return Command ' part ...

It doesnt exist as a variable anywhere ... so it is logical that it doesnt return anything ..

and the local Commands = (UserCommands(user, data, cmd) or OpCommands(user, data, cmd) or MasterCommands(user, data, cmd)) this line in theory stands correct .. since those functions return 1 if any of the cmds is found ..

although the operation of the script halts there ..
Title:
Post by: Themaster on 27 September, 2004, 00:08:23
It do exist i can't get into main now only this coming op in the main now "wrong use read !help menu !!"
Title:
Post by: Themaster on 27 September, 2004, 21:29:55
Need still help to my Commands.lua i can't get it wright..i only got this in main wrong use read !help menu !!
Title:
Post by: plop on 27 September, 2004, 21:55:59
you had Commands and Command.
but 2 get you on your way try the next dataarival.
function DataArrival(user, data)
   if (strsub(data, 1, 1) == "<" ) then
      data=strsub(data,1,strlen(data)-1)
      local s,v, cmd = strfind(data, "%b<>%s+(%S+)")
      if cmd then
         cmd = strlower(cmd)
         local cmdprefix = strsub(cmd, 1,1)
         if cmdprefix == "!" or cmdprefix == "+" or cmdprefix == "#" or cmdprefix == "?" then
            cmd = strsub(cmd, 2,strlen(cmd))
            if cmd == "say" then
               _,_,as,message = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(.+)")
               SendToAll(as, message)
               return 1
            end
         end
      end
   end
end

plop
Title:
Post by: Themaster on 27 September, 2004, 22:05:08
it still a problem on it :s...My Commands do not come in main
Title:
Post by: bastya_elvtars on 27 September, 2004, 22:22:14
edited plops post a bit, this function must work

added some help
function DataArrival(user, data) -- fired when hub gets data from client(s)
   if (strsub(data, 1, 1) == "<" ) then -- any mainchat event
      data=strsub(data,1,strlen(data)-1) -- remove end pipe ("|")
      local _,_,cmd = strfind(data, "%b<>%s+([%!%+%#%?]%S+)") -- sees if there is a non-space string after > and it starts with ! or # or + or ?
      if cmd then -- if so then
         cmd = strlower(cmd) -- puts into lowercase ---> case-insensitive
            cmd = strsub(cmd, 2,strlen(cmd)) -- remove 1st char
            if cmd == "says" then
               local _,_,as,message = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(.+)") -- finding params
               SendToAll(as, message) -- doing job
               return 1 -- blocking appearance of command in main
            end
         end
      end
   end
Title:
Post by: Themaster on 27 September, 2004, 22:30:45
thx now i got it work...thx for all of you help i'm happy now....THX :]
Title:
Post by: Themaster on 28 September, 2004, 02:28:17
i still got a small problem with the command's
i can get 2 things working on it but when i try to pass more command's on it..then it made a syntax error
Syntax error: attempt to index global `awayArray' (a nil value)
stack traceback:
   1:  function `UserCommands' at line 14 [file `blade/Commands.lua']
   2:  function `DataArrival' at line 85 [file `...ngs\ scripts\Blade?.lua']


     if (strsub(data, 1, 1) == "<" ) then -- any mainchat event
      data=strsub(data,1,strlen(data)-1)  -- remove end pipe ("|")
      local _,_,cmd = strfind(data, "%b<>%s+([%!%+%#%?%?]%S+)")  -- sees if there is a non-space string after > and it starts with ! or # or + or ?
      if cmd then -- if so then
         cmd = strlower(cmd) -- puts into lowercase ---> case-insensitive
            cmd = strsub(cmd, 2,strlen(cmd)) -- remove 1st char
            if cmd == "says" then
               local _,_,as,message = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(.+)") -- finding params
               SendToAll(as, message) -- doing job
               return 1  -- blocking appearance of command in main
            end
         local Commands = (UserCommands(user, data, cmd) or OperatorCommands(user, data, cmd) or MasterCommands(user, data, cmd))
         return Commands
         end
      end
function UserCommands(user, data, cmd)
   if cmd == "myip" then
      user:SendData(BotName, "Your IP is *** "..user.sIP)
      return 0
   elseif cmd == "version" then
      user:SendData("The Script ", "  "..Version ..Build .. Creators)
      return 0
   elseif cmd=="away" then
      s,e,cmd,arg = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
      if (not (arg)) then
      arg = "Default away msg"
      end
      SendToAll(BotName,date("user "..user.sName.." told us at %T that he is away! He left this message: ")..arg.." .")
      awayArray[user.sName]=arg
   end
end
Title:
Post by: bastya_elvtars on 28 September, 2004, 02:52:35
inh the 1st line of your script, include this:

awayArray={}

with this, you create the table, which is a must do thing to use it :)
Title:
Post by: Themaster on 28 September, 2004, 03:03:02
no it do not work...maybe i miss something on it
Title:
Post by: Themaster on 28 September, 2004, 03:05:24
ups sry my fall
Title:
Post by: Themaster on 30 September, 2004, 20:48:45
i just wont to get some off the things on my script and now i got this
Syntax error: `end' expected (to close `if' at line 76);
  last token read: `if' at line 81 in file `...uments and Settings\den lille\Skrivebord\Hub\scripts\Blade? 1.0.lua'

No syntax errors in script file RightClicker.lua

and here are the settings there are errow on it
  if (strsub(data, 1, 1) == "<" ) then
   local data=strsub(data,1,strlen(data)-1)
   local _,_,cmd=strfind(data, "%b<>%s+([%!%+%#%?%?]%S+)")
   local Commands = UserCommands(user, data, cmd)
   return Commands
      if cmd then
         cmd = strlower(cmd)
            cmd = strsub(cmd, 2,strlen(cmd))
            if cmd == "says" then
               local _,_,as,message = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(.+)")
               SendToAll(as, message)
               return 1
            end
         end
      end

plz little bit off help
Title:
Post by: VidFamne on 30 September, 2004, 21:57:32
Quotereturn and break statements can only be written as the last statements of a block
So try to put an "end" after 'return Commands'
Title:
Post by: Themaster on 30 September, 2004, 22:12:12
now i got to work..But my OpChat it do not ?


function DataArrival(user,data)
   if (strsub(data,1,7) == "$MyINFO") then
      Tag,Speed,Share = Parse(data)
      TagCheck(Tag,Speed,Share,user)
   end

   if (strsub(data, 1, 1) == "<" ) then
   local data=strsub(data,1,strlen(data)-1)
   local _,_,prefix,cmd=strfind(data, "%b<>%s+(%S)(%S+)")
      if Tprefix[prefix] and cmd then
         prefixcmd = Tprefix[prefix]..cmd
         local Commands = UserCommands(user, data, cmd)
         return Commands
      end
   end
   
   if strsub(data, 1, 5) == "$To: " then
      local s,e,to,from,text = strfind(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s$(.*)$")
         if to == OpChat then
            if user.bOperator then
               local s,e,msg = strfind(text,"^%b<>%s+(.+)")
               OpChatRoom(user,msg)
            end
         end
      end
   end
Title:
Post by: Themaster on 02 October, 2004, 11:56:31
i got a problem now again i can't get my rules to work
it made a error

[/code]
Syntax error: attempt to call global `ShowRules' (a nil value)
stack traceback:
   1:  function `Commands' at line 24 [file `blade/Commands.lua']
   2:  function `DataArrival' at line 89 [file `...\Blade? 1.0.lua']
[/code]

and here is where is the make the error

elseif cmd == "rules" then
      ShowRules(user)
      return 1

if (strsub(data, 1, 1) == "<" ) then
   local data=strsub(data,1,strlen(data)-1)
   local _,_,prefix,cmd=strfind(data, "%b<>%s+(%S)(%S+)")
      if Tprefix[prefix] and cmd then
         prefixcmd = Tprefix[prefix]..cmd
         local Commands = Commands(user, data, cmd)
         return Commands
      end
   end


I Got this function

rules = "blade/txt/rules.txt"
network = "blade/txt/network.txt"
faq = "blade/txt/faq.txt"


function advert(message, where)
tosend = ""
border = strrep ("~", strlen (message)*2/3+2)
tosend = "\r\n\r\n"..border.."\r\n"..message.."\r\n"..border.."\r\n"
if (where == "PM") then
SendPmToAll(BotName, tosend)
else
SendToAll(BotName, tosend)
end
end

function Readtextfile(user, file)
    local filecontents = ""
local handle = openfile(file, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
        filecontents = filecontents..line.."\r\n"
line = read(handle)
end
closefile(handle)
      user:SendPM(Bot, filecontents)
end
end
Title:
Post by: Herodes on 02 October, 2004, 16:14:46
well I couldnt notice any function named ' ShowRules ' in the script parts that u provide ...

so I suspect that is the problem ...

my suggestion is to change this elseif cmd == "rules" then
      ShowRules(user)
      return 1
to elseif cmd == "rules" then
      Readtextfile(user, rules)
      return 1
Title:
Post by: Themaster on 04 October, 2004, 16:38:32
I can get another DataArrival on that i make...et get a error

this is my data

if (strsub(data, 1, 1) == "<" ) then
   local data = strsub(data,1,strlen(data)-1)
   local _,_,prefix,cmd=strfind(data, "%b<>%s+(%S)(%S+)")
      if Tprefix[prefix] and cmd then
         prefixcmd = Tprefix[prefix]..cmd
         local Commands = Commands(user, data, cmd)
         return Commands
      end
   end


and here are the next data is from kenny...

    if (strsub(data,1,1) == "<") then
    data=strsub(data,1,strlen(data)-1)
    s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if user.bOperator then
Title:
Post by: Herodes on 04 October, 2004, 19:27:33
So what is the error ?
Title:
Post by: Themaster on 13 October, 2004, 17:58:15
Help i got a wrong stoff when i log on to my hub in main.. i just wont to have word replace on my script at now this get in main when log on

[17:52:46]  $MyINFO $ALL Themaster? Blade? Creator$ $DSL$$12042852195$

here are this on my dataarrival
  replaced = nil
local newmsg = gsub(data,"(%w+)",
   function (word)
         if tWords[strlower( word )] then
replaced = 1
return tWords[strlower( word )]
else
            return word
end
end)
if replaced then
SendToAll(" "..newmsg.."|")
return 1
end
Title:
Post by: Herodes on 13 October, 2004, 18:06:13
sorry that lil bit of script doesnt help to understand what is going on ..
Title:
Post by: Themaster on 13 October, 2004, 18:28:21
here are all my Data
function DataArrival(user,data)
   if (strsub(data,1,7) == "$MyINFO") then
      Tag,Speed,Share = Parse(data)
      TagCheck(Tag,Speed,Share,user)
   end
   
   if (strsub(data, 1, 1) == "<" ) then
   local data = strsub(data,1,strlen(data)-1)
   local _,_,prefix,cmd=strfind(data, "%b<>%s+(%S)(%S+)")
      if Tprefix[prefix] and cmd then
         prefixcmd = Tprefix[prefix]..cmd
         local Commands = Commands(user, data, cmd)
         return Commands
      elseif Kennylizednicks[user.sName] == 1 then
            text=kennytext[random(1, getn(kennytext))]
SendToAll(user.sName, text)
return 1
         end
      end
   
   replaced = nil
local newmsg = gsub(data,"(%w+)",
   function (word)
         if tWords[strlower( word )] then
replaced = 1
return tWords[strlower( word )]
else
            return word
end
end)
if replaced then
SendToAll(" "..newmsg.."|")
return 1
end

   if strsub(data, 1, 5) == "$To: " then
      local s,e,to,from,text = strfind(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s$(.*)$")
         if to == OpChat then
            if user.bOperator then
               local s,e,msg = strfind(text,"^%b<>%s+(.+)")
               OpChatRoom(user,msg)
            end
         end
      end
   end
Title:
Post by: Themaster on 13 October, 2004, 18:58:32
i have made it now
Title:
Post by: Herodes on 13 October, 2004, 19:41:08
if (strsub(data,1,7) == "$MyINFO") then
      Tag,Speed,Share = Parse(data)
      TagCheck(Tag,Speed,Share,user)
   end
This can be like
  if (strsub(data,1,7) == "$MyINFO") then
      TagCheck(Parse(data),user)
   end
also this
     if Tprefix[prefix] and cmd then
         prefixcmd = Tprefix[prefix]..cmd
          local Commands = Commands(user, data, cmd)
         return Commands
can be like this
     if Tprefix[prefix] and cmd then
         prefixcmd = Tprefix[prefix]..cmd
         return Commands(user, data, cmd)
And this ...
if (to == OpChat) then
               if (user.bOperator) then
to this ..
if (to == OpChat) and (user.bOperator) then
  all the changes that I propose target to shorten the code ,...
this ofcourse has some disadvantage in reading the code ...
so while developing it is better to keep everything not so packed in like I mention ... but ofcourse thats up to you to see ...

PS : Glad you could find the problem ;)
Title:
Post by: Themaster on 13 October, 2004, 22:18:15
hmmm now i got this error when i use ? on my hub


Syntax error: table index is nil
stack traceback
1:  function `DataArrival' at line 101 [file `...den lille\Skrivebord\Hub\scripts\Blade? 1.0.lua']

function DataArrival(user,data)
   if (strsub(data,1,7) == "$MyINFO") then
      Tag,Speed,Share = Parse(data)
      TagCheck(Tag,Speed,Share,user)
   end
   
   if (strsub(data, 1, 1) == "<" ) then
   local data = strsub(data,1,strlen(data)-1)
   local _,_,prefix,cmd=strfind(data, "%b<>%s+(%S)(%S+)")
      if Tprefix[prefix] and cmd then
       [COLOR=red]  prefixcmd = Tprefix[prefix]..cmd[/COLOR]
         local Commands = Commands(user, data, cmd)
         return Commands
      elseif Kennylizednicks[user.sName] == 1 then
            text=kennytext[random(1, getn(kennytext))]
SendToAll(user.sName, text)
return 1
         end
      end
   
   replaced = nil
local newmsg = gsub(data,"(%w+)",
   function (word)
         if tWords[strlower( word )] then
replaced = 1
return tWords[strlower( word )]
else
            return word
end
end)
if replaced then
SendToAll(""..newmsg.."|")
return 1
end

   if strsub(data, 1, 5) == "$To: " then
      local s,e,to,from,text = strfind(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s$(.*)$")
         if to == OpChat then
            if user.bOperator then
               local s,e,msg = strfind(text,"^%b<>%s+(.+)")
               OpChatRoom(user,msg)
            end
         end
      end
   end

The red is there when error are
Title:
Post by: bastya_elvtars on 13 October, 2004, 22:32:59
lets see the Tprefix table
Title:
Post by: Herodes on 13 October, 2004, 22:37:28
yeah .. that variable ('prefix') is refering to an index in the table ... if the table doesnt contain the value of 'prefix' then it returns that "table index is nil" message ... simply because it isnt there ...
Title:
Post by: Themaster on 13 October, 2004, 22:38:15
--// Commands prefix
Tprefix = {
["!"]=1,
["+"]=1,
["#"]=1,
["?"]=1,
["-"]=1,
 }
Title:
Post by: Herodes on 13 October, 2004, 22:43:17
master ... try this 1 ...
change this
if Tprefix[prefix] and cmd then
to this ..
if Tprefix[prefix] ==1 then
if cmd then
Title:
Post by: Themaster on 13 October, 2004, 22:49:24
still the same error
Title:
Post by: Herodes on 13 October, 2004, 22:58:18
then try a

for i , v in tPrefix do .... end

thing ...
Title:
Post by: bastya_elvtars on 13 October, 2004, 23:03:54
local _,_,cmd=strfind(data,"%b<>%s+([%!%+%#%?%-]%S+)")
safest way, no need 4 prefix table, its like using a cannon for hunting sparrows
Title:
Post by: Themaster on 14 October, 2004, 15:27:44
i can't get it work write
Title:
Post by: Themaster on 14 October, 2004, 16:27:22
my command do not work when i chance to your's line sry
Title:
Post by: Themaster on 14 October, 2004, 17:00:32
Now i have fin out is not write in my DataArrival it do whith the first i made :S

i Realy need Some help
Title:
Post by: Themaster on 14 October, 2004, 17:41:37
i don't now why it do it when i past ? in the main it get's a nil function in ptokax...plz help
Title:
Post by: Herodes on 14 October, 2004, 18:49:48
QuoteOriginally posted by Themaster
i don't now why it do it when i past ? in the main it get's a nil function in ptokax...plz help
Uhm ... how about posting your Main() ?
Title:
Post by: Themaster on 14 October, 2004, 19:52:05
Hmm...i can't fix that error
i still have the same problem when ? come in main..how can i get it work so there are no problem ????

function Main()
   loadfile(savekicks)
   frmHub:UnregBot(BotName)
frmHub:RegBot(BotName)
   frmHub:RegBot(OpChat)
   TimeSpanInMinutes = 60
   SendToAll(BotName,"?-=-=-=-? Script Reloaded at: "..date("  %X -- %d/%m-%Y").." ?Version? "..Version.." ?Build? "..Build.." ?Creators? "..Creators.." ?-=-=-=-?")
BotNameInfo = "$MyINFO $ALL "..BotName.." <++V:1.0 Blade? 1.0,C:Themaster? $ $LAN(T3)"..strchar( 1 ).."$$"
   OpChatInfo = "$MyINFO $ALL "..OpChat.." <++V:1.0 Blade? 1.0,C:Themaster? $ $LAN(T3)"..strchar( 1 ).."$$"
   SendToAll(ScriptRestart)
   SendToAll(BotNameInfo)
   SendToAll(OpChatInfo)
SetTimer(TimeSpanInMinutes*60000)
StartTimer()
end
Title:
Post by: Herodes on 14 October, 2004, 20:00:58
oooh now I get it ... you mean the MainChat ! :)

that fault has to be data arrival ...

check the line the error happens ...
identify what variables are used ...
and make sure they all have values in them ( meaning that they should be declared at some point before that line ... )

if they have all been declared by a function
then try to make sure that the function returns real values ... (not nil)

SendToAll, SendToNick and so on should
help you "scan" through the various part and the various variable values ...
Title:
Post by: Themaster on 14 October, 2004, 20:11:39
that i mean is when i do this ? in main is get a nil in ptokax how can i fix it
Title:
Post by: Themaster on 15 October, 2004, 16:04:44
now i got what is made that error and i need help to get it write

  if (strsub(data, 1, 1) == "<" ) then
   local data = strsub(data,1,strlen(data)-1)
   local _,_,prefix,cmd=strfind(data, "%b<>%s+(%S)(%S+)")
      if Tprefix[prefix] and cmd then
         prefixcmd = Tprefix[prefix]..cmd
         local Commands = Commands(user, data, cmd)
         return Commands

Title:
Post by: bastya_elvtars on 15 October, 2004, 17:35:15
Try this!

  if (strsub(data, 1, 1) == "<" ) then

   local data = strsub(data,1,strlen(data)-1)

   local _,_,prefix,cmd=strfind(data, "%b<>%s+(.)(%S+)")

      if Tprefix[prefix] and cmd then

         prefixcmd = Tprefix[prefix]..cmd

         local Commands = Commands(user, data, cmd)

         return Commands
Title:
Post by: Themaster on 15 October, 2004, 19:00:35
i still got the same error :s
Title:
Post by: bastya_elvtars on 15 October, 2004, 19:04:00
post me the tprefix table

but already told u not 2 make a table 4 this
Title:
Post by: Themaster on 15 October, 2004, 19:06:20
i have try to get it short but it still made the error

in DataArrival

  if (strsub(data, 1, 1) == "<" ) then
   local data = strsub(data,1,strlen(data)-1)
   local _,_,prefix,cmd=strfind(data, "%b<>%s+(.)(%S+)")
      if Tprefix[prefix] and cmd then
         prefixcmd = Tprefix[prefix]..cmd
         local Commands = Commands(user, data, cmd)
         return Commands

in Setup

--// Prefix
Tprefix = {
["!"] = 1,
["+"] = 1,
["-"] = 1,
["/"] = 1,
}
Title:
Post by: VidFamne on 15 October, 2004, 19:08:33
If prefix is a control charackter you could use %c in reg.exp
Title:
Post by: Themaster on 15 October, 2004, 19:12:11
like what ?
Title:
Post by: bastya_elvtars on 15 October, 2004, 19:14:22
  if (strsub(data, 1, 1) == "<" ) then

   local data = strsub(data,1,strlen(data)-1)

   local _,_,cmd=strfind(data, "%b<>%s+(%S+)")

      if cmd and Tprefix[strsub(cmd,1,1)] then -- gets the 1st char of the cmd string and sees if its in the table

         prefixcmd = cmd

         local Commands = Commands(user, data, strsub(cmd,2,strlen(cmd))) -- stripping the prefix

         return Commands

Now some notes:

/ as prefix is bad, not all clients send it 2 hub

Dont use a table when u can use:

local _,_,cmd=strfind(data,"%b<>%s+[%!%+%-%/](%S+)) -- checks if the 1st word in main is starting with ! or - or / or +
Title:
Post by: Themaster on 15 October, 2004, 19:20:06
k...now i got it..but why can't i made so there are a table to change it else ??
Title:
Post by: bastya_elvtars on 15 October, 2004, 19:24:21
whats the use of having it all in a table? or whats the harm, if  u dont prevent users using +help instead of !help?
Title:
Post by: Themaster on 15 October, 2004, 19:37:29
Hmm....now my commands is dead !!!!
Title:
Post by: bastya_elvtars on 15 October, 2004, 19:47:10
i dont understand what u r up to so please post the entire script
Title:
Post by: Themaster on 15 October, 2004, 19:51:38
you have post this

local _,_,cmd=strfind(data,"%b<>%s+[%!%+%-%/](%S+)) -- checks if the 1st word in main is starting with ! or - or / or +

it just need a "
local _,_,cmd=strfind(data,"%b<>%s+[%!%+%-%/](%S+)") -- checks if the 1st word in main is starting with ! or - or / or +

that why it was dead
Title:
Post by: bastya_elvtars on 15 October, 2004, 20:04:38
ah sry just bought my new HDD and im moving about 100G data, so i am attending to 6 things - sry
Title:
Post by: Themaster on 15 October, 2004, 20:12:39
ok...hmm...damn now when i do +help there is nothing going on :s
Title:
Post by: Themaster on 15 October, 2004, 20:33:50
hm i can't Not get it work write now... here is my script


sec = 1000
min = 60*sec
hour = 60*min
day = 24*hour

Version ="Blade? 1.0"
Build ="?1.7?"
Creators ="Themaster?"


HubName = frmHub:GetHubName()
HubDesc = frmHub:GetHubDescr()
Redirect = frmHub:GetRedirectAddress()
MaxUsers = frmHub:GetMaxUsers()
MinShare = frmHub:GetMinShare(3)

pmArray={}
awayArray={}
MainArray={}
Symbol = { "%c", "?", "|" }
maxkicks = 3
kicks = {}
warn = {}

ScriptRestart = {}
Kennylizednicks = {}
savekicks = "blade/logs/count.kicks.txt"
WriteKickBan = "blade/logs/writekickban.txt"
rules = "blade/txt/rules.txt"
network = "blade/txt/network.txt"
Guard_File = "blade/PeerGuardian/Guarding.P2P"

function Main()
   loadfile(savekicks)
   frmHub:UnregBot(BotName)
frmHub:RegBot(BotName)
   frmHub:RegBot(OpChat)
   TimeSpanInMinutes = 60
   SendToAll(BotName,"?~~~~? Script ReStart at: "..date("  %X -- %d/%m-%Y").." ? Version ? "..Version.." ? Build ? "..Build.." ? Creators ? "..Creators.." ?~~~~?")
BotNameInfo = "$MyINFO $ALL "..BotName.." <++V:1.0 Blade? 1.0,C:Themaster? $ $LAN(T3)"..strchar( 1 ).."$$"
   OpChatInfo = "$MyINFO $ALL "..OpChat.." <++V:1.0 Blade? 1.0,C:Themaster? $ $LAN(T3)"..strchar( 1 ).."$$"
   SendToAll(ScriptRestart)
   SendToAll(BotNameInfo)
   SendToAll(OpChatInfo)
SetTimer(TimeSpanInMinutes*60000)
StartTimer()
end

function OnTimer()
SendAdMessage()
end

function SendAdMessage()
upline = "~~~~~~~~~~~~H~U~B~~S~T~A~T~S~~~~~~~~~~"
underline = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
hubstats = "\r\n\r\n"..upline.."\r\n"..
"      ?Script Version:     "..Version.."\r\n"..
       "      ?Build:     "..Build.."\r\n"..
"      ?Script Creator:     "..Creators.."\r\n"..
"      ?Hub Name:     "..HubName.."\r\n"..
"      ?Hub Description:   "..HubDesc.."\r\n"..
"      ?Hub Adress:   "..HubAdress.."\r\n"..
       "      ?Web Adress:   "..WebAdress.."\r\n"..
"      ?Owner: "..HubOwner.."\r\n"..
  "      ?Online Users: "..frmHub:GetUsersCount().."\r\n"..
"      ?Redirect Adress:   "..Redirect.."\r\n"..
"      ?Maximum Users:   "..MaxUsers.."\r\n"..
"      ?Hub Network: !network".."\r\n"..
"      ?Hub Rules:     !rules".."\r\n"..underline.."\r\n".." "

SendToAll(BotName, hubstats)
end

function DataArrival(user,data)
   if (strsub(data,1,7) == "$MyINFO") then
      Tag,Speed,Share = Parse(data)
      TagCheck(Tag,Speed,Share,user)
   end
   
   if (strsub(data, 1, 1) == "<" ) then
   local data = strsub(data,1,strlen(data)-1)
   local _,_,prefix,cmd=strfind(data, "%b<>%s+(.)(%S+)")
      if Tprefix[prefix] and cmd then
         prefixcmd = Tprefix[prefix]..cmd
         local Commands = Commands(user, data, cmd)
         return Commands

      elseif Kennylizednicks[user.sName] == 1 then
            text=kennytext[random(1, getn(kennytext))]
SendToAll(user.sName, text)
return 1
         end
      end
   
   replaced = nil
local newmsg = gsub(data,"(%w+)",
   function (word)
         if tWords[strlower( word )] then
replaced = 1
return tWords[strlower( word )]
else
            return word
end
end)
if replaced then
SendToAll(""..newmsg.."|")
return 1
end

   if strsub(data, 1, 5) == "$To: " then
      local s,e,to,from,text = strfind(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s$(.*)$")
         if to == OpChat then
            if user.bOperator then
               local s,e,msg = strfind(text,"^%b<>%s+(.+)")
               OpChatRoom(user,msg)
            end
         end
      end
   end

function NewUserConnected(user,data)
   user:SendData(" Use !help in main for your Command! ")
Connected(user)    
end
OpConnected = NewUserConnected

function OpChatRoom(user,msg)
      local allprofiles = GetProfiles()
      local index, profile, index2, nick
      for index, profile in allprofiles do
         local users = GetUsersByProfile(profile)
         for index2, nick in users do
            local usr = GetItemByName(nick)
            if usr ~= nil then
               if user.sName == usr.sName then
               else
                  if usr.iProfile == 0 or usr.iProfile == 1 or usr.iProfile == 4 then
                     usr:SendData("$To: "..usr.sName.." From: "..OpChat.." $<"..user.sName.."> "..msg)
                  end
               end
            end
         end
      end
end

function BlockGuard(ip)
   local _,_,a,b,c,d = strfind(ip "(%d*).(%d*).(%d*).(%d*)")
   if ( tonumber(a) and tonumber(b) and tonumber (c) and tonumber (d) ) then
      local uip = Computer(ip)
      if uip then
         for ranger,comp in Guard do
            local _,_,r1,r2 = strfind(ranger, "(.*)-(.*)")
            r1 = ComputeIP(r1)
            r2 = ComputeIP(r2)
            if uip>=r1 and uip <=r2 then
               return 1,comp
            end
         end
      end
   end
end

function Computer(curIP)
   local _,_,a,b,c,d = strfind (curIP, "(%d+).(%d+).(%d+).(%d+)")
   return a*16777216 + b*65536 + c+256 + d
end

function DeComputeIP(cIP)
local temp1 = mod(cIP,16777216)
local temp2 = mod(temp1,65536)
return (floor(cIP/16777216).."."..floor(temp1/65536).."."..floor(temp2/256).."."..floor(mod(temp2,256)))
end

function LoadGuard(table,file)
local handle = openfile(file, "r")
if (handle) then
    local line = read(handle)
    while line do
s,e,ind,val = strfind( line, "(.*):(.*)")
if ind and val then
table[val]=ind
end
line = read(handle)
    end
  closefile(handle)
end
end

function Readtextfile(user, file)
    local filecontents = ""
local handle = openfile(file, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
        filecontents = filecontents..line.."\r\n"
line = read(handle)
end
closefile(handle)
      user:SendPM(Bot, filecontents)
end
end

function Readtextfile(user,file)
   local filecontents = ""
   local line
   ret,err = readfrom("blade/txt/"..file)
   if ret then
      while 1 do
      line = read()
         if line == nil then
         break
         end
      filecontents = filecontents..line.."\r\n"
      end
      user:SendPM(BotName, filecontents)
      readfrom()
   else
      user:SendData(BotName, "Error: "..file.." not found")
   end
end

function WriteKickBan(what)
appendto("blade/logs/banned.txt")
write(what.."\n")
writeto()
end

function WriteKicked(what)
appendto("blade/logs/kicked.txt")
write(what.."\n")
writeto()
end

function ReadKicked(user, data)
readfrom("blade/logs/kicked.txt")
local message = ""
while 1 do
local line = read()
if line == nil then break
else
message = message..line.."\r\n"
end
end
user:SendPM(BotName, "\r\n"..message)
end

function WriteKickBan(what)
appendto("blade/logs/banned.txt")
write(what.."\n")
writeto()
end

function ReadKickBan(user, data)
readfrom("blade/logs/banned.txt")
local message = ""
while 1 do
local line = read()
if line == nil then break
else
message = message..line.."\r\n"
end
end
user:SendPM(BotName, "\r\n"..message)
end

plz test it and tell me where bug is
it still a problem with ?
Title:
Post by: bastya_elvtars on 15 October, 2004, 23:38:06
its only me that cant see Commands function?
Title:
Post by: Herodes on 16 October, 2004, 19:38:16
And also i suggest you take more care in your tabbing ...

example :function LoadGuard(table,file)
local handle = openfile(file, "r")
if (handle) then
    local line = read(handle)
    while line do
s,e,ind,val = strfind( line, "(.*):(.*)")
if ind and val then
table[val]=ind
end
line = read(handle)
    end
  closefile(handle)
end
end
would read very very bad comparing to this :function LoadGuard(table,file)
local handle = openfile(file, "r")
if (handle) then
local line = read(handle)
while line do
s,e,ind,val = strfind( line, "(.*):(.*)")
if ind and val then
table[val]=ind
end
line = read(handle)
end
  closefile(handle)
end
end


Also look out for globals ... try and keep their count to as low as possible ...example

somevariable = 1 --- this is a global

local somevariable = 1 --- this is a local


this has an impact on the memory the script consumes ...
Title:
Post by: Themaster on 21 October, 2004, 18:52:52
have a lillte problem again.
it is my word replaced i have this bot if i writ some stoff in PM then they send the replaced word to all users

replaced = nil
local newmsg = gsub(data,"(%w+)",
      function (word)
if tWords[strlower( word )] then
replaced = 1
return tWords[strlower( word )]
else
            return word
end
end)
if replaced then
SendToAll(""..newmsg.."|")
return 1
end
Title:
Post by: bastya_elvtars on 21 October, 2004, 19:05:44
this fuction probably isnt notified if the conversation goes in PM - and the SendToAll isnt a lucky choice :P
Title:
Post by: Themaster on 21 October, 2004, 19:12:01
if i do m8 in PM then they come a other PM with Mate
Sry i don't post that
Title:
Post by: Themaster on 21 October, 2004, 22:12:57
i have that code


   replaced = nil
local newmsg = gsub(data,"(%w+)",
      function (word)
if tWords[strlower( word )] then
replaced = 1
return tWords[strlower( word )]
else
            return word
end
end)
if replaced then
SendToAll(""..newmsg.."|")
return 1
end
   

if i do 1 off the thing in word replace in PM then it show it to all...and that i have a problem i just only want 2 have in main