v0nz Posted July 10, 2008 Share Posted July 10, 2008 -- 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 posX, posY, posZ = getElementPosition( source ) -- create a sphere of the specified radius in that position local chatSphere = createColSphere( posX, posY, posZ, chatRadius ) -- get a table all player elements inside it local nearbyPlayers = getElementsWithinColShape( chatSphere, "player" ) -- and destroy the sphere, since we're done with it destroyElement( chatSphere ) -- deliver the message to each player in that table for index, nearbyPlayer in ipairs( nearbyPlayers ) do outputChatBox( message, nearbyPlayer ) end end end -- attach our new chat handler to onPlayerChat addEventHandler( "onPlayerChat", getRootElement(), sendMessageToNearbyPlayers ) -- define another handler function that cancels the event so that the message won't be delivered through the function blockChatMessage() cancelEvent() end -- attach it as a handler to onPlayerChat addEventHandler( "onPlayerChat", getRootElement(), blockChatMessage ) I am trying to make it... A name: "Chat" I was looking at outputChatBox( message, nearbyPlayer ). Adding getClientName: does not work. Link to comment
icedsun Posted July 12, 2008 Share Posted July 12, 2008 You just pasted an example straight from the wiki entry for the onPlayerChat() event... It should work just fine. What are you trying to do to modify it??? And that example is for server-side code, so make sure you're running it that way. Link to comment
robhol Posted July 12, 2008 Share Posted July 12, 2008 Also, learn to use the proper subforums! This is NOT an add-on, it's a normal script. Link to comment
v0nz Posted July 12, 2008 Author Share Posted July 12, 2008 Im just trying to make it have a name before the text such as... "v0nz: I like to type". And yes, I know, its serversided. Link to comment
robhol Posted July 13, 2008 Share Posted July 13, 2008 This is scripting, the topic should be there. Link to comment
Recommended Posts