orangetom1 Posted November 17, 2009 Share Posted November 17, 2009 i need to put a colour for example when i say something it would be in red this is the script so far: local chatRadius = 25 --units function sendMessageToNearbyPlayers( message, messageType ) if messageType == 1 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 outputChatBox( message, nearbyPlayer ) end end end addEventHandler( "onPlayerChat", getRootElement(), sendMessageToNearbyPlayers ) function blockChatMessage() cancelEvent() end addEventHandler( "onPlayerChat", getRootElement(), blockChatMessage ) function onChat ( message, messageType ) if messageType == 0 then local root = getRootElement() outputChatBox ( getPlayerName ( source ) .. .. message, getRootElement(), true ) cancelEvent() end end addEventHandler ( "onPlayerChat", getRootElement(), onChat )See Also Link to comment
Exploit Posted November 17, 2009 Share Posted November 17, 2009 I don't know why you did those 2 extra functions 'onChat' and 'blockChatMessage' so I removed them. Basically to display the chat in color all you had to do is add the color you wanted in hex format Red in hex format is #FF0000 chatRadius = 25 -- Units function sendMessageToNearbyPlayers( message, messageType ) if messageType == 1 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 -- PUT COLOR IN HEX format, example red = #FF0000 outputChatBox ( "#FF0000" .. getPlayerName ( source ) .. " says: " .. message, nearbyPlayer ) end end end addEventHandler( "onPlayerChat", getRootElement(), sendMessageToNearbyPlayers ) Link to comment
Dark Dragon Posted November 18, 2009 Share Posted November 18, 2009 unfortunately your hex code will fail coloring anything as long as you don't allow color code to be used in outputChatBox's arguments (it's disabled by default). you also forget to add cancelEvent(), in the current form you would see everything on the chat twice. chatRadius = 25 -- Units function sendMessageToNearbyPlayers( message, messageType ) if messageType == 1 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 -- PUT COLOR IN HEX format, example red = #FF0000 outputChatBox ( "#FF0000" .. getPlayerName ( source ) .. " says: " .. message, nearbyPlayer,255,255,255,true ) end cancelEvent() end end addEventHandler( "onPlayerChat", getRootElement(), sendMessageToNearbyPlayers ) besides, i guess he wants to have different players having different colors. for your use i'd suggest screwing the colshape and just use getDistanceBetweenPoints3D for each player (getElementsByType("player")) element and the player who sent it, for the colors you could just use getPlayerNametagColor or get/setElementData of course you can keep it the way you currently do it and just use getPlayerNametagColor or get/setElementData and the color argument in outputChatBox in both cases you should use the color code to color the text after the players name in some neutral color 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