PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: KillerOfDay on 13 June, 2005, 13:39:32

Title: error in word replace lua
Post by: KillerOfDay on 13 June, 2005, 13:39:32
Hi

i have this word replace in lua but there is an error in the script

Quote-- PtokaX Lua 5 version by PPK



-- Naruto www.narutodc.tk

-- Body by plop thx to him



-- This script stops the ***** words :) It has some words saved..

-- Plz if you know new words plz add them or go to my homepage and tell me..

-- Languages:  English

-- Version 1.0





---------------------------------------------------------------------------------------------



---- filter what? use 1 to enable, nil to disable the filter.

FilterPm = 1

FilterMain = 1



---- the words to be replaced and by what.

tBadWords = {

      ["ciao"]= "prova",
   
}



---- the words to be replaced and by what (function mode).

tBadFuncs = {

   -- replace lol with a random amount of o's

   ["lol"] = function()

      local i = math.random(1,20)

      return "L"..(string.rep("o", i)).."L"

   end

}



-- prefixes table, allowed for me and let commands bypase the replacer

tPre = { ["+"] = 1, ["!"] = 1, ["/"] = 1, ["-"]=1 }



function Main()

   local num = string.gsub(os.date(), "%D", "")

   math.randomseed(tonumber(num))

end



function CheckWord(word)

   local wordl = string.lower(word)

   if tBadWords[wordl] then

      return tBadWords[wordl]

   elseif tBadFuncs[wordl] then

      return tBadFuncs[wordl]()

   else

      return word

   end

end



function ChatArrival(user, data)

   if FilterMain then

      local s,e,data =string.find(string.sub(data, 1, (string.len(data)-1)), "%b<>%s+(.*)")

      local data,c = string.gsub(data , "(%w+)", function(word) return CheckWord(word) end)

      local s,e,pre, cmd = string.find(data, "^%s*(%W)(%S+)")

      if c ~= 0 then

         if pre and tPre
 then

            if cmd == "me" then

               SendToAll("* "..user.sName.." "..string.sub(data, 5, string.len(data)).."|")

               return 1

            else

               return 0

            end

         else

            SendToAll(user.sName, data.."|")

            return 1

         end

      end

   end

end



function ToArrival(user, data)

   if FilterPm then

      local s,e,whoto = string.find(data, "%S+%s*(%S+)")

      local s,e,data = string.find(strsub(data, 1, (string.len(data)-1)), "$%b<>%s*(.*)$")

      local data,c=string.gsub(data , "(%S+)", function(word) return CheckWord(word) end)

      if c ~= 0 then

         SendPmToNick(whoto, user.sName, data.."|")

         return 1

      end

   end

end


with ptokax 0.3.3.1 error is:
scripts\wordreplace.lua:153: attempt to call global `strsub' (a nil value)

how can I correct it?

Then for the pm it doesn't work, what it needs to add?

thanks  ;)
Title:
Post by: Dessamator on 13 June, 2005, 14:00:41
local s,e,data = string.find(strsub(data, 1, (string.len(data)-1)), "$%b<>%s*(.*)$")

thats the line, next time when u post show us what line, anyways, change "strsub" to string.sub !
Title: Replace...
Post by: Scanning on 13 June, 2005, 14:01:09
Replace strsub with string.sub in

local s,e,data = string.find(strsub (data, 1, (string.len(data)-1)), "$%b<>%s*(.*)$")


Ahh, me slooooow :-)
Title:
Post by: plop on 13 June, 2005, 18:45:28
here (http://ptxscriptdb.psycho-chihuahua.net/download.php?view.22) you can find a version which is fully made by me.
has some extra features, like adding words while running.

plop
Title:
Post by: dragos_sto on 20 June, 2005, 00:26:04
plop nice script
keep going in your work
Title:
Post by: plop on 20 June, 2005, 07:33:57
QuoteOriginally posted by dragos_sto
plop nice script
keep going in your work

thanx.
i won't stop as i still have 2 much plans for things 2 make.

plop