~Air Posted January 3, 2015 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)
MTA Team botder Posted January 3, 2015 MTA Team Posted January 3, 2015 He sends the message to every player (root) and wonders why everyone can see the message.
Castillo Posted January 3, 2015 Posted January 3, 2015 Yeah, I noticed that, but he's not even stating what is the problem with his code.
MTA Team botder Posted January 3, 2015 MTA Team Posted January 3, 2015 Thread title: Teamchat shows on globalchat (messageType == 2)
Castillo Posted January 3, 2015 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.
~Air Posted January 3, 2015 Author 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.
Castillo Posted January 3, 2015 Posted January 3, 2015 Well, that's obvious, isn't it? do you see any team-related function in that code?
~Air Posted January 3, 2015 Author Posted January 3, 2015 Oh.. yeah sorry im so dumb, but thanks. I'll fix it by myself.
~Air Posted January 5, 2015 Author 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)
Castillo Posted January 5, 2015 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'.
~Air Posted January 5, 2015 Author 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 ?
~Air Posted January 6, 2015 Author 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)
Castillo Posted January 6, 2015 Posted January 6, 2015 That's because "team" is nil outside that 'if' statement.
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