Jump to content

Editar chat "t"


Recommended Posts

Olá estou criando um servidor 100% focado no RP puro. então para forçar os players a usarem o "Z" para falar e fazerem RP , eu queria saber como deixar o chat "T" unicamente para uso de comandos por exemplo:

O player quando escrever alguma palavra no chat ela não vai aparecer de jeito nenhum para o outro jogador ,

porém se ele usar um comando irá funcionar , se alguem poder me ajudar fico muito agradecido!

Edited by Renazz
Link to comment

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 MensagemTwitter(source, cmd, ...) 
    local MessagemT = table.concat ( { ... }, " " )
    local name = getPlayerName(source); 
for _,v in ipairs(getElementsByType("player")) do 
    outputChatBox("᠉  #00BFFFTwitter- #ffffff"..name.."#00BFFF - #FFFFFF"..MessagemT,v, 255, 255, 255, true) 
    end 
end 
addCommandHandler("Twitter",  MensagemTwitter)
  
addCommandHandler( "DeepWeb", function ( source, cmd, ... )            
    local message2 = #{...} > 0 and table.concat({...}," ") or nil
    if message2 then
        for _, p in ipairs (getElementsByType("player")) do
            if hasObjectPermissionTo(p, "command.mute", true) then
                outputChatBox("᠉ #696969 DeepWeb- #696969"..message2, p, 255, 255, 255, true)
            else
                outputChatBox("᠉ #696969 DeepWeb- #696969"..message2, p, 255, 255, 255, true)
            end
        end
    else
    end
end )

addEventHandler("onPlayerJoin", getRootElement(),  
function() 
  bindKey(source, "t", "down", "chatbox", "Twitter")
end 

addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() 
  for index,player in pairs(getElementsByType("player")) do 
        bindKey(player,"t", "down", "chatbox", "Twitter")
  end 
end 

addEventHandler("onPlayerJoin", getRootElement(),  
function() 
  bindKey(source, "u", "down", "chatbox", "DeepWeb")
end 

addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() 
  for index,player in pairs(getElementsByType("player")) do 
        bindKey(player,"u", "down", "chatbox", "DeepWeb")
  end 
end 

está junto com o outro chat (DeepWeb)

Link to comment

Tenta assim:

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 
 
addEventHandler ("onPlayerChat", root,
	function (msg, type)
		if type == 0 then
			cancelEvent ()
			local mainChatDelay = 1000
			if chatTime[source] and chatTime[source] + mainChatDelay > getTickCount() then
				return	outputChatBox ("Não floode....", source, 255, 50, 50, true)
			else
				chatTime[source] = getTickCount()
			end			
			if isObjectInACLGroup ("user."..getAccountName(getPlayerAccount(source)), aclGetGroup ("Everyone")) then
				outputChatBox("᠉  #00BFFFTwitter- #ffffff"..getPlayerName(source).."#00BFFF - #FFFFFF"..msg, root, 255, 255, 255, true) 
			end	
		end
	end
)
  
addCommandHandler ("DeepWeb", function (source, cmd, ...)            
	local message2 = #{...} > 0 and table.concat({...}," ") or nil
	if message2 then
		local everybody = getElementsByType("player")
		for _, p in ipairs (everybody) do
			if hasObjectPermissionTo(p, "command.mute", true) then
				outputChatBox("᠉ #696969 DeepWeb- #696969"..message2, p, 255, 255, 255, true)
			end	
		end
	end
end)

addEventHandler ("onPlayerJoin", getRootElement(),  
	function () 
		bindKey(source, "u", "down", "chatbox", "DeepWeb")
	end
) 

addEventHandler ("onResourceStart", resourceRoot, 
	function () 
		local everybody = getElementsByType("player")
		for index, player in pairs(everybody) do 
			bindKey(player,"u", "down", "chatbox", "DeepWeb")
		end 
	end
) 

 

Edited by Jonas^
Edit
  • Thanks 2
Link to comment
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 
 
addEventHandler ("onPlayerChat", root,
	function (msg, type)
		if type == 0 then
			cancelEvent ()
		end	
	end
)
function MensagemTwitter (source, cmd, ...) 
	local MessagemT = table.concat ( { ... }, " " )
	local name = getPlayerName(source); 
	local everybody = getElementsByType("player")
	for _, v in ipairs(everybody) do 
		outputChatBox("᠉  #00BFFFTwitter- #ffffff"..name.."#00BFFF - #FFFFFF"..MessagemT, v, 255, 255, 255, true) 
	end 
end 
addCommandHandler ("Twitter", MensagemTwitter)

addCommandHandler ("DeepWeb", function (source, cmd, ...)            
	local message2 = #{...} > 0 and table.concat({...}," ") or nil
	if message2 then
		local everybody = getElementsByType("player")
		for _, p in ipairs (everybody) do
			if hasObjectPermissionTo(p, "command.mute", true) then
				outputChatBox("᠉ #696969 DeepWeb- #696969"..message2, p, 255, 255, 255, true)
			end	
		end
	end
end)

addEventHandler ("onPlayerJoin", getRootElement(),  
	function () 
		bindKey (source, "u", "down", "chatbox", "DeepWeb")
		bindKey (source, "o", "down", "chatbox", "Twitter")
	end
) 

addEventHandler ("onResourceStart", resourceRoot, 
	function () 
		local everybody = getElementsByType("player")
		for index, player in pairs(everybody) do 
			bindKey (player,"u", "down", "chatbox", "DeepWeb")
			bindKey (player,"o", "down", "chatbox", "Twitter")
		end 
	end
) 

 

  • Thanks 1
Link to comment

com licença...falando em chat acho que o meu tem algo errado, nao funciona

 

-chat_client.lua

chatGUI = { 
    button = {x}, 
    edit = {},
}

chatbox = {
    {"Bem-vindo ao chat!","INFO"},
    {"Pressione 'X' para escrever "," INFO"},
    {"Nosso grupo -" ,"INFO"},
    {"Наш сайт: dayz-start.ru","INFO"},
}
local otChat = 0
local show = false
local show_gui = false
local sobbe = 1 --// 1 Global // 2 group // 3 radio
local sW,sH = guiGetScreenSize()
local chatRadius = 15

function startRollMessage(text, r, g, b)
    table.insert(chatbox,{text,"ATENÇÃO",133,53,53})
end
addEvent("onRollMessageStart", true)
addEventHandler("onRollMessageStart", getLocalPlayer(), startRollMessage)


function startRollMessage2(head,text, r, g, b)
    table.insert(chatbox,{text,"ATENÇÃO",133,53,53})
end
addEvent("displayClientInfo", true)
addEventHandler("displayClientInfo", getLocalPlayer(), startRollMessage2)

function drawChat()
    if not getElementData(getLocalPlayer(),"logedin") then return end

    if getKeyState("enter") == true and show_gui == true then
        sendMes()
    end    
    sY = 0
    for i=1, #chatbox do
        if i > 6 then
            table.remove(chatbox,1)
        end
        if getElementData ( localPlayer, "GPS" ) >= 1 then
        wm = dxGetTextWidth(chatbox[2],1.02,"default-bold")
        dxDrawRectangle(sW*0.005, sH*0.5+sY, wm+10, 17,tocolor(chatbox[3],chatbox[4], chatbox[5],230))
        nick = dxDrawText(chatbox[2]..": ",sW*0.007, sH*0.5+sY, 150, 30, tocolor ( 255,255,255,255), 1.02, "default" )-- apelido de saída
        wn = dxGetTextWidth(chatbox[2]..": ",1.02,"default-bold")
        dfx2 = dxDrawText(chatbox[1], sW*0.011+wn, sH*0.5+sY, 150, 30, tocolor ( 255,255,255,230), 1.02, "default-bold" )
        --guiSetProperty(chatGUI.button[2], "NormalTextColour", "FFAAAAAA")
        -- saída de mensagem    
        else
        
            wm = dxGetTextWidth(chatbox[2],1.02,"default-bold")
        dxDrawRectangle(sW*0.005, sH*0.8+sY, wm+10, 17,tocolor(chatbox[3],chatbox[4], chatbox[5],230))
        nick = dxDrawText(chatbox[2]..": ",sW*0.007, sH*0.8+sY, 150, 30, tocolor ( 255,255,255,255), 1.02, "default" )-- apelido de saída
        wn = dxGetTextWidth(chatbox[2]..": ",1.02,"default-bold")
        dfx2 = dxDrawText(chatbox[1], sW*0.011+wn, sH*0.8+sY, 150, 30, tocolor ( 255,255,255,230), 1.02, "default-bold" )
        
        
        
        
        --guiSetProperty(chatGUI.button[2], "NormalTextColour", "FFAAAAAA")
        -- saída de mensagem    
end        
        sY = sY + 20
    end 
end
addEventHandler("onClientRender",getRootElement(),drawChat)


bindKey("x","down",function()
    createdGUI()
    if show_gui == false then
        creatChat()
        sobbe = 1
    --else
        --closeChat()
    end    
end)


--[[bindKey("u","down",function()
local posX, posY, posZ = getElementPosition( source )
        local chatSphere = createColSphere( posX, posY, posZ, chatRadius )
        local nearbyPlayers = getElementsWithinColShape( chatSphere, "player" )
        destroyElement( chatSphere )
    createdGUI()
    if show_gui == false then
        creatChat()
        sobbe = 2
    end    
    for index, nearbyPlayer in ipairs( nearbyPlayers ) do
    if source == nearbyPlayer then
    table.insert(chatbox,{"Você não é um membro.!","",255,0,255,"","Servidor"})
    end
end)--]]

function createdGUI()
    if show == false then
      -- if getElementData ( localPlayer, "GPS" ) >= 1 then
        chatGUI.button[2] = guiCreateButton((sW/2-sW/2)+325, sH/2+70, sW*0.054, sH*0.022, "FECHAR", false)
        form1s = guiCreateLabel((sW/2-sW/2)+113, sH/2+50,sW*0.15, sH*0.022, "Digite a mensagem:", false)
        chatGUI.edit[1] = guiCreateEdit((sW/2-sW/2)+110, sH/2+70, sW*0.15, sH*0.022, "", false) 
                guiSetProperty(chatGUI.button[2], "NormalTextColour", "FFAAAAAA")

        --end
        --guiSetProperty(chatGUI.button[2], "NormalTextColour", "FFAAAAAA")
        guiSetInputMode("no_binds_when_editing")
        guiBringToFront( chatGUI.edit[1] )
        guiEditSetCaretIndex( chatGUI.edit[1], 1 )
        setTimer(function ()
        guiSetText ( chatGUI.edit[1], "" )
        end,50,1)
        show = true
        

        
        addEventHandler("onClientGUIClick",chatGUI.button[2],closeChat,false)
        guiEditSetMaxLength(chatGUI.edit[1],42)
    end
end

bindKey("enter","down",function()
sendMes()
end)

function sendMes()
    if show_gui == true then
        local text = guiGetText(chatGUI.edit[1])
        if otChat ~= 0 then return end
        if pregFind(text, "([0-9]{1,3})[^[:digit:]^[:cntrl:]]{1,3}([0-9]{1,3})[^[:digit:]^[:cntrl:]]{1,3}([0-9]{1,3})[^[:digit:]^[:cntrl:]]{1,3}([0-9]{1,3})") then return end
        if string.len(text) <= 0 then closeChat() return end
        triggerServerEvent("sendMessage",resourceRoot,getLocalPlayer(),"",text,sobbe)
        closeChat()
        otChat = 3
    end    
end
function updateChat()
    if otChat > 0 then 
        otChat = otChat - 1 
    end
end
setTimer(updateChat,1000,0)

function creatChat()
    guiSetVisible(chatGUI.button[2],true)
    guiSetVisible(chatGUI.edit[1],true)
    guiSetVisible(form1s,true)

        if getElementData ( localPlayer, "GPS" ) > 0 then
 guiSetPosition (chatGUI.button[2], sW*0.16, sH*0.47,false )
     guiSetPosition (form1s, sW*0.008, sH*0.45, false)
     guiSetPosition (chatGUI.edit[1], sW*0.006, sH*0.47, false )
     else
     
     
     
      guiSetPosition (chatGUI.button[2], sW*0.16, sH*0.77,false )
     guiSetPosition (form1s, sW*0.008, sH*0.75, false)
     guiSetPosition (chatGUI.edit[1], sW*0.006, sH*0.77, false )
     end--]]
    setElementData(getLocalPlayer(),"enteredChat",true)
    showCursor(true)
    show_gui = true
    guiBringToFront( chatGUI.edit[1] )
    guiEditSetCaretIndex( chatGUI.edit[1], 1 )
    guiSetAlpha ( chatGUI.edit[1], 0.7 )
setTimer(function ()
    guiSetText ( chatGUI.edit[1], "" )
        end,50,1)

end

function closeChat()

--guiSetVisible(chatGUI.button[1],false)
    guiSetVisible(chatGUI.button[2],false)
    guiSetVisible(chatGUI.edit[1],false)
    guiSetVisible(form1s,false)
    setElementData(getLocalPlayer(),"enteredChat",false)
    showCursor(false)
    show_gui = false
end

function addNewMessage(msg,name)
    table.insert(chatbox,{name,msg})
end
addEvent("addNewMessage",true)
addEventHandler("addNewMessage",getRootElement(),addNewMessage)

 

-chat_server.lua

function setNewChat(thePlayer, cmd, message, sobbe)
    msg = string.gsub(table.concat ( { message }, " " ),"","")
    local name =  string.gsub(getPlayerName(thePlayer),"#%x%x%x%x%x%x","")
    if sobbe == 1 then
        if (isObjectInACLGroup("user." ..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin"))) then
            r,g,b = 209,10,10
            triggerClientEvent(root,"addNewMessage",root,name,msg,r,g,b)
            outputServerLog("[Chat][Admin]"..name..": "..msg)
            outputConsole("[Chat][Admin]"..name..": "..msg)
        else
            r,g,b = 209,10,10
            if msg == "/kill" then
            triggerClientEvent(root,"addNewMessage",root,name,"está funcionando",r,g,b)
            end
            triggerClientEvent(root,"addNewMessage",root,name,msg,r,g,b)
            outputServerLog("[Chat]"..name..": "..msg)
            outputConsole("[Chat]"..name..": "..msg)
            --triggerClientEvent(root,"addNewMessage",root,name,msg,r,g,b,"","[-------------]")
        end
    elseif sobbe == 2 then
        local gangname = getElementData(thePlayer,"gang")
        if getElementData(thePlayer,"gang") == "None" then return end
        for i, player in ipairs(getElementsByType("player")) do
            if gangname == getElementData(player,"gang") then
                r,g,b = 255,255,0
                triggerClientEvent(root,"addNewMessage",root,name,msg,r,g,b,"","[Группа] ")
            end    
        end    
    end    
    cancelEvent()
end
addEvent("sendMessage",true)
addEventHandler("sendMessage",getRootElement(),setNewChat)

local root = getRootElement()
 
addEventHandler("onPlayerLogin", root,
    function()
        triggerClientEvent ( "onRollMessageStart", getRootElement(), getPlayerName(source).." logado!",255,255,255, "join")
    end
)

addEventHandler('onClientPlayerJoin', root,
    function()
        triggerClientEvent ( "onRollMessageStart", getRootElement(), getPlayerName(source).." juntou к игре!",255,255,255, "join")
    end
)


addEventHandler('onClientPlayerQuit', root,
    function()
            triggerClientEvent ( "onRollMessageStart", getRootElement(), getPlayerName(source).." fora do jogo!",255,255,255, "join")
    end
)

 

-meta

<meta>
  <info author="gabriel" type="misc" version="1.3.1" />
  <script src="chat_client.lua" />
  <script src="chat_server.lua" />

</meta>
 

 

 

 

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