Zeus Scripter Posted April 15, 2020 Share Posted April 15, 2020 Boa tarde, caros usuários da F.MTA! Então pessoal, estou com um problema pra adicionar a função de comandos ao usar o chat local, eu gostaria de saber se algum programador poderia me explicar o que adicionar ou modificar? esse é o código / script: chat_range=100 addEventHandler("onPlayerJoin",getRootElement(), function () bindKey(source,"t","down","chatbox","LocalChat") end) addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), function () for index, player in pairs(getElementsByType("player")) do bindKey(player,"t","down","chatbox","LocalChat") 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("#00ff00[ Local ] #ffffff"..nick..": #FFFFFF"..msg,v,r,g,b,true) end end end addCommandHandler("LocalChat",onChat) Quem puder me ajudar agradeço dês de já. Att: ~ Zeus. Link to comment
Gw8 Posted April 15, 2020 Share Posted April 15, 2020 local lastChatMessage = {} function ChatSystem ( text, msgType) local name = _getPlayerName( source ) local text = string.gsub( text,'#%x%x%x%x%x%x', " ") if ( msgType == 1 ) then return cancelEvent(true) end if ( msgType == 0 ) then cancelEvent(true) if chatTime[source] and chatTime[source] + tonumber(150) > getTickCount() then return outputChatBox("Please dont spam.",source,255,0,0) else chatTime[source] = getTickCount() end if lastChatMessage[source] and lastChatMessage[source] == text then return outputChatBox("You can't repeat that message so soon.",source,255,0,0,true) else lastChatMessage[source] = text end cancelEvent(true) local x,y,z = getElementPosition(source) for i,player in pairs(getElementsByType("player")) do local px,py,pz = getElementPosition(player) local distance = getDistanceBetweenPoints3D(x,y,z,px,py,pz) if distance < 100 then outputChatBox(name.."#FFFFFF: "..text,player,255,255,255,true) end end end end addEventHandler("onPlayerChat",root,ChatSystem) function _getPlayerName(player) local playerTeam = getPlayerTeam(player) if (playerTeam) then local r,g,b = getTeamColor(playerTeam) local color = RGBToHex(r,g,b) playerName = color..getPlayerName(player) else playerName = "#FFFFFF"..getPlayerName(player) end return playerName end function RGBToHex(red,green,blue) return string.format("#%.2X%.2X%.2X",red,green,blue) end Nem testei blz familiaa testa ai ver oque da! 1 1 Link to comment
Zeus Scripter Posted April 15, 2020 Author Share Posted April 15, 2020 (edited) Aí sim em cara irei testar aqui manito. ~Dês de já agradeço pelo suporte prestado será de extrema ajuda! @Gw8! 16 minutes ago, Gw8 said: local lastChatMessage = {} function ChatSystem ( text, msgType) local name = _getPlayerName( source ) local text = string.gsub( text,'#%x%x%x%x%x%x', " ") if ( msgType == 1 ) then return cancelEvent(true) end if ( msgType == 0 ) then cancelEvent(true) if chatTime[source] and chatTime[source] + tonumber(150) > getTickCount() then return outputChatBox("Please dont spam.",source,255,0,0) else chatTime[source] = getTickCount() end if lastChatMessage[source] and lastChatMessage[source] == text then return outputChatBox("You can't repeat that message so soon.",source,255,0,0,true) else lastChatMessage[source] = text end cancelEvent(true) local x,y,z = getElementPosition(source) for i,player in pairs(getElementsByType("player")) do local px,py,pz = getElementPosition(player) local distance = getDistanceBetweenPoints3D(x,y,z,px,py,pz) if distance < 100 then outputChatBox(name.."#FFFFFF: "..text,player,255,255,255,true) end end end end addEventHandler("onPlayerChat",root,ChatSystem) function _getPlayerName(player) local playerTeam = getPlayerTeam(player) if (playerTeam) then local r,g,b = getTeamColor(playerTeam) local color = RGBToHex(r,g,b) playerName = color..getPlayerName(player) else playerName = "#FFFFFF"..getPlayerName(player) end return playerName end function RGBToHex(red,green,blue) return string.format("#%.2X%.2X%.2X",red,green,blue) end Nem testei blz familiaa testa ai ver oque da! Vixi mano, mais nesse chat qual seria a tecla pro chat ? queria por no "T" Edited April 15, 2020 by Zeus Scripter Marcação. Link to comment
Zeus Scripter Posted April 16, 2020 Author Share Posted April 16, 2020 2 hours ago, Gw8 said: Mas é no T Deixa eu ver se eu entendi, eu tenho que por esse código em baixo do meu certo ? ficando assim : local lastChatMessage = {} function ChatSystem ( text, msgType) local name = _getPlayerName( source ) local text = string.gsub( text,'#%x%x%x%x%x%x', " ") if ( msgType == 1 ) then return cancelEvent(true) end if ( msgType == 0 ) then cancelEvent(true) if chatTime[source] and chatTime[source] + tonumber(150) > getTickCount() then return outputChatBox("Please dont spam.",source,255,0,0) else chatTime[source] = getTickCount() end if lastChatMessage[source] and lastChatMessage[source] == text then return outputChatBox("You can't repeat that message so soon.",source,255,0,0,true) else lastChatMessage[source] = text end cancelEvent(true) local x,y,z = getElementPosition(source) for i,player in pairs(getElementsByType("player")) do local px,py,pz = getElementPosition(player) local distance = getDistanceBetweenPoints3D(x,y,z,px,py,pz) if distance < 100 then outputChatBox(name.."#FFFFFF: "..text,player,255,255,255,true) end end end end addEventHandler("onPlayerChat",root,ChatSystem) function _getPlayerName(player) local playerTeam = getPlayerTeam(player) if (playerTeam) then local r,g,b = getTeamColor(playerTeam) local color = RGBToHex(r,g,b) playerName = color..getPlayerName(player) else playerName = "#FFFFFF"..getPlayerName(player) end return playerName end function RGBToHex(red,green,blue) return string.format("#%.2X%.2X%.2X",red,green,blue) end local lastChatMessage = {} function ChatSystem ( text, msgType) local name = _getPlayerName( source ) local text = string.gsub( text,'#%x%x%x%x%x%x', " ") if ( msgType == 1 ) then return cancelEvent(true) end if ( msgType == 0 ) then cancelEvent(true) if chatTime[source] and chatTime[source] + tonumber(150) > getTickCount() then return outputChatBox("Please dont spam.",source,255,0,0) else chatTime[source] = getTickCount() end if lastChatMessage[source] and lastChatMessage[source] == text then return outputChatBox("You can't repeat that message so soon.",source,255,0,0,true) else lastChatMessage[source] = text end cancelEvent(true) local x,y,z = getElementPosition(source) for i,player in pairs(getElementsByType("player")) do local px,py,pz = getElementPosition(player) local distance = getDistanceBetweenPoints3D(x,y,z,px,py,pz) if distance < 100 then outputChatBox(name.."#FFFFFF: "..text,player,255,255,255,true) end end end end addEventHandler("onPlayerChat",root,ChatSystem) function _getPlayerName(player) local playerTeam = getPlayerTeam(player) if (playerTeam) then local r,g,b = getTeamColor(playerTeam) local color = RGBToHex(r,g,b) playerName = color..getPlayerName(player) else playerName = "#FFFFFF"..getPlayerName(player) end return playerName end function RGBToHex(red,green,blue) return string.format("#%.2X%.2X%.2X",red,green,blue) end Link to comment
Gw8 Posted April 16, 2020 Share Posted April 16, 2020 mano testa só aquele que eu te enviei, ele sozinho. Link to comment
Zeus Scripter Posted April 16, 2020 Author Share Posted April 16, 2020 13 hours ago, Gw8 said: mano testa só aquele que eu te enviei, ele sozinho. Foi não Link to comment
Angelo Pereira Posted April 16, 2020 Share Posted April 16, 2020 Não está funcionando, pois, está apenas faltando criar a tabela do chatTime local range = 100 local chatTime = { } --/> ADD local lastChatMessage = { } addEventHandler("onPlayerChat", root, function ( text, msgType ) local name = _getPlayerName( source ) local text = string.gsub( text,'#%x%x%x%x%x%x', " ") if ( msgType == 1 ) then return cancelEvent(true) end if ( msgType == 0 ) then cancelEvent(true) if chatTime[source] and chatTime[source] + tonumber(150) > getTickCount() then return outputChatBox("Evite Fazer SPAM.",source,255,0,0) else chatTime[source] = getTickCount() end if lastChatMessage[source] and lastChatMessage[source] == text then return outputChatBox("Evite Mensagem Repetida.",source,255,0,0,true) else lastChatMessage[source] = text end cancelEvent(true) local x,y,z = getElementPosition(source) for i, player in pairs(getElementsByType("player")) do local px,py,pz = getElementPosition(player) local distance = getDistanceBetweenPoints3D(x,y,z,px,py,pz) if ( distance < range ) then outputChatBox("[ Chat Local ] "..name.." #FFFFFF: "..text, player, 255, 255, 255, true) end end end end) function _getPlayerName (player) local playerTeam = getPlayerTeam(player) if (playerTeam) then local r,g,b = getTeamColor(playerTeam) local color = RGBToHex(r,g,b) playerName = color..getPlayerName(player) else playerName = "#FFFFFF"..getPlayerName(player) end return playerName end function RGBToHex(red,green,blue) return string.format("#%.2X%.2X%.2X",red,green,blue) end 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now