Jump to content

Preciso de uma ajuda em um script de chat!


Recommended Posts

Eu tenho um script de chat diferente do chat padrão do Gta
unknown.png

 

A menssagem deveria ser para o chat local, mas ela aparece para todos no chat!
 

Código na partde de lua:
 


Chatbox = { };

cLocal = { };
cTwitter = { };
cOlx = { };
cAnonymous = { };

addEventHandler( "onClientResourceStart", resourceRoot,
	function( )

		local showC = showChat( false )

		if showC == true then

			showChat( false )
			addEventHandler( "onClientRender", root, chatbox )

		end

		Animationtick = getTickCount( )
		pagechat = 'local'
		selectchat = pagechat

		digit = guiCreateEdit( chatPosition[ 1 ], chatPosition[ 2 ] + 28 * 10, 344, 30, "dsadasd", false )
		guiSetAlpha( digit, 0 )
		guiSetVisible( digit, false )
		guiEditSetMaxLength( digit, 50 )

	end
)

function cancel( button )
	if showdigit then
		if button == "p" or "F1" or "F2" or "F3" or "F4" or "F5" or "F6" or "F7" or "F8" or "F9" or "F10" or "F11" or "b" or "enter" then
			cancelEvent()
		end
	end
end
addEventHandler("onClientKey", getRootElement(), cancel)


function chatbox( )

	dxDrawRectangle( chatPosition[ 1 ], chatPosition[ 2 ], 344, 36, tocolor( 41, 41, 41, 255 ), false )

	if showdigit then

		if isElement( digit ) then

			dxDrawTextDigit( guiGetText( digit ), chatPosition[ 1 ], chatPosition[ 2 ] + 28 * 10, 344, 26, tocolor( 0, 0, 0, 120 ), "default-bold" )

		end

	end

	for i, v in ipairs( chat ) do

		if export:cursorOnElement( chatPosition[ 1 ] + i * 86 - 86, chatPosition[ 2 ], 86, 36 ) or selectchat == v then

			dxDrawRectangle( chatPosition[ 1 ] + i * 86 - 86, chatPosition[ 2 ], 86, 36, tocolor( 0, 0, 0, 50 ), false )
			dxDrawRectangle( chatPosition[ 1 ] + i * 86 - 86, chatPosition[ 2 ] + 6 * 6 - 2, 86, 2, tocolor( 0,255,127, 255 ), false )

		end

		dxDrawImage( chatPosition[ 1 ] + i * 86 - 86, chatPosition[ 2 ], 86, 36, "assets/icons/"..v..".png", 0, 0, 0, tocolor( 255, 255, 255, 255 ), false )

	end

	if pagechat == 'local' then

		for iloc, loc in ipairs( cLocal ) do

			if iloc > 12 then

				table.remove( cLocal, 1 )

			end

			if loc.visible then

				loc.alpha = loc.alpha + 10

				if loc.alpha > 255 then

					loc.alpha = 255

				end

			end

			dxDrawTextCenter( loc.message, chatPosition[ 1 ], chatPosition[ 2 ] + iloc * 20 + 20, 344, 20, { 247, 178, 94, loc.alpha }, { 255, 255, 255, loc.alpha }, "default-bold" )

		end

	elseif pagechat == 'twitter' then

		for itw, twi in ipairs( cTwitter ) do

			if twi.visible then

				twi.alpha = twi.alpha + 10

				if twi.alpha > 255 then

					twi.alpha = 255

				end

			end

			if itw > 12 then

				table.remove( cTwitter, 1 )

			end

			dxDrawTextCenter( twi.message, chatPosition[ 1 ], chatPosition[ 2 ] + itw * 20 + 20, 344, 20, { 93, 155, 226, twi.alpha }, { 255, 255, 255, twi.alpha }, "default-bold" )

		end

	elseif pagechat == 'olx' then

		for iol, vol in ipairs( cOlx ) do

			if vol.visible then

				vol.alpha = vol.alpha + 10

				if vol.alpha > 255 then

					vol.alpha = 255

				end

			end

			if iol > 12 then

				table.remove( cOlx, 1 )

			end

			dxDrawTextCenter( vol.message, chatPosition[ 1 ], chatPosition[ 2 ] + iol * 20 + 20, 344, 20, { 171, 245, 98, vol.alpha }, { 255, 255, 255, vol.alpha }, "default-bold" )

		end

	elseif pagechat == 'anonymous' then

		for iav, van in ipairs( cAnonymous ) do

			if van.visible then

				van.alpha = van.alpha + 10

				if van.alpha > 255 then

					van.alpha = 255

				end

			end

			if iav > 12 then

				table.remove( cAnonymous, 1 )

			end

			dxDrawTextCenter( van.message, chatPosition[ 1 ], chatPosition[ 2 ] + iav * 20 + 20, 344, 20, { 255, 60, 60, van.alpha }, { 255, 255, 255, van.alpha }, "default-bold" )

		end

	end

end

addEventHandler( "onClientClick", root,
	function( button, state )

		if ( button == "left" and state == "down" ) then

			for i, v in ipairs( chat ) do

				if export:cursorOnElement( chatPosition[ 1 ] + i * 86 - 86, chatPosition[ 2 ], 86, 36 ) then

					selectchat = v
					pagechat = selectchat

				end

			end

		end

	end
)

addEventHandler( "onClientKey", root,
	function( key, press )

		if key == "t" then

			if showdigit == false then

				showdigit = true
				guiSetVisible( digit, true )
				guiFocus( digit )
				setTimer( function( ) guiSetText( digit, "" ) end, 4, 1 )
				showCursor( true )

			end

		elseif key == "enter" then

			if pagechat then

				if showdigit == true then

					local text = guiGetText(digit)
					if text ~= "" then
						if (string.sub(text,1,1) == "/") then
							text = text:sub(2, #text)

							if (text:gsub("%s", "") == "")then
								return
							end

							local command = text:split(" ")
							local args = ""	
							for i=2, #command do
								args = args.." "..command[i]
							end

							executeCommandHandler(command[1], args)
							triggerServerEvent("executePlayerCommand", resourceRoot, command[1], args)
						else
							while (text:find("@@@@@@@@@@")) do
								text = msg:gsub("@@@@@@@@@@", "@@@")
							end

							triggerServerEvent( "getChatMessage", resourceRoot, guiGetText( digit ), pagechat )

						end

					end

					showdigit = false
					guiSetVisible( digit, false )
					showCursor( false )

				end

			end

		end

	end
)

function setChatMessage( message, page )

	if message and page then

		local self = setmetatable( { 

			message = message,
			pagechat = page,
			color = { },
			alpha = 0,
			visible = true,

		}, Chatbox )

		if self then

			if self.pagechat == 'local'then

				table.insert( cLocal, self )

			elseif self.pagechat == 'twitter' then

				table.insert( cTwitter, self )

			elseif self.pagechat == 'olx' then

				table.insert( cOlx, self )

			elseif self.pagechat == 'anonymous' then

				table.insert( cAnonymous, self )

			end

		end

	end

	return self;
end
addEvent( "setChatMessage", true )
addEventHandler( "setChatMessage", resourceRoot, setChatMessage )

 

 

A parte do server que eu tentei fazer!!!!

 

function getChatMessage( message, page )

	if message then

		if page == "anonymous" then

			triggerClientEvent( root, "setChatMessage", resourceRoot, "Anonimo: " .. message, page )

		else

			triggerClientEvent( root, "setChatMessage", resourceRoot, getPlayerName( client ) .. ": " .. message, page )

		end

	end

end
addEvent( "getChatMessage", true )
addEventHandler( "getChatMessage", resourceRoot, getChatMessage )


function distancia( message, page )
	if message then
		if page == "local" then
			local posX1, posY1, posZ1 = getElementPosition(source)
      		for id, player in ipairs(getElementsByType("player")) do
          	local posX2, posY2, posZ2 = getElementPosition(player)
          		if getDistanceBetweenPoints3D(posX1, posY1, posZ1, posX2, posY2, posZ2) <= 10 then
					triggerClientEvent( root, "setChatMessage", resourceRoot, getPlayerName( client ) .. ": " .. message, page )
				end
			end
		end
	end				
end


addEvent("executePlayerCommand", true)
addEventHandler("executePlayerCommand", resourceRoot,
	function(command, args)
		if (hasObjectPermissionTo(client, "command."..command, true)) then
			executeCommandHandler(command, client, args)
		end
	end
)

 

 

(OBS): Eu tentei adicionar essa função que tá nomeada como "distancia" para fazer com o que a menssagem aparecesse de acordo com certa distância. Não deu certo, preciso da ajuda de alguém!

Link to comment
  • Other Languages Moderators

Olá!

Por mais que eu não saiba a fonte desse script, irei te ajudar. Espero que não seja nada vazado. Além disso, uma observação sobre o conteúdo do seu tópico. Quando se trata de um código com muitas linhas, prefira usar a ferramenta de Spoiler. Dessa forma, não fica algo muito gigantesco na tela dos usuários. :)

Você pode encontrar essa ferramenta aqui: https://i.imgur.com/DrdiJgj.png

Agora, dada as devidas informações, aqui está o código que deve funcionar (não testei!):

function getChatMessage(message, page)
    if message then
        if page == "anonymous" then
            triggerClientEvent(root, "setChatMessage", resourceRoot, "Anonimo: " .. message, page)
        elseif page == "local" then -- Adiciona uma nova verificação para a página local
            local x, y, z = getElementPosition(client) -- Obtém a posição do jogador que enviou a mensagem
            local playersInRange = getElementsWithinRange(x, y, z, 10, "player") -- Obtém apenas os jogadores que estão numa distância de 10 metros
            triggerClientEvent(playersInRange, "setChatMessage", resourceRoot, getPlayerName(client) .. ": " .. message, page) -- Envia a mensagem apenas para os jogadores que estão próximos
        else
            triggerClientEvent(root, "setChatMessage", resourceRoot, getPlayerName(client) .. ": " .. message, page)
        end
    end
end
addEvent("getChatMessage", true)
addEventHandler("getChatMessage", resourceRoot, getChatMessage)

 

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