RangerMind Posted April 7, 2018 Share Posted April 7, 2018 Hi Sorry for my bad english:( Learn how to disable Global Chat on my server For example, players who are not in one place do not see other players' chats please Help me Link to comment
Moderators Patrick Posted April 8, 2018 Moderators Share Posted April 8, 2018 (edited) 20 hours ago, RangerMind said: Hi Sorry for my bad english:( Learn how to disable Global Chat on my server For example, players who are not in one place do not see other players' chats please Help me -- SERVER SIDE addEventHandler("onPlayerChat", getRootElement(), function(message) cancelEvent() local x, y, z = getElementPosition(source) local radius = createColSphere(x, y, z, 15) -- see the message in 15m radius local nearPlayers = getElementsWithinColShape(radius, "player") destroyElement(radius) for _, player in ipairs(nearPlayers) do if getElementDimension(player) == getElementDimension(source) then outputChatBox(getPlayerName(source)..": #FFFFFF"..message, player, 255, 255, 255, true) end end end) Edited April 8, 2018 by Patrick2562 Link to comment
RangerMind Posted April 8, 2018 Author Share Posted April 8, 2018 thanks you please give me a faction system PD , FBI , NG , Medic , NR And More . . . . . . Quote Link to comment
Moderators Patrick Posted April 8, 2018 Moderators Share Posted April 8, 2018 12 minutes ago, RangerMind said: thanks you please give me a faction system PD , FBI , NG , Medic , NR And More . . . . . . I have not. And a faction system is really complicated. Link to comment
mehmet Posted March 13, 2019 Share Posted March 13, 2019 On 08/04/2018 at 14:08, stPatrick said: -- SERVER SIDE addEventHandler("onPlayerChat", getRootElement(), function(message) cancelEvent() local x, y, z = getElementPosition(source) local radius = createColSphere(x, y, z, 15) -- see the message in 15m radius local nearPlayers = getElementsWithinColShape(radius, "player") destroyElement(radius) for _, player in ipairs(nearPlayers) do if getElementDimension(player) == getElementDimension(source) then outputChatBox(getPlayerName(source)..": #FFFFFF"..message, player, 255, 255, 255, true) end end end) Why server side? Link to comment
Moderators Patrick Posted March 13, 2019 Moderators Share Posted March 13, 2019 37 minutes ago, mehmet said: Why server side? Why not? Link to comment
XaskeL Posted March 13, 2019 Share Posted March 13, 2019 On 08.04.2018 at 15:08, stPatrick said: - СТОРОНА СЕРВЕРА this code will bury the server. Use it: -- define our chat radius local chatRadius = 20 --units -- define a handler that will distribute the message to all nearby players function sendMessageToNearbyPlayers(message, messageType) -- we will only send normal chat messages, action and team types will be ignored if messageType == 0 then -- get the chatting player's position local posX1, posY1, posZ1 = getElementPosition(source) -- loop through all player and check distance 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(message, player) end end end -- block the original message by cancelling this event cancelEvent() end -- attach our new chat handler to onPlayerChat addEventHandler( "onPlayerChat", getRootElement(), sendMessageToNearbyPlayers ) Link to comment
mehmet Posted March 13, 2019 Share Posted March 13, 2019 (edited) 18 minutes ago, stPatrick said: Why not? And on the client side, you can? 4 minutes ago, XaskeL said: this code will bury the server. Use it: -- define our chat radius local chatRadius = 20 --units -- define a handler that will distribute the message to all nearby players function sendMessageToNearbyPlayers(message, messageType) -- we will only send normal chat messages, action and team types will be ignored if messageType == 0 then -- get the chatting player's position local posX1, posY1, posZ1 = getElementPosition(source) -- loop through all player and check distance 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(message, player) end end end -- block the original message by cancelling this event cancelEvent() end -- attach our new chat handler to onPlayerChat addEventHandler( "onPlayerChat", getRootElement(), sendMessageToNearbyPlayers ) Почему похоронит? И мог бы объяснить на какой части это лучше делать? на клиентской или серверной Edited March 13, 2019 by mehmet Link to comment
Moderators Patrick Posted March 13, 2019 Moderators Share Posted March 13, 2019 (edited) 7 minutes ago, mehmet said: And on the client side, you can? Почему похоронит? И мог бы объяснить на какой части это лучше делать? на клиентской или серверной I am not sure, but I think this is worse, because the loop check all players on the server. My script is check only players which near to you. (I don't know which better) Edited March 13, 2019 by stPatrick Link to comment
XaskeL Posted March 14, 2019 Share Posted March 14, 2019 7 hours ago, stPatrick said: Я не уверен, но я думаю, что это хуже, потому что цикл проверяет всех игроков на сервере. Мой скрипт проверяет только игроков, которые рядом с вами. (Я не знаю, что лучше) better to go through a few hundred players on the server. rather than creating an element, every message that will be synchronized with all clients regardless of distance and then destroyed by itself or one of the slowest functions in the MTA. This may lead to a drop in FPS for players with a large number of players and messages at the same time. Link to comment
mehmet Posted March 14, 2019 Share Posted March 14, 2019 (edited) 4 hours ago, XaskeL said: better to go through a few hundred players on the server. rather than creating an element, every message that will be synchronized with all clients regardless of distance and then destroyed by itself or one of the slowest functions in the MTA. This may lead to a drop in FPS for players with a large number of players and messages at the same time. Is this method slow? createColSphere List of players available on the client? (Список игроков можно получить на клиенте?) Edited March 14, 2019 by mehmet 1 Link to comment
JeViCo Posted March 14, 2019 Share Posted March 14, 2019 (edited) @RangerMind you should use separate table for this action as @mehmet said you should use createColSprere + onClientColShapeHit to insert players into table and then remove them when onClientColShapeLeave event triggers. By using onClientChatMessage event you can filter messages and display them from players, who are in your table This method won't affect performance much Edited March 14, 2019 by JeViCo 1 Link to comment
mehmet Posted March 14, 2019 Share Posted March 14, 2019 2 hours ago, JeViCo said: @RangerMind you should use separate table for this action as @mehmet said you should use createColSprere + onClientColShapeHit to insert players into table and then remove them when onClientColShapeLeave event triggers. By using onClientChatMessage event you can filter messages and display them from players, who are in your table This method won't affect performance much stop, which method is better? addEventHandler("onPlayerChat", getRootElement(), function(message) cancelEvent() local x, y, z = getElementPosition(source) local radius = createColSphere(x, y, z, 15) -- see the message in 15m radius local nearPlayers = getElementsWithinColShape(radius, "player") destroyElement(radius) for _, player in ipairs(nearPlayers) do if getElementDimension(player) == getElementDimension(source) then outputChatBox(getPlayerName(source)..": #FFFFFF"..message, player, 255, 255, 255, true) end end end) OR -- define our chat radius local chatRadius = 20 --units -- define a handler that will distribute the message to all nearby players function sendMessageToNearbyPlayers(message, messageType) -- we will only send normal chat messages, action and team types will be ignored if messageType == 0 then -- get the chatting player's position local posX1, posY1, posZ1 = getElementPosition(source) -- loop through all player and check distance 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(message, player) end end end -- block the original message by cancelling this event cancelEvent() end -- attach our new chat handler to onPlayerChat addEventHandler( "onPlayerChat", getRootElement(), sendMessageToNearbyPlayers ) Link to comment
XaskeL Posted March 14, 2019 Share Posted March 14, 2019 2 hours ago, mehmet said: стоп, какой метод лучше? ИЛИ ЖЕ 2 Link to comment
Mr.Loki Posted March 14, 2019 Share Posted March 14, 2019 Instead of using col shapes you can use getElementsWithinRange just sayin. Link to comment
Moderators Patrick Posted March 14, 2019 Moderators Share Posted March 14, 2019 29 minutes ago, Mr.Loki said: Instead of using col shapes you can use getElementsWithinRange just sayin. I know, but this is a new function, and not the best to check distance. Quote This function checks if elements are in a box, not in a circle. Z argument isn't in use currently, but make your scripts like it is for future compatibility reasons. 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