~Air Posted January 3, 2015 Share Posted January 3, 2015 Hey guys, I am back with an another problem but I don't know what's false, there is no error. Here is the code: -- Teamchat local function playerChat(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") outputChatBox("(TEAM): " ..getPlayerName(source)..": "..color..""..message, root, 255, 255, 255, true ) else outputChatBox("(TEAM): " ..getPlayerName(source)..": #FFFFFF"..message, root, 255, 255, 255, true ) end else outputChatBox("(TEAM): "..getPlayerName(source)..": #FFFFFF"..message, root, 255, 255, 255, true ) end outputServerLog("CHAT: "..getPlayerName(source)..": "..message) end end addEventHandler("onPlayerChat", root, playerChat) Link to comment
MTA Team botder Posted January 3, 2015 MTA Team Share Posted January 3, 2015 He sends the message to every player (root) and wonders why everyone can see the message. Link to comment
Castillo Posted January 3, 2015 Share Posted January 3, 2015 Yeah, I noticed that, but he's not even stating what is the problem with his code. Link to comment
MTA Team botder Posted January 3, 2015 MTA Team Share Posted January 3, 2015 Thread title: Teamchat shows on globalchat (messageType == 2) Link to comment
Castillo Posted January 3, 2015 Share Posted January 3, 2015 Oh, my bad, I didn't read that part, still, it would be good if he put it on the actual topic aswell. Link to comment
~Air Posted January 3, 2015 Author Share Posted January 3, 2015 Sorry, that I didn't write it in the topic So the problem is if you press Y (messageType == 2) everyone can read this message if he isn't in a team or in an another team. Link to comment
Castillo Posted January 3, 2015 Share Posted January 3, 2015 Well, that's obvious, isn't it? do you see any team-related function in that code? Link to comment
~Air Posted January 3, 2015 Author Share Posted January 3, 2015 Oh.. yeah sorry im so dumb, but thanks. I'll fix it by myself. Link to comment
~Air Posted January 5, 2015 Author Share Posted January 5, 2015 Here is my new code: it's still the same problem: everyone can see it. local function playerChat(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, root, 255, 255, 255, true ) end else outputChatBox("(TEAM): " ..getPlayerName(source)..": #FFFFFF"..message, root, 255, 255, 255, true ) end else outputChatBox("(TEAM): "..getPlayerName(source)..": #FFFFFF"..message, root, 255, 255, 255, true ) end outputServerLog("CHAT: "..getPlayerName(source)..": "..message) end end addEventHandler("onPlayerChat", root, playerChat) Link to comment
Anubhav Posted January 5, 2015 Share Posted January 5, 2015 You are outputing it to root. Link to comment
~Air Posted January 5, 2015 Author Share Posted January 5, 2015 What should I use instead? Link to comment
Castillo Posted January 5, 2015 Share Posted January 5, 2015 for _, team in ipairs ( getPlayersInTeam ( team ) ) do outputChatBox("(TEAM): " ..getPlayerName(source)..": "..color..""..message, root, 255, 255, 255, true ) end You must change 'root' to 'team'. Link to comment
~Air Posted January 5, 2015 Author Share Posted January 5, 2015 for _, team in ipairs ( getPlayersInTeam ( team ) ) do outputChatBox("(TEAM): " ..getPlayerName(source)..": "..color..""..message, root, 255, 255, 255, true ) end --> to: for _, team in ipairs ( getPlayersInTeam ( team ) ) do outputChatBox("(TEAM): " ..getPlayerName(source)..": "..color..""..message, team, 255, 255, 255, true ) end ? Link to comment
~Air Posted January 5, 2015 Author Share Posted January 5, 2015 Also the EventHandler? Link to comment
Castillo Posted January 5, 2015 Share Posted January 5, 2015 You don't have to change event handler. Link to comment
~Air Posted January 6, 2015 Author Share Posted January 6, 2015 That's my script, but I can see it anyway. 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
Castillo Posted January 6, 2015 Share Posted January 6, 2015 That's because "team" is nil outside that 'if' statement. 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