MTA.Castiel Posted March 17, 2023 Share Posted March 17, 2023 Good afternoon, I'm trying to remove blank text (space) inputs from our chats. The code we're modifying today is used in the 'Freeroam' resource (server-side). The main aim is to use a minimum of 1 character per message, and so if it's not a letter or a digit or a symbol, we don't output the message. I had trouble with the image link but I'll text the example below: 1. Example of the correct output message > CHAT: Castiel: Hello World. 2. Example of the blank output (space/s) > CHAT: Castiel: 3. Example of (spaces) used between words > CHAT: Castiel: Hello World . If someone could assist me on this one, i would really appreciate it. addEventHandler('onPlayerChat', root, function(msg, type) -- blank message patch if ( msg == " " ) then outputChatBox( "Invalid text input." ) return end if type == 0 then cancelEvent() if not hasObjectPermissionTo(source, "command.kick") and not hasObjectPermissionTo(source, "command.mute") then if chatTime[source] and chatTime[source] + tonumber(get("*chat/mainChatDelay")) > getTickCount() then outputChatBox("Stop spamming main chat!", source, 255, 0, 0) return else chatTime[source] = getTickCount() end if get("*chat/blockRepeatMessages") == "true" and lastChatMessage[source] and lastChatMessage[source] == msg then outputChatBox("Stop repeating yourself!", source, 255, 0, 0) return else lastChatMessage[source] = msg end end if isElement(source) then local r, g, b = getPlayerNametagColor(source) outputChatBox(getPlayerName(source) .. ': #FFFFFF' .. stripHex(msg), root, r, g, b, true) outputServerLog( "CHAT: " .. getPlayerName(source) .. ": " .. msg ) end end end ) Link to comment
AngelAlpha Posted March 17, 2023 Share Posted March 17, 2023 6 hours ago, MTA.Castiel said: Good afternoon, I'm trying to remove blank text (space) inputs from our chats. The code we're modifying today is used in the 'Freeroam' resource (server-side). The main aim is to use a minimum of 1 character per message, and so if it's not a letter or a digit or a symbol, we don't output the message. I had trouble with the image link but I'll text the example below: 1. Example of the correct output message > CHAT: Castiel: Hello World. 2. Example of the blank output (space/s) > CHAT: Castiel: 3. Example of (spaces) used between words > CHAT: Castiel: Hello World . If someone could assist me on this one, i would really appreciate it. addEventHandler('onPlayerChat', root, function(msg, type) -- blank message patch if ( msg == " " ) then outputChatBox( "Invalid text input." ) return end if type == 0 then cancelEvent() if not hasObjectPermissionTo(source, "command.kick") and not hasObjectPermissionTo(source, "command.mute") then if chatTime[source] and chatTime[source] + tonumber(get("*chat/mainChatDelay")) > getTickCount() then outputChatBox("Stop spamming main chat!", source, 255, 0, 0) return else chatTime[source] = getTickCount() end if get("*chat/blockRepeatMessages") == "true" and lastChatMessage[source] and lastChatMessage[source] == msg then outputChatBox("Stop repeating yourself!", source, 255, 0, 0) return else lastChatMessage[source] = msg end end if isElement(source) then local r, g, b = getPlayerNametagColor(source) outputChatBox(getPlayerName(source) .. ': #FFFFFF' .. stripHex(msg), root, r, g, b, true) outputServerLog( "CHAT: " .. getPlayerName(source) .. ": " .. msg ) end end end ) try this code if ( msg:gsub(" ", "") == "" ) then outputChatBox( "Invalid text input." ) return end 1 Link to comment
alex17" Posted March 18, 2023 Share Posted March 18, 2023 addEventHandler('onPlayerChat', root, function(msg, type) -- blank message patch local firstCharacter = string.sub(msg, 1, 1) if ( string.byte(firstCharacter) == 32 ) then outputChatBox( "Invalid text input." ) return end if type == 0 then cancelEvent() if not hasObjectPermissionTo(source, "command.kick") and not hasObjectPermissionTo(source, "command.mute") then if chatTime[source] and chatTime[source] + tonumber(get("*chat/mainChatDelay")) > getTickCount() then outputChatBox("Stop spamming main chat!", source, 255, 0, 0) return else chatTime[source] = getTickCount() end if get("*chat/blockRepeatMessages") == "true" and lastChatMessage[source] and lastChatMessage[source] == msg then outputChatBox("Stop repeating yourself!", source, 255, 0, 0) return else lastChatMessage[source] = msg end end if isElement(source) then local r, g, b = getPlayerNametagColor(source) outputChatBox(getPlayerName(source) .. ': #FFFFFF' .. stripHex(msg), root, r, g, b, true) outputServerLog( "CHAT: " .. getPlayerName(source) .. ": " .. msg ) end end end ) 1 Link to comment
MTA.Castiel Posted March 18, 2023 Author Share Posted March 18, 2023 @AngelAlpha This one has done the trick, i just needed to add the cancelEvent ( ) onto it like so: Many many thanks! -- Blank message patch if ( message:gsub(" ", "") == "" ) then outputChatBox( "Invalid text input." ) cancelEvent ( ) return end Link to comment
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