RangerMind

how to disable global chat on MTA Server (RPG)

Recommended Posts

 

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 :(

 

Share this post


Link to post
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 by Patrick2562

Share this post


Link to post

thanks you

please give me a faction system

PD , FBI , NG , Medic , NR And More . . . . . . 

 

Quote

 

 

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
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 )

 

Share this post


Link to post
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 by mehmet

Share this post


Link to post
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 by stPatrick

Share this post


Link to post
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.

Share this post


Link to post
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 by mehmet
  • Like 1

Share this post


Link to post

@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 by JeViCo
  • Thanks 1

Share this post


Link to post
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 )

 

Share this post


Link to post
2 hours ago, mehmet said:

стоп, 

какой метод лучше?


  
	
        
     
       
      
    
        
        
            
                 
        
    

ИЛИ ЖЕ



  



    
      
        
         

        
            
             
              
                 
            
        
    
    
    


  

 

2

Share this post


Link to post
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.

 

Share this post


Link to post

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.