Jump to content

MTA Global chat script


Recommended Posts

Hello, I am making a RP server and I have a script, that disables the global chat and only shows the chat from a radios. My question is, where do I have to put

this script to work? I am a beginner in scripting so please dont judge me :D 

The script:

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
  • Scripting Moderators

On server-side in any resource. If you don't have one, just create it.
You'd need a folder (which would be your resource name), inside this folder, there should be meta.xml and server.lua (which will contain your code).
Your meta would look like this.
 

<meta>
	<script src="server.lua" type="server"/>
</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...