FoxG^ Posted June 1, 2019 Posted June 1, 2019 local chat_range=25 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("#838B83[ #FFFF00вcɢ ʟᴏᴄᴀʟ #838B83] "..nick..": #FFFF00"..msg,v,r,g,b,true) end end end addCommandHandler(onChat) [PT-BR] Salve Comunidade do MTA, Então estou tendo um probleminha no meu chat local que é o seguinte: Queria que essa mensagem do outputChatBox fosse mandada no say, com uma distancia para servir como chat local, Não manjo muito de programação e venho aqui pedir uma ajuda de vcs! Recalculando: Chat local no no "t"(say) com uma distancia que ja esta no codigo para servir de chat local TMJ!
Moderators Patrick Posted June 1, 2019 Moderators Posted June 1, 2019 community profile | map converters | map images | pDownloader | pAttach | model encrypter
FoxG^ Posted June 1, 2019 Author Posted June 1, 2019 (edited) addEventHandler("onPlayerChat", getRootElement(), function(message) cancelEvent() local x, y, z = getElementPosition(source) local radius = createColSphere(x, y, z, 15) local nearPlayers = getElementsWithinColShape(radius, "player") destroyElement(radius) for _, player in ipairs(nearPlayers) do if getElementDimension(player) == getElementDimension(source) then outputChatBox("#838B83[ #FFFF00вcɢ ʟᴏᴄᴀʟ #838B83]"..getPlayerName(source).."#FFFF00 : "..message, player, 255, 255, 255, true) end end end) Arrumei o codigo está certo ? Edited June 1, 2019 by joaolamar
DNL291 Posted June 2, 2019 Posted June 2, 2019 7 hours ago, joaolamar said: addEventHandler("onPlayerChat", getRootElement(), function(message) cancelEvent() local x, y, z = getElementPosition(source) local radius = createColSphere(x, y, z, 15) local nearPlayers = getElementsWithinColShape(radius, "player") destroyElement(radius) for _, player in ipairs(nearPlayers) do if getElementDimension(player) == getElementDimension(source) then outputChatBox("#838B83[ #FFFF00вcɢ ʟᴏᴄᴀʟ #838B83]"..getPlayerName(source).."#FFFF00 : "..message, player, 255, 255, 255, true) end end end) Arrumei o codigo está certo ? Falta verificar se a mensagem é do comando say, e em vez de criar um elemento de colisão, sugiro utilizar a função getDistanceBetweenPoints3D. Talvez seja este mesmo resource que você está procurando: https://community.multitheftauto.com/index.php?p=resources&s=details&id=2801 Se não for, imagino que seja isto: local chatRadius = 20 addEventHandler( "onPlayerChat", root, function (message, messageType) if messageType == 0 then local x,y,z = getElementPosition(source) cancelEvent() for i,player in ipairs(getElementsByType("player")) do local npx, npy, npz = getElementPosition(player) if getDistanceBetweenPoints3D(x,y,z, npx,npy,npz) <= chatRadius then outputChatBox("#838B83[ #FFFF00вcɢ ʟᴏᴄᴀʟ #838B83]"..getPlayerName(source).."#FFFF00 : #ffffff"..message, player, 255, 255, 255, true) end end end end ) Please do not PM me with scripting related question nor support, use the forums instead.
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