Jump to content

Chatbug


~Air

Recommended Posts

Posted

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) 

Posted

I guess you aren't in a team.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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.

Posted

You put the wrong message type, 0 = normal, 2 = team.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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!

Posted

Post your current code.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I already told you how to fix that code.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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.

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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.

Posted
Bad argument @getPlayerAccount [expected account at argument 1, got boolean]

That error doesn't make any sense, getPlayerAccount expects a player, not an account.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Change it to 'thePlayer'.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Thanks!

But now I get this error:

Expected element at argument 1

Line:

if ( getAccountData ( account, "chatc" ) and getElementData ( source, "Vip" ) == true ) then

Posted

if ( getAccountData ( account, "chatc" ) and getElementData ( thePlayer, "Vip" ) == true ) then 

source => thePlayer in getElementData

Previously known as MrTasty.

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