Jump to content

Team Color Chat


Overkillz

Recommended Posts

You want to set player's nick colored his team's color on chat? If so

function RGBToHex ( red, green, blue, alpha ) 
    if( ( red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255 ) or ( alpha and ( alpha < 0 or alpha > 255 ) ) ) then 
        return nil 
    end 
    if ( alpha ) then 
        return string.format ( "#%.2X%.2X%.2X%.2X", red, green, blue, alpha ) 
    else 
        return string.format ( "#%.2X%.2X%.2X", red, green, blue ) 
    end 
end 
  
addEventHandler ( "onPlayerChat", root, 
    function ( message, messageType ) 
    if ( messageType == 0 ) then 
        cancelEvent ( ) 
        local team = getPlayerTeam ( source ) 
        if ( team ) then 
            local r, g, b = getTeamColor ( team ) 
            local hexCode = RGBToHex ( r, g, b ) 
             
            local name = getPlayerName ( source ) 
            outputChatBox ( hexCode .. name .. "#FFFFFF: " .. message, root, 255, 255, 255, true ) 
        end 
    end 
) 

Link to comment
You want to set player's nick colored his team's color on chat? If so
function RGBToHex ( red, green, blue, alpha ) 
    if( ( red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255 ) or ( alpha and ( alpha < 0 or alpha > 255 ) ) ) then 
        return nil 
    end 
    if ( alpha ) then 
        return string.format ( "#%.2X%.2X%.2X%.2X", red, green, blue, alpha ) 
    else 
        return string.format ( "#%.2X%.2X%.2X", red, green, blue ) 
    end 
end 
  
addEventHandler ( "onPlayerChat", root, 
    function ( message, messageType ) 
    if ( messageType == 0 ) then 
        cancelEvent ( ) 
        local team = getPlayerTeam ( source ) 
        if ( team ) then 
            local r, g, b = getTeamColor ( team ) 
            local hexCode = RGBToHex ( r, g, b ) 
             
            local name = getPlayerName ( source ) 
            outputChatBox ( hexCode .. name .. "#FFFFFF: " .. message, root, 255, 255, 255, true ) 
        end 
    end 
) 

Doesn't work ;(

http://puu.sh/7Ltkt.png

Link to comment
  
function RGBToHex ( red, green, blue, alpha ) 
    if( ( red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255 ) or ( alpha and ( alpha < 0 or alpha > 255 ) ) ) then 
        return nil 
    end 
    if ( alpha ) then 
        return string.format ( "#%.2X%.2X%.2X%.2X", red, green, blue, alpha ) 
    else 
        return string.format ( "#%.2X%.2X%.2X", red, green, blue ) 
    end 
end 
  
addEventHandler ( "onPlayerChat", root, 
    function ( message, messageType ) 
    if ( messageType == 2 ) then 
        cancelEvent ( ) 
        local team = getPlayerTeam ( source ) 
        if ( team ) then 
            local r, g, b = getTeamColor ( team ) 
            local hexCode = RGBToHex ( r, g, b ) 
            
            local name = getPlayerName ( source ) 
            outputChatBox ( hexCode .. name .. "#FFFFFF: " .. message, root, 255, 255, 255, true ) 
        end 
    end 
) 
  

Link to comment
  
function RGBToHex ( red, green, blue, alpha ) 
    if( ( red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255 ) or ( alpha and ( alpha < 0 or alpha > 255 ) ) ) then 
        return nil 
    end 
    if ( alpha ) then 
        return string.format ( "#%.2X%.2X%.2X%.2X", red, green, blue, alpha ) 
    else 
        return string.format ( "#%.2X%.2X%.2X", red, green, blue ) 
    end 
end 
  
addEventHandler ( "onPlayerChat", root, 
    function ( message, messageType ) 
    if ( messageType == 2 ) then 
        cancelEvent ( ) 
        local team = getPlayerTeam ( source ) 
        if ( team ) then 
            local r, g, b = getTeamColor ( team ) 
            local hexCode = RGBToHex ( r, g, b ) 
            
            local name = getPlayerName ( source ) 
            outputChatBox ( hexCode .. name .. "#FFFFFF: " .. message, root, 255, 255, 255, true ) 
        end 
    end 
) 
  

Still unworking ;(

Link to comment
addEventHandler ( "onPlayerChat", root, 
    function ( message, messageType ) 
        if ( messageType == 2 ) then 
            cancelEvent ( ) 
             
            local name = getPlayerName ( source ) 
            local team = getPlayerTeam ( source ) 
            for _, player in ipairs ( getElementsByType ( "player" ) ) do 
                if ( getPlayerTeam ( player ) == team ) then 
                    outputChatBox ( name .. "#FFFFFF: " .. message, player, 255, 255, 255, true ) 
                end 
            end 
        end 
    end 
) 

Check this out ( serverside script ).

Link to comment
addEventHandler ( "onPlayerChat", root, 
    function ( message, messageType ) 
        if ( messageType == 2 ) then 
            cancelEvent ( ) 
             
            local name = getPlayerName ( source ) 
            local team = getPlayerTeam ( source ) 
            for _, player in ipairs ( getElementsByType ( "player" ) ) do 
                if ( getPlayerTeam ( player ) == team ) then 
                    outputChatBox ( name .. "#FFFFFF: " .. message, player, 255, 255, 255, true ) 
                end 
            end 
        end 
    end 
) 

Check this out ( serverside script ).

Thanks so much, this workfine ^^

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