Jump to content

Antiinsult


Recommended Posts

Sure, show me the code.

Words = {"bitch", 
         "gay" 
         } 
  
  
    addEventHandler("onPlayerChat", getRootElement(), 
    function(msg, msgType) 
            for k,v in ipairs (Words) do 
    if string.find(msg,v) then 
                    cancelEvent() 
            pName = getPlayerName(source) 
            outputChatBox("INFO: #ffffff[#00ff00 Console#ffffff ]#ff0000 set mute to #ffff00"..pName.." ",getRootElement(),255,0,0,true) 
            setPlayerMuted(source, true) 
            setTimer (function (  ) 
            setPlayerMuted (source, false ) 
            end, 
            300000,1, source ) 
            end 
        end 
end 
) 

Link to comment

I don't want it to mute player, i want to replace the word by another one like example

Bitch replace with lady.

lua

local insults = { 
    "Fu ck" 
} 
  
local replace_sentence = { 
"Love", 
} 
  
local max_insult = 1000; 
local uebereinstimmungsrate = 4; 
local handle_type = 1; 
-- handle_type 1 = replaces the offense with a gay word 
-- handle_type 2 = kicks a user searches for "max_insult" from the server. 
-- handle_type 3 = recursively also sets up terms (not being completed) 
-- handle_type 4 = undertakes nothing 
  
addEventHandler("onPlayerChat", root, function(message, _type) 
    for index, val in pairs(insults) do 
        local new_val = val:lower(); 
        local message = message:lower(); 
        local match = false; 
         
        local laufwert = 0; 
        if message:len() > new_val:len() then 
            laufwert = new_val:len(); 
        elseif message:len() < new_val:len() then 
            laufwert = message:len(); 
        elseif message:len() == new_val:len() then 
            laufwert = new_val:len(); 
        end  
         
        if ( handle_type == 3 ) then 
            -- local currentLaufwert = 1; 
            -- local match = false; 
            -- local break_schleife = false; 
            -- laufwert = message:len(); 
            -- local inte_laufwert = 1; 
             
            -- local search_in_text_match = false 
            -- while ( inte_laufwert < laufwert+1 and search_in_text_match == false ) do 
                -- if ( string.byte(tostring(message), inte_laufwert) == string.byte(new_val) ) then 
                    -- search_in_text_match = true 
                    -- if inte_laufwert == 1 then 
                        -- outputDebugString("A"); 
                    -- end 
                -- end 
                -- inte_laufwert = inte_laufwert+1 
            -- end 
             
            -- if search_in_text_match then 
                -- while ( (currentLaufwert < laufwert+1) and ( break_schleife == false ) ) do 
                    -- if ( string.byte(tostring(message), currentLaufwert+inte_laufwert) ) then 
                         
                        -- if ( string.byte(tostring(message), currentLaufwert+inte_laufwert) ~= string.byte(tostring(new_val), currentLaufwert) ) then 
                            -- break_schleife = true 
                        -- else  
                            -- if ( currentLaufwert >= uebereinstimmungsrate ) then 
                                -- match = true 
                                -- break_schleife = true 
                            -- end 
                        -- end 
                         
                        -- currentLaufwert = currentLaufwert+1 
                    -- end 
                -- end 
            -- end 
        elseif ( handle_type == 2 ) then 
            local currentLaufwert = 1; 
            local break_schleife = false; 
            while ( (currentLaufwert < laufwert+1) and ( break_schleife == false ) ) do 
                if ( string.byte(tostring(message), currentLaufwert) ~= string.byte(tostring(new_val), currentLaufwert) ) then 
                    break_schleife = true 
                else  
                    if ( currentLaufwert >= uebereinstimmungsrate ) then 
                        match = true 
                        break_schleife = true 
                    end 
                end 
                 
                currentLaufwert = currentLaufwert+1 
            end 
             
            if ( match ) then 
                cancelEvent(); 
                handle_match(1); 
                break; 
            end 
             
        elseif ( handle_type == 1 ) then 
            local currentLaufwert = 1; 
            local break_schleife = false; 
            while ( (currentLaufwert < laufwert+1) and ( break_schleife == false ) ) do 
                if ( string.byte(tostring(message), currentLaufwert) ~= string.byte(tostring(new_val), currentLaufwert) ) then 
                    break_schleife = true 
                else  
                    if ( currentLaufwert >= uebereinstimmungsrate ) then 
                        match = true 
                        break_schleife = true 
                    end 
                end 
                 
                currentLaufwert = currentLaufwert+1 
            end 
         
            if ( match ) then 
                cancelEvent(); 
                handle_match(2); 
                break; 
            end 
        end 
             
         
         
    end 
end) 
  
function handle_match(_type) 
    if ( _type == 1 ) then 
        local oriVal = getElementData(source, "b_count") 
        if ( oriVal == false ) then 
            setElementData(source, "b_count", 1); 
            oriVal = 1; 
        else 
            oriVal = oriVal+1 
            setElementData(source, "b_count", oriVal) 
        end 
         
        if ( oriVal > max_insult ) then 
            kickPlayer(source, source, "Du hast die Grundregeln nicht beachtet!") 
        else 
            outputChatBox(string.format("Warnung %d: '%s' ist eine Beleidigung.\nWenn du drei mal auffällig geworden bist, wirst du gekickt.", oriVal, val), source, 255, 0, 0) 
        end 
    elseif ( _type == 2 ) then 
        local rand = math.random(1, #replace_sentence); 
        outputChatBox(string.format("%s\n#ff0011[libel action]", replace_sentence[rand]), root, 100, 100, 0, true); 
    end 
     
end 
  
addEventHandler("onResourceStop", root, function() 
    for index, ply in pairs(getElementsByType("player")) do  
        setElementData(ply, "b_count", 0); -- reset 
    end 
end) 
  
addEventHandler("onResourceStart", root, function() 
     
end) 

i tried this but wont work

Link to comment

Wait wait, try this i hope it'll work with you:

local pName = getPlayerName(source) 
  
addEventHandler("onPlayerChat", getRootElement(), 
function(msg, msgType) 
        if string.find(msg,"bitch") then 
           cancelEvent() 
           outputChatBox(pName..": Lady ",getRootElement(),255,0,0,true) 
        elseif string.find(msg,"gay") then 
           cancelEvent() 
           outputChatBox(pName..": Man ",getRootElement(),255,0,0,true) 
        end 
end 
) 

Link to comment

Maybe it's from string.find, i'll find solution soon.

EDIT:

i solved it, hope it will works.

ladies = { 
    "bitch", 
} 
  
mans = { 
    "gay" 
}    
  
function chatL ( msg ) 
    for k,v in ipairs (ladies) do 
        if string.find(msg,v) then 
        cancelEvent( ) 
        local pn = getPlayerName (source) 
        outputChatBox(" " .. pn  .. "  : lady",0,255,0,true) 
        end 
    end 
end 
addEventHandler( "onPlayerChat", getRootElement(), chatL ) 
  
function chatM ( msg ) 
    for k,v in ipairs (mans) do 
        if string.find(msg,v) then 
        cancelEvent( ) 
        local pn = getPlayerName (source) 
        outputChatBox(" " .. pn  .. "  : man",0,255,0,true) 
        end 
    end 
end 
addEventHandler( "onPlayerChat", getRootElement(), chatM ) 

Edited by Guest
Link to comment
Anything else?
Insults = { 
    ['shit'] = 'caca', 
    ['fuck'] = 'love', 
    ['bitch'] = 'miss', 
    ['gay'] = 'nice man' 
} 
  
  
addEventHandler("onPlayerChat", getRootElement(), 
function(message, type) 
    if message and (type == 0) then 
        for i, w in pairs(Insults)do 
            if string.find(message, i) then 
                cancelEvent() 
                local message = string.gsub(message, i, w) 
                outputChatBox(getPlayerName(source)..":#FFFFFF "..message, getRootElement(), 255, 255, 255, true) 
            end 
        end  
    end 
end) 

Link to comment

(If FatalTerror's code dosn't work)

You can try this, although i havn't tested it.

Insults = { 
    -- Note: USE lowercase LETTERS 
    -- Format: { "Insult Word", "Replace Word" }, 
    { "bitch", "cow" }, 
} 
  
function chatL ( msg ) 
    for k,v in ipairs (Insults) do 
        if string.find( string.lower ( msg ),v[1]) then 
            msg = msg:gsub ( msg, v[2] ) 
        end 
    end 
    cancelEvent ( ) 
    outputChatBox(getPlayerName ( source )..": #ffffff"..msg,root,0,255,0,true) 
end 
addEventHandler( "onPlayerChat", getRootElement(), chatL ) 

Link to comment
(If FatalTerror's code dosn't work)

You can try this, although i havn't tested it.

Insults = { 
    -- Note: USE lowercase LETTERS 
    -- Format: { "Insult Word", "Replace Word" }, 
    { "bitch", "cow" }, 
} 
  
function chatL ( msg ) 
    for k,v in ipairs (Insults) do 
        if string.find( string.lower ( msg ),v[1]) then 
            msg = msg:gsub ( msg, v[2] ) 
        end 
    end 
    cancelEvent ( ) 
    outputChatBox(getPlayerName ( source )..": #ffffff"..msg,root,0,255,0,true) 
end 
addEventHandler( "onPlayerChat", getRootElement(), chatL ) 

Working but keep repeating my message like player colos like example

Steven: Bitch

Steven: Cow

It write like that.

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...