Jump to content

[REL] Censorship system 1.0.0


dukenukem

Recommended Posts

  • Discord Moderators

mutha fucka is in the censorship words but mother fucker isn't.

Isn't it just slang? :D

Also, I personally consider muffdiver a compliment rather something else.

Can't associate it with something bad!

Link to comment
  • Discord Moderators

I made a version for you (thanks to wiki for help)

local censored = { 
'technocrane', 
'teletubbie', 
'nebula' 
-- ... your censored words here 
} 
  
function Check(funcname, ...) 
    local arg = {...} 
  
    if (type(funcname) ~= "string") then 
        error("Argument type mismatch at 'Check' ('funcname'). Expected 'string', got '"..type(funcname).."'.", 2) 
    end 
    if (#arg % 3 > 0) then 
        error("Argument number mismatch at 'Check'. Expected #arg % 3 to be 0, but it is "..(#arg % 3)..".", 2) 
    end 
  
    for i=1, #arg-2, 3 do 
        if (type(arg[i]) ~= "string" and type(arg[i]) ~= "table") then 
            error("Argument type mismatch at 'Check' (arg #"..i.."). Expected 'string' or 'table', got '"..type(arg[i]).."'.", 2) 
        elseif (type(arg[i+2]) ~= "string") then 
            error("Argument type mismatch at 'Check' (arg #"..(i+2).."). Expected 'string', got '"..type(arg[i+2]).."'.", 2) 
        end 
  
        if (type(arg[i]) == "table") then 
            local aType = type(arg[i+1]) 
            for _, pType in next, arg[i] do 
                if (aType == pType) then 
                    aType = nil 
                    break 
                end 
            end 
            if (aType) then 
                error("Argument type mismatch at '"..funcname.."' ('"..arg[i+2].."'). Expected '"..table.concat(arg[i], "' or '").."', got '"..aType.."'.", 3) 
            end 
        elseif (type(arg[i+1]) ~= arg[i]) then 
            error("Argument type mismatch at '"..funcname.."' ('"..arg[i+2].."'). Expected '"..arg[i].."', got '"..type(arg[i+1]).."'.", 3) 
        end 
    end 
end 
  
function string.explode(self, separator) 
    Check("string.explode", "string", self, "ensemble", "string", separator, "separator") 
  
    if (#self == 0) then return {} end 
    if (#separator == 0) then return { self } end 
  
    return loadstring("return {\""..self:gsub(separator, "\",\"").."\"}")() 
end 
  
function string.nail (chat) 
    local exString = string.explode (chat, ' ') 
        for k, v in ipairs (exString) do 
            for j, s in ipairs (censored) do 
                if v == s then 
                    outputChatBox ('someone do something, '..tostring (getPlayerName (source))..' just said '..v..'!') -- your action here 
                end 
            end 
        end 
end 
addEventHandler ('onPlayerChat', root, string.nail) 

the code separates all words in a chat message into a table, and matches the values in 'censored' table with any of them, using loops.

this way probably isn't very good, rather use string.find to catch people saying 'goddamnit' while only having 'goddamn' listed

just an example to show you this doesn't have to fill 600 lines

as a suggestion, you could maybe cancelEvent onPlayerChat and outputChatBox the message with the word censored, warning the player, for a less violent way.

Your current way is pretty rough :P

Link to comment
I made a version for you (thanks to wiki for help)
local censored = { 
'technocrane', 
'teletubbie', 
'nebula' 
-- ... your censored words here 
} 
  
function Check(funcname, ...) 
    local arg = {...} 
  
    if (type(funcname) ~= "string") then 
        error("Argument type mismatch at 'Check' ('funcname'). Expected 'string', got '"..type(funcname).."'.", 2) 
    end 
    if (#arg % 3 > 0) then 
        error("Argument number mismatch at 'Check'. Expected #arg % 3 to be 0, but it is "..(#arg % 3)..".", 2) 
    end 
  
    for i=1, #arg-2, 3 do 
        if (type(arg[i]) ~= "string" and type(arg[i]) ~= "table") then 
            error("Argument type mismatch at 'Check' (arg #"..i.."). Expected 'string' or 'table', got '"..type(arg[i]).."'.", 2) 
        elseif (type(arg[i+2]) ~= "string") then 
            error("Argument type mismatch at 'Check' (arg #"..(i+2).."). Expected 'string', got '"..type(arg[i+2]).."'.", 2) 
        end 
  
        if (type(arg[i]) == "table") then 
            local aType = type(arg[i+1]) 
            for _, pType in next, arg[i] do 
                if (aType == pType) then 
                    aType = nil 
                    break 
                end 
            end 
            if (aType) then 
                error("Argument type mismatch at '"..funcname.."' ('"..arg[i+2].."'). Expected '"..table.concat(arg[i], "' or '").."', got '"..aType.."'.", 3) 
            end 
        elseif (type(arg[i+1]) ~= arg[i]) then 
            error("Argument type mismatch at '"..funcname.."' ('"..arg[i+2].."'). Expected '"..arg[i].."', got '"..type(arg[i+1]).."'.", 3) 
        end 
    end 
end 
  
function string.explode(self, separator) 
    Check("string.explode", "string", self, "ensemble", "string", separator, "separator") 
  
    if (#self == 0) then return {} end 
    if (#separator == 0) then return { self } end 
  
    return loadstring("return {\""..self:gsub(separator, "\",\"").."\"}")() 
end 
  
function string.nail (chat) 
    local exString = string.explode (chat, ' ') 
        for k, v in ipairs (exString) do 
            for j, s in ipairs (censored) do 
                if v == s then 
                    outputChatBox ('someone do something, '..tostring (getPlayerName (source))..' just said '..v..'!') -- your action here 
                end 
            end 
        end 
end 
addEventHandler ('onPlayerChat', root, string.nail) 

the code separates all words in a chat message into a table, and matches the values in 'censored' table with any of them, using loops.

this way probably isn't very good, rather use string.find to catch people saying 'goddamnit' while only having 'goddamn' listed

just an example to show you this doesn't have to fill 600 lines

as a suggestion, you could maybe cancelEvent onPlayerChat and outputChatBox the message with the word censored, warning the player, for a less violent way.

Your current way is pretty rough :P

heh :P good thanks but i want too make

Player say: f**k

* - when you say it you dont get mute but **** censor

Link to comment

heh :P good thanks but i want too make

Player say: f**k

* - when you say it you dont get mute but **** censor

function wordCensor(word) 
  local asterisk = "*" 
  local hide = word:sub(2, #word-1) 
  return word:gsub(hide, asterisk:rep(#hide)) 
end 

for example: wordCensor("banana") will return b****a

Link to comment

heh :P good thanks but i want too make

Player say: f**k

* - when you say it you dont get mute but **** censor

function wordCensor(word) 
  local asterisk = "*" 
  local hide = word:sub(2, #word-1) 
  return word:gsub(hide, asterisk:rep(#hide)) 
end 

for example: wordCensor("banana") will return b****a

heh. I wanted to do it yourself :D

Link to comment

heh :P good thanks but i want too make

Player say: f**k

* - when you say it you dont get mute but **** censor

function wordCensor(word) 
  local asterisk = "*" 
  local hide = word:sub(2, #word-1) 
  return word:gsub(hide, asterisk:rep(#hide)) 
end 

for example: wordCensor("banana") will return b****a

heh. I wanted to do it yourself :D

yuo still have a lot to do :P

Link to comment
  • 4 weeks later...

Nice resource man, thanks for it, I've got one problem; when I get muted, I am still able to talk?o.O

EDIT: Oh man, sorry for this post, didn't read well. Thank you very much man! It works :D 5/5

EDIT2: Hmmm, thought it worked, but when you put a word like 'mf' in the list, and someone says amfitamin (is that a word?)

you'll still get muted...

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...