Jump to content

Chat problem


Recommended Posts

I wrote a small code that can be connected to chat, the problem is that if I start the resource there will be a double chat, how can I solve this so that there is only one chat

local radius = 10 

addEventHandler("onPlayerChat", root, 
function (message, messageType)
	if (messageType	 == 0) then
		local x, y, z = getElementPosition(source)
		for i, player in ipairs(getElementsByType("player")) do

			local x1, y1, z1 = getElementPosition(player)
			local name = getPlayerName(source)
			if  getDistanceBetweenPoints3D(x, y, z, x1, y1, z1) <= radius then
				outputChatBox("#cccccc" .. name .. " #ffffff mondja: #cccccc"..message , root, 0, 0, 0, true)
			end		

		end	
	end			
end
)

spacer.png

Link to comment

Since I don't see the main things which are needed to make the original chat disappear in your code snippet, I will give you some code snippet improvements that you need to have in your code besides that you have right now.
 

triggerClientEvent("onMessageIncome",source,""..message,0)


 

local textsToDraw = {}
local hideown
local showtime
local characteraddition

addEvent("onMessageIncome",true)
	addEventHandler("onMessageIncome",getRootElement(),income)
function income(message,messagetype)
	if source ~= getLocalPlayer() or not hideown then
		addText(source,message,messagetype)
	end
end

function addText(source,message,messagetype)
	local notfirst = false
	for i,v in ipairs(textsToDraw) do
		if v[1] == source then
			v[4] = v[4] + 1
			notfirst = true
		end
	end
	local infotable = {source,message,messagetype,0}
	table.insert(textsToDraw,infotable)
	if not notfirst then
		setTimer(removeText,showtime + (#message * characteraddition),1,infotable)
	end
end
function sendMessageToClient(message,messagetype)
	if messagetype == 0 or messagetype == 2 then
		triggerClientEvent("onMessageIncome",source,message,messagetype)
	end
function sendLocalSay(ped, msg)
	sendSay(ped, msg)
end

addCommandHandler("say",
	function (commandName, ...)
		if getElementData(localPlayer, "loggedIn") then
			sendSay(localPlayer, table.concat({...}, " "):gsub("#%x%x%x%x%x%x", ""))
		end
	end)

 

Edited by Flashmyname
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...