Jump to content

Localchat.


Rat32

Recommended Posts

Posted
local chatRadius = 50 
  
function sendMessageToNearbyPlayers ( message, messageType ) 
    if ( messageType == 0 ) then 
        local posX, posY, posZ = getElementPosition ( source ) 
  
        local chatSphere = createColSphere ( posX, posY, posZ, chatRadius ) 
        local nearbyPlayers = getElementsWithinColShape ( chatSphere, "player" ) 
        destroyElement ( chatSphere ) 
  
        for index, nearbyPlayer in ipairs( nearbyPlayers ) do 
            local red, green, blue = getPlayerNametagColor ( source ) 
            outputChatBox( getPlayerName ( source )..": #ffffff".. message, nearbyPlayer, red, green, blue, true ) 
        end 
        cancelEvent ( ) 
    end 
end 
addEventHandler ( "onPlayerChat", getRootElement(), sendMessageToNearbyPlayers ) 
  
  
addEventHandler ( "onPlayerChat", getRootElement(), 
function ( message, messageType ) 
    if messageType == 1 then 
        cancelEvent() 
    end 
end) 

Why this doesn't work? Sends a double message, does not close the event.

Posted

He didn't wrote that at first time

* He edited it

and colshape for that i think gives lagg, why don't u use math better than creating colshapes

get distance then check if distance is lower then 15 or something then cancel event and output again

  • Moderators
Posted

It is probably sending double messages because you are using the freeroam resource, which is also using this event.

Or some other resource.

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...