Bilal135 Posted November 18, 2014 Posted November 18, 2014 Hi, so today I was trying to make some anti insult script. But this doesn't seem to work. local badWord = { } badWord[1] = "fuck" badWord[2] = "bitch" function getMessage(message, messageType) if messageType == 0 then if message == badWord then killPed(source) end end end addEventHandler("onPlayerChat", getRootElement(), getMessage) This one works but only with one word ("fuck") local badWord = { } badWord[1] = "fuck" badWord[2] = "bitch" function getMessage(message, messageType) if messageType == 0 then if message == badWord[1] then killPed(source) end end end addEventHandler("onPlayerChat", getRootElement(), getMessage) Do u guys have any solution for this?
Et-win Posted November 18, 2014 Posted November 18, 2014 Use a table: for placeNumber, stringData in ipairs(badWord) do --Stuff end This will loop through your table. placeNumber = row number and stringData is what is on that row. That would be and "bitch" in this case.
Bilal135 Posted November 18, 2014 Author Posted November 18, 2014 local badWord = { } badWord[1] = "fuck" badWord[2] = "bitch" badWord[3] = "fucktard" badWord[4] = "fucker" badWord[5] = "dickhead" badWord[6] = "hijo de puta" badWord[7] = "puta" function getMessage(message, messageType) for placeNumber, stringData in ipairs(badWord) do setPlayerMuted(source, true) outputChatBox(getPlayerName(source).." Was Muted For Saying a Bad Word!", source) end end addEventHandler("onPlayerChat", getRootElement(), getMessage) Says the same thing 7 times.
Saml1er Posted November 18, 2014 Posted November 18, 2014 You don't need a loop for such a small thing. local badWord = { [":O" ]= true , ["lol"] = true } local function getMessage(message, messageType) if messageType == 0 then if badWord[message] then killPed(source) end end end addEventHandler("onPlayerChat", getRootElement(), getMessage) EDIT: Fixed a typo.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now