Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Roleplay Name - How to filter bad words and specific words?

Asked by 6 years ago

Hi!

I was wondering how could I prevent players from using specific words such has "Naruto" or "Bob Ross" and also filter bad words in any kind of Roleplay Name changer?

I know there is Chat-Filtering for custom chats scripts but I couldn't find any for simple Name Changing systems.

1 answer

Log in to vote
0
Answered by 6 years ago

This is a simple example. There are probably more sophisticated ways but here you go. I use string.find(string, searchString). string is the name and searchString is the banned word. You'll have to do the fine tuning yourself.

local BannedWords = {"Naruto", "Bob Ross"}

local function CreateName(nameChangedTo)
    local isBadName = false

    for _,banned in pairs(BannedWords) do
        --use string:lower() so all text are lowercased
        if string.find(nameChangedTo:lower(), banned:lower()) then
            isBadName = true
        end
    end

    if not isBadName then
        print("Yep, name is good to go")
    else
        print("Nope, bad name!")
    end
end

CreateName("Naruto Who?") --"Nope, bad name!"
CreateName("Bob Ross Who?") --"Nope, bad name!"
CreateName("naruto") --"Nope, bad name!"
CreateName("NNarutoooooo") --"Nope, bad name!"
CreateName("Bob Rose") --"Yep, name is good to go"
CreateName("Bobby Rossu")  --"Yep, name is good to go"
1
Cool! Thank you so much! This is exactly what I was looking for!! :) xenoslav 7 — 6y
Ad

Answer this question