-.Paradox.- Posted April 11, 2014 Share Posted April 11, 2014 Hello, i have a problem here, when i try to chat in team chat, everybody can see the message that i wrote and same thing happening to other teams chat, If you don't understand what i mean, is that when i write in team chat, everybody can read the message like local chat, hope somebody help, thanks. function RGBToHex(red, green, blue) if((red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255)) then return nil end return string.format("#%.2X%.2X%.2X", red, green, blue) end local function onplayerChat ( message, messageType ) if ( messageType == 2 ) then --Team (Clan) chat cancelEvent ( ) local name = getPlayerName ( source ) local red, green, blue = getPlayerNametagColor ( source ) local hex = RGBToHex ( red, green, blue ) outputChatBox( "#9AFE2E(CLAN)" .. hex.." "..name .. ":#FFFFFF" .. message, root, 255, 255, 255, true ) outputServerLog( "(TEAM): " .. name .. ": " .. message )--NOTE: Beacuse we cancelled the onPlayerChat event, we need to log chat manually. end end addEventHandler ( "onPlayerChat", root, onplayerChat ) function nickChangeHandler() if isPlayerMuted ( source ) then outputChatBox("You are muted.", source, 100, 0, 0) cancelEvent() end end addEventHandler("onPlayerChangeNick", getRootElement(), nickChangeHandler) Link to comment
Moderators Citizen Posted April 11, 2014 Moderators Share Posted April 11, 2014 You were displaying the message to root (which means everyone). local function onplayerChat ( message, messageType ) if ( messageType == 2 ) then --Team (Clan) chat cancelEvent ( ) local name = getPlayerName ( source ) local red, green, blue = getPlayerNametagColor ( source ) local hex = RGBToHex ( red, green, blue ) local team = getPlayerTeam( source ) if not team then return outputChatBox( "You are not part of a team yet !", source, 200, 0, 0) end -- We have to get all the team members instead of using root local members = getPlayersInTeam( team ) or {} outputChatBox( "#9AFE2E(CLAN)" .. hex.." "..name .. ":#FFFFFF" .. message, members, 255, 255, 255, true ) outputServerLog( "(TEAM): " .. name .. ": " .. message ) end end addEventHandler ( "onPlayerChat", root, onplayerChat ) Link to comment
TAPL Posted April 12, 2014 Share Posted April 12, 2014 I think outputChatBox doesn't accept table, so in case Citizen code doesn't work, try this: local function onplayerChat ( message, messageType ) if ( messageType == 2 ) then --Team (Clan) chat cancelEvent ( ) local name = getPlayerName ( source ) local red, green, blue = getPlayerNametagColor ( source ) local hex = RGBToHex ( red, green, blue ) local team = getPlayerTeam( source ) if not team then return outputChatBox( "You are not part of a team yet !", source, 200, 0, 0) end -- We have to get all the team members instead of using root local members = getPlayersInTeam( team ) or {} for _, player in ipairs(members) do outputChatBox( "#9AFE2E(CLAN)" .. hex.." "..name .. ":#FFFFFF" .. message, player, 255, 255, 255, true ) end outputServerLog( "(TEAM): " .. name .. ": " .. message ) end end addEventHandler ( "onPlayerChat", root, onplayerChat ) Link to comment
Moderators Citizen Posted April 12, 2014 Moderators Share Posted April 12, 2014 I think outputChatBox doesn't accept table Well, you are probably right, I don't know why but I thought getRootElement() was returning a table. But if the outputChatBox is looking for the children of the element (like root for example) we can then probably create an element and put the team members as children of it and then send that element as argument. (I know ur loop is a way better, it's just to share this possible solution.) But then, if the team element has the members as children, we can probably try to do an outputChatBox on team instead of root I'll test this out this week-end. Link to comment
.:HyPeX:. Posted April 12, 2014 Share Posted April 12, 2014 for i=1, countPlayersInTeam(TEAM) do outputChatBox("", i) end Link to comment
Saml1er Posted April 12, 2014 Share Posted April 12, 2014 for i=1, countPlayersInTeam(TEAM) do outputChatBox("", i) end That won't work, its like. outputChatBox("", 1) outputChatBox("", 2) outputChatBox("", 3) ............ ...... Link to comment
.:HyPeX:. Posted April 12, 2014 Share Posted April 12, 2014 Dude, you know how it works? i will be 1,2,3,4,5 (Or until whatever number the count returns) and it will work.. Eg: for i=1, 10 do outputChatBox(i, getRootElement()) end Will output: 1 2 3 4 5 6 7 8 9 10 Anyways yes, it wont work if based on a team and not a table. for i,v in ipairs(getPlayersInTeam(TEAM)) do outputChatBox("text", v) end But if table members.. for i=1, #members do outputChatBox("text", members[i]) end Link to comment
Saml1er Posted April 12, 2014 Share Posted April 12, 2014 Dude, you know how it works? i will be 1,2,3,4,5 (Or until whatever number the count returns) and it will work..Eg: for i=1, 10 do outputChatBox(i, getRootElement()) end Will output: 1 2 3 4 5 6 7 8 9 10 Anyways yes, it wont work if based on a team and not a table. for i,v in ipairs(getPlayersInTeam(TEAM)) do outputChatBox("text", v) end But if table members.. for i=1, #members do outputChatBox("text", members[i]) end Read your code again. outputChatBox ( "", i) -- Do you see it now? the "i" is in the second arg which is totally wrong. _____________________________________________________________________________________________________________ for i=1, 10 do outputChatBox(i, getRootElement()) end And yes this will work ofc, I never said anything about this. Link to comment
.:HyPeX:. Posted April 12, 2014 Share Posted April 12, 2014 Its supposed that I will go to a player, inside table position I, not to work alone imo. Link to comment
Mr_Moose Posted April 12, 2014 Share Posted April 12, 2014 The second argument in outputChatBox is optional with root as default value, passing any argument that isn't acceptable will either generate errors or output your text to root. There might be a solution to pass a team as argument if you can convert it to an element tree structure. Otherwise it will most likely fall back to root and the team messages keeps showing for all players online. I would recommend the loop based on the table of team members that's probably the easiest solution. Link to comment
TAPL Posted April 12, 2014 Share Posted April 12, 2014 Idk what are you on about, I already posted it in loop. Link to comment
Moderators Citizen Posted April 12, 2014 Moderators Share Posted April 12, 2014 They are just trying to make HyPeX understand his code is totally wrong and won't work at all, because he was sure his code was fine without testing it at all. @Nikolai96: Just use TAPL's code (3rd post) Link to comment
-.Paradox.- Posted April 14, 2014 Author Share Posted April 14, 2014 Thank you TAPL and Citizen. 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