~Air Posted January 31, 2015 Share Posted January 31, 2015 Hey guys, I got again a problem. So a player that hasn't got a chatcolor and writes in the teamchat, the message will be displayed to everyone. Only if a player has got a chatcolor the message will be only shown on the teamchat. Could someone help me please? local function teamChat(message, messageType) if messageType == 2 then cancelEvent() local acc = getPlayerAccount(source) if not isGuestAccount(acc) then if getAccountData(acc,"chatc") and getElementData(source, "Vip") == true then local color = getAccountData(acc,"chatc") local team = getPlayerTeam ( source ) if ( not team ) then return end for _, team in ipairs ( getPlayersInTeam ( team ) ) do outputChatBox("(TEAM): " ..getPlayerName(source)..": "..color..""..message, team, 255, 255, 255, true ) end else outputChatBox("(TEAM): " ..getPlayerName(source)..": #FFFFFF"..message, team, 255, 255, 255, true ) end else outputChatBox("(TEAM): "..getPlayerName(source)..": #FFFFFF"..message, team, 255, 255, 255, true ) end outputServerLog("CHAT: "..getPlayerName(source)..": "..message) end end addEventHandler("onPlayerChat", root, teamChat) Link to comment
John Smith Posted January 31, 2015 Share Posted January 31, 2015 not sure but reason might be that variable team is being conflicted at line 13 Link to comment
4O4 Posted February 1, 2015 Share Posted February 1, 2015 (edited) You're defining local team variable in line 9 and it only exists in that scope. For more information check this http://lua-users.org/wiki/ScopeTutorial The for loop is unnecessary. My suggestion is to put lines 9-12 just after "local acc..." so all of your code that depends on "team" is in the same scope. Also the for loop needs to be repeated two more times. local function teamChat(message, messageType) if messageType == 2 then cancelEvent() local acc = getPlayerAccount(source) local team = getPlayerTeam ( source ) if ( not team ) then return end if not isGuestAccount(acc) then if getAccountData(acc,"chatc") and getElementData(source, "Vip") == true then local color = getAccountData(acc,"chatc") for _, player in ipairs(getPlayersInTeam(team)) do outputChatBox("(TEAM): " .. getPlayerName(source) .. ": " .. color .. message, player, 255, 255, 255, true) end else for _, player in ipairs(getPlayersInTeam(team)) do outputChatBox("(TEAM): " .. getPlayerName(source) .. ": #FFFFFF" .. message, player, 255, 255, 255, true) end end else for _, player in ipairs(getPlayersInTeam(team)) do outputChatBox("(TEAM): " .. getPlayerName(source) .. ": #FFFFFF" .. message, player, 255, 255, 255, true ) end end outputServerLog("CHAT: "..getPlayerName(source)..": "..message) end end addEventHandler("onPlayerChat", root, teamChat) Edited February 1, 2015 by Guest Link to comment
~Air Posted February 1, 2015 Author Share Posted February 1, 2015 Still doesn't work 4O4 Link to comment
TAPL Posted February 1, 2015 Share Posted February 1, 2015 outputChatBox doesn't seems to work with team element, therefore you will have to make the loop. Link to comment
4O4 Posted February 1, 2015 Share Posted February 1, 2015 outputChatBox doesn't seems to work with team element, therefore you will have to make the loop. Oops! You're right, my bad. I've been always using custom team elements and forgot that this doesn't work by default. I'll edit the code. 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