Jump to content

Chatbug


~Air

Recommended Posts

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
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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...