Jump to content

Mudar o chat


Recommended Posts

Eu queria mudar o chat do T para o chat local eu fiz isso so que ele não manda os comandos exemplo:
O cara manda mensagem no T e ele vai mandar no global que no caso e /rp ai quando ele vai falar não manda o comando ele simplesmente fala /rp mensagem
Script 
 

chat_range=100 
  
addEventHandler("onPlayerJoin",getRootElement(), 
function () 
bindKey(source,"t","down","chatbox","Say") 
end) 
  
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
function () 
for index, player in pairs(getElementsByType("player")) do 
bindKey(player,"t","down","chatbox","Say") 
  end 
end) 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
   local px,py,pz=getElementPosition(player) 
   return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end 
  
function onChat(player,_,...) 
  local px,py,pz=getElementPosition(player) 
  local msg = table.concat({...}, " ") 
  local nick=getPlayerName(player) 
local r,g,b = getTeamColor(getPlayerTeam(player)) 
  for _,v in ipairs(getElementsByType("player")) do 
    if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
      outputChatBox("#BEBEBELocal* #FFFAFA"..nick..": #DCDCDC"..msg,v,r,g,b,true) 
    end 
  end 
end 
addCommandHandler("Say",onChat) 

 

Quem estiver precisando de print 
Clique aqui

Link to comment
local isChatVisible = true 

function chat ()
    if isChatVisible then 
        showChat ( false ) 
        isChatVisible = false
    else
        showChat ( true ) 
        isChatVisible = true 
    end
end
addCommandHandler ("ativarchat", chat ) 
-- Se o player dê /showchat aparecera o chat, não sei como impedi isto. Mas está ai a forma de desativar
-- o chat.

EDIT: Este código é client-side.

Edited by itachi0
Link to comment
  • Other Languages Moderators
2 hours ago, C0DE said:

E como eu desativo ?

function disableChat (message, messageType)
    cancelEvent ()
end
addEventHandler ("onPlayerChat", getRootElement(), disableChat)

 

-----------------

A propósito, na wiki do onPlayerChat já tem um exemplo de chat local.

Link to comment

Ainda não funcionou pois ele não manda comando nenhum
Vou mandar os scripts que eu fiz nele

lc.lua

chat_range=100 
  
addEventHandler("onPlayerJoin",getRootElement(), 
function () 
bindKey(source,"t","down","chatbox","Say") 
end) 
  
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
function () 
for index, player in pairs(getElementsByType("player")) do 
bindKey(player,"t","down","chatbox","Say") 
  end 
end) 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
   local px,py,pz=getElementPosition(player) 
   return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end 
  
function onChat(player,_,...) 
  local px,py,pz=getElementPosition(player) 
  local msg = table.concat({...}, " ") 
  local nick=getPlayerName(player) 
local r,g,b = getTeamColor(getPlayerTeam(player)) 
  for _,v in ipairs(getElementsByType("player")) do 
    if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
      outputChatBox("#BEBEBELocal* #FFFAFA"..nick..": #DCDCDC"..msg,v,r,g,b,true) 
    end 
  end 
end 
addCommandHandler("Say",onChat) 


client.lua

function disableChat (message, messageType)
    cancelEvent ()
end
addEventHandler ("onPlayerChat", getRootElement(), disableChat)


meta.xml

<meta>
	<info author="C0DE" name="localchat"  version="1.0" type="script"/>
	<script src="lc.lua" type="server" />
		<script src="client.lua" type="server" />
</meta>

 

Vou fazer um script na base desse onPlayerChat se obtiver resultados irei postar aqui

Link to comment

local chatRadius = 25 


function sendMessageToNearbyPlayers(message, messageType)

    if messageType == 0 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) <= chatRadius then
                outputChatBox("#BEBEBELocal* #FFFAFA"..getPlayerName..": #DCDCDC"..message,v,r,g,b,true)
            end
        end
    end
    
    cancelEvent()
end

addEventHandler( "onPlayerChat", getRootElement(), sendMessageToNearbyPlayers )

Fiz um monte de modificação ate que esse so deu um erro mais não consigo pegar o nome do player
Erro  no console
 

ERROR: [managers]\Local\ls.lua:15: attempt to concatenate global 'getPlayerName' (a function value)

 

Link to comment
  • Moderators
51 minutes ago, C0DE said:

ERROR: [managers]\Local\ls.lua:15: attempt to concatenate global 'getPlayerName' (a function value)

Não tem nenhum argumento especificado na função, por isso não vai funcionar. O correto seria "getPlayerName(player).

1 hour ago, C0DE said:

Ainda não funcionou pois ele não manda comando nenhum
Vou mandar os scripts que eu fiz nele

lc.lua


chat_range=100 
  
addEventHandler("onPlayerJoin",getRootElement(), 
function () 
bindKey(source,"t","down","chatbox","Say") 
end) 
  
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
function () 
for index, player in pairs(getElementsByType("player")) do 
bindKey(player,"t","down","chatbox","Say") 
  end 
end) 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
   local px,py,pz=getElementPosition(player) 
   return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end 
  
function onChat(player,_,...) 
  local px,py,pz=getElementPosition(player) 
  local msg = table.concat({...}, " ") 
  local nick=getPlayerName(player) 
local r,g,b = getTeamColor(getPlayerTeam(player)) 
  for _,v in ipairs(getElementsByType("player")) do 
    if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
      outputChatBox("#BEBEBELocal* #FFFAFA"..nick..": #DCDCDC"..msg,v,r,g,b,true) 
    end 
  end 
end 
addCommandHandler("Say",onChat) 


client.lua


function disableChat (message, messageType)
    cancelEvent ()
end
addEventHandler ("onPlayerChat", getRootElement(), disableChat)


meta.xml


<meta>
	<info author="C0DE" name="localchat"  version="1.0" type="script"/>
	<script src="lc.lua" type="server" />
		<script src="client.lua" type="server" />
</meta>

 

Vou fazer um script na base desse onPlayerChat se obtiver resultados irei postar aqui

Remova esse client.lua e passe esse código para o lc.lua:

function disableChat (message, messageType)
    cancelEvent ()
end
addEventHandler ("onPlayerChat", getRootElement(), disableChat)

 

Link to comment

Tentei de tudo mais ainda esta bugando quando eu tento da qualquer comando ele não vai

chat_range=100 
  
addEventHandler("onPlayerJoin",getRootElement(), 
function () 
bindKey(source,"t","down","chatbox","Say") 
end) 
  
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
function () 
for index, player in pairs(getElementsByType("player")) do 
bindKey(player,"t","down","chatbox","Say") 
  end 
end) 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
   local px,py,pz=getElementPosition(player) 
   return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end 
  
function onChat(player,_,msg) 
  local px,py,pz=getElementPosition(player) 
  local nick=getPlayerName(player) 
  for _,v in ipairs(getElementsByType("player")) do 
    if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
      outputChatBox("#BEBEBELocal* #FFFAFA"..nick..": #DCDCDC"..msg,v,30,30,200,true) 
    end 
  end 
end 
addCommandHandler("t",onChat) 

 

Link to comment
  • Moderators
addCommandHandler("t",onChat) 

Deve ser:

addCommandHandler("Say",onChat) 

Código:

chat_range=100 
  
addEventHandler("onPlayerJoin",getRootElement(), 
function () 
bindKey(source,"t","down","chatbox","Say") 
end) 
  
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
function () 
for index, player in pairs(getElementsByType("player")) do 
bindKey(player,"t","down","chatbox","Say") 
  end 
end) 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
   local px,py,pz=getElementPosition(player) 
   return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end 
  
function onChat(player,_,msg) 
  local px,py,pz=getElementPosition(player) 
  local nick=getPlayerName(player) 
  for _,v in ipairs(getElementsByType("player")) do 
    if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
      outputChatBox("#BEBEBELocal* #FFFAFA"..nick..": #DCDCDC"..msg,v,30,30,200,true) 
    end 
  end 
end 
addCommandHandler("Say",onChat)

 

Link to comment
  • 3 weeks later...
On 04/01/2019 at 22:45, DNL291 said:

addCommandHandler("t",onChat) 

Deve ser:


addCommandHandler("Say",onChat) 

Código:


chat_range=100 
  
addEventHandler("onPlayerJoin",getRootElement(), 
function () 
bindKey(source,"t","down","chatbox","Say") 
end) 
  
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
function () 
for index, player in pairs(getElementsByType("player")) do 
bindKey(player,"t","down","chatbox","Say") 
  end 
end) 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
   local px,py,pz=getElementPosition(player) 
   return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end 
  
function onChat(player,_,msg) 
  local px,py,pz=getElementPosition(player) 
  local nick=getPlayerName(player) 
  for _,v in ipairs(getElementsByType("player")) do 
    if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
      outputChatBox("#BEBEBELocal* #FFFAFA"..nick..": #DCDCDC"..msg,v,30,30,200,true) 
    end 
  end 
end 
addCommandHandler("Say",onChat)

 

Testei esse mesmo codigo,  acontece que quando vou falar no chat, aparece apenas a primeira palavra, e tambem não pega comandos

 

Link to comment
  • Other Languages Moderators

-----------------------

Bom, voltando ao seu problema: Esse problema de comandos não funcionarem no seu chat só ocorre quando este resource está ativado? Ou com ele desligado tbm acontece isso?

Link to comment
  • Other Languages Moderators

Cara, no seu lugar eu tentaria desativar as funções 1 por 1 até descobrir qual está impedindo o uso de comandos.

Uma dica é deixar a função inteira como comentário, dai ela não será lida pelo resource.

Link to comment
6 hours ago, Lord Henry said:

Cara, no seu lugar eu tentaria desativar as funções 1 por 1 até descobrir qual está impedindo o uso de comandos.

Uma dica é deixar a função inteira como comentário, dai ela não será lida pelo resource.

Bom, eu vim parar nesse tópico por indicação, mas enfim, estou precisando muito desse chat local na letra T, mas eu queria que pudesse usar comandos nele...

Link to comment
  • Moderators
13 hours ago, danblemes1 said:

Testei esse mesmo codigo,  acontece que quando vou falar no chat, aparece apenas a primeira palavra, e tambem não pega comandos

 

Isto vai corrigir o problema de aparecer só a primeira palavra:


local chat_range=100 
  
addEventHandler("onPlayerJoin",getRootElement(), 
function () 
	bindKey(source,"t","down","chatbox","Say") 
end) 
  
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
function () 
	for index, player in pairs(getElementsByType("player")) do 
		bindKey(player,"t","down","chatbox","Say") 
	end 
end)
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
	local px,py,pz=getElementPosition(player) 
	return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end

function onChat(player,_, ...)
	local msg = table.concat({...}," ")
	local px,py,pz=getElementPosition(player)
	local nick=getPlayerName(player) 
	for _,v in ipairs(getElementsByType("player")) do 
		if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
			outputChatBox("#BEBEBELocal* #FFFAFA"..nick..": #DCDCDC"..msg,v,30,30,200,true) 
		end 
	end 
end 
addCommandHandler("Say",onChat)

Só que os espaços, se tiver mais que 1, os outros serão ignorados e será aplicado só uma vez.

E sobre os comandos, eu vou testar depois, acho que dá pra fazer executar com "/" no começo.

Edited by DNL291
Link to comment
  • Moderators

local chat_range=100 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
	local px,py,pz=getElementPosition(player) 
	return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end

function onPlayerChatHandler( message, messageType )
	if (messageType == 0) then
		cancelEvent()
	
		local px,py,pz=getElementPosition(source)
		local nick=getPlayerName(source) 
		for _,v in ipairs(getElementsByType("player")) do 
			if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
				outputChatBox("#BEBEBELocal* #FFFAFA"..nick..": #DCDCDC"..message,v,30,30,200,true) 
			end 
		end 
	end
end
addEventHandler( "onPlayerChat", root, onPlayerChatHandler )

Mais fácil assim 9_9

@danblemes1

Edited by DNL291
  • Thanks 1
Link to comment
15 hours ago, DNL291 said:

local chat_range=100   function isPlayerInRangeOfPoint(player,x,y,z,range) 	local px,py,pz=getElementPosition(player) 	return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range endfunction onPlayerChatHandler( message, messageType )	if (messageType == 0) then		cancelEvent()			local px,py,pz=getElementPosition(source)		local nick=getPlayerName(source) 		for _,v in ipairs(getElementsByType("player")) do 			if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 				outputChatBox("#BEBEBELocal* #FFFAFA"..nick..": #DCDCDC"..message,v,30,30,200,true) 			end 		end 	endendaddEventHandler( "onPlayerChat", root, onPlayerChatHandler )

Mais fácil assim 9_9

@danblemes1

Mas ai as mensagens estão saido duplicadas, tipo MeuNick:msg | Local MeuNick: msg

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