Jump to content

[CHAT] Blank message


Recommended Posts

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

 

  • Thanks 1
Link to comment
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
)

 

  • Thanks 1
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...