~Air Posted December 27, 2014 Share Posted December 27, 2014 Hey guys, when I am in no team and I press 'T' it doesn't show a message in the chatbox it gives an error out in the debugscript. Errors: 1. Bad argument @ 'getPlayersInTeam' [Expected 'team' at argument 1, got boolean] 2. bad argument #1 to 'ipairs' (table expected, got boolean) Code: local function playerChat(message, messageType) if messageType == 0 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") for i,team in ipairs(getPlayersInTeam(getPlayerTeam(source))) do local r,g,b = getTeamColor(getPlayerTeam(source)) if ( r ) and ( g ) and ( b ) then outputChatBox("(ALL): "..RGBToHex(r,g,b)..""..getPlayerName(source)..": "..color..""..message, root, 255, 255, 255, true ) else outputChatBox("(ALL): "..RGBToHex(r,g,b)..""..getPlayerName(source)..": #FFFFFF"..message, root, 255, 255, 255, true ) end end else outputChatBox("(ALL): "..RGBToHex(r,g,b)..""..getPlayerName(source)..": #FFFFFF"..message, root, 255, 255, 255, true ) end outputServerLog("CHAT: "..getPlayerName(source)..": "..message) end end end addEventHandler("onPlayerChat", root, playerChat) Link to comment
Castillo Posted December 27, 2014 Share Posted December 27, 2014 I guess you aren't in a team. Link to comment
~Air Posted December 27, 2014 Author Share Posted December 27, 2014 Yes because it is the normal chat. User should be able to write in the normal chat too. I already did one for the team. Link to comment
Castillo Posted December 27, 2014 Share Posted December 27, 2014 You put the wrong message type, 0 = normal, 2 = team. Link to comment
~Air Posted December 27, 2014 Author Share Posted December 27, 2014 Oh damn, haha didn't notice it because I copied it from my other script :D Thank you ! //closerequest Link to comment
~Air Posted December 27, 2014 Author Share Posted December 27, 2014 Oh no.. you didn't understand it. Don't close it. This is the normal chat and it should be. But the problem is: Players without team can't write in the normal chat because of that errors! Link to comment
Castillo Posted December 27, 2014 Share Posted December 27, 2014 Post your current code. Link to comment
~Air Posted December 28, 2014 Author Share Posted December 28, 2014 It's in the first post. Link to comment
Castillo Posted December 28, 2014 Share Posted December 28, 2014 I already told you how to fix that code. Link to comment
~Air Posted December 28, 2014 Author Share Posted December 28, 2014 No it isn't because of the messagetype. Normal chat = 0 thats right. But the problem is when I am in no team and write something in the normal chat I get those errors. Link to comment
Castillo Posted December 28, 2014 Share Posted December 28, 2014 local function playerChat ( message, messageType ) cancelEvent ( ) if ( messageType == 2 ) then 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 local r, g, b = getTeamColor ( team ) local name = getPlayerName ( source ) for _, team in ipairs ( getPlayersInTeam ( team ) ) do outputChatBox ( "(ALL): ".. RGBToHex ( r, g, b ) .."".. name ..": ".. ( color and color or "#FFFFFF" ) .."".. message, root, 255, 255, 255, true ) end end end elseif ( messageType == 0 ) then local r, g, b = getPlayerNametagColor ( source ) local name = getPlayerName ( source ) outputChatBox ( "(ALL): ".. RGBToHex ( r, g, b ) .."".. name ..": #FFFFFF".. message, root, 255, 255, 255, true ) outputServerLog ( "CHAT: ".. name ..": ".. message ) end end addEventHandler ( "onPlayerChat", root, playerChat ) Link to comment
~Air Posted December 28, 2014 Author Share Posted December 28, 2014 Thanks it worked! And I got one Language-chatbug I hope you can help me. ( I used account but I don't know why it doesn't work.) Errors: Bad argument @getPlayerAccount [expected account at argument 1, got boolean] Bad argument @isGuestAccount [expected account at argument 1, got boolean] Bad argument @getAccountData [expected account at argument 1, got boolean] Code: function LanguageChat(thePlayer, cmd, ...) local msg = table.concat({...}, " ") for _,players in ipairs(getElementsByType("player")) do local r, g, b = getPlayerNametagColor (thePlayer) local name = getPlayerName(thePlayer) local mycountry = exports.admin:getPlayerCountry(thePlayer) local playerscountry = exports.admin:getPlayerCountry(players) if (playerscountry == mycountry) then if (msg and msg ~= "") then local account = getPlayerAccount ( source ) if ( not isGuestAccount ( account ) ) then if ( getAccountData ( account, "chatc" ) and getElementData ( source, "Vip" ) == true ) then local color = getAccountData ( account, "chatc" ) for i,team in ipairs(getPlayersInTeam(getPlayerTeam(source))) do local r,g,b = getTeamColor(getPlayerTeam(source)) if ( r ) and ( g ) and ( b ) then outputChatBox("("..mycountry.."): "..RGBToHex(r,g,b)..""..name.."#ffffff: ".. color .. ""..msg.."",players,255, 255, 255,true) end end end end end end end end addCommandHandler("Language",LanguageChat) addEventHandler("onPlayerJoin",root, function () bindKey(source,"L","down","chatbox","Language") end ) addEventHandler("onResourceStart",resourceRoot, function () for index, player in ipairs(getElementsByType("player")) do bindKey(player,"L","down","chatbox","Language") end end ) Hope you can help me at this one too, I am very new to scripting sorry for those annoying questions. Link to comment
Castillo Posted December 28, 2014 Share Posted December 28, 2014 Bad argument @getPlayerAccount [expected account at argument 1, got boolean] That error doesn't make any sense, getPlayerAccount expects a player, not an account. Link to comment
~Air Posted December 28, 2014 Author Share Posted December 28, 2014 I changed 'source' to 'player' but it still doesn't work. Link to comment
Castillo Posted December 28, 2014 Share Posted December 28, 2014 Change it to 'thePlayer'. Link to comment
~Air Posted December 28, 2014 Author Share Posted December 28, 2014 Thanks! But now I get this error: Expected element at argument 1 Line: if ( getAccountData ( account, "chatc" ) and getElementData ( source, "Vip" ) == true ) then Link to comment
Addlibs Posted December 28, 2014 Share Posted December 28, 2014 if ( getAccountData ( account, "chatc" ) and getElementData ( thePlayer, "Vip" ) == true ) then source => thePlayer in getElementData Link to comment
~Air Posted December 28, 2014 Author Share Posted December 28, 2014 Thanks, I fixxed the rest by myself! 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