Sign in to follow this  
Fullton

[Question]: Team colour in chatbox and dx-messages

Recommended Posts

Hello, community! I was interested how to put team colour with nickname in messages.

Look at this image. First part of name with tag of team is without colour:

aGTifIM.png

Here you can see my colour of team only in simple chat.

I used this:

outputChatBox("#ffffff"..getPlayerNametagText(source).." #ff0000has been muted for spam", getRootElement(), 255, 255, 0,true) 

The same thing is with dxDrawText:

O1pufUk.png

I will be very glad if you give me any help.

Share this post


Link to post

If you mean message color, you can use community created function rGBToHex

Example:

local r, g, b = getPlayerNametagColor(source) 
color = tocolor(r, g, b) 
outputChatBox("#ffffff"..getPlayerNametagText(source).. "" .. RGBToHex(r, g, b) .. " has been muted for spam", getRootElement(), 255, 255, 0,true) 
  
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 

Share this post


Link to post
If you mean message color, you can use community created function rGBToHex

Example:

local r, g, b = getPlayerNametagColor(source) 
color = tocolor(r, g, b) 
outputChatBox("#ffffff"..getPlayerNametagText(source).. "" .. RGBToHex(r, g, b) .. " has been muted for spam", getRootElement(), 255, 255, 0,true) 
  
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 

tocolor gets a nil value.

I saw function that gets player's team color in script nametags(not standart) and downloaded from community but i lost this script and fuction.

Share this post


Link to post
tocolor gets a nil value.

I saw function that gets player's team color in script nametags(not standart) and downloaded from community but i lost this script and fuction.

So do you want team color to message or team color to name or both?

Btw that tocolor was mistake, you can remove the line. And remove local front of r, g, b.

Share this post


Link to post
So do you want team color to message or team color to name or both?

Both. Team color and player name. getPlayerNametagText gets only colored name without team color.

Share this post


Link to post

Maybe this:

add to start:

addEventHandler("onPlayerJoin", root, 
function() 
    local team = getPlayerTeam(source) 
    local tr, tg, tb = getTeamColor(team) 
    setPlayerNameTagColor(tr, tg, tb) 
end 
) 

Mute message:

local team = getPlayerTeam(source) 
local tr, tg, tb = getTeamColor(team) 
outputChatBox("#ffffff"..getPlayerNametagText(source).. "" .. RGBToHex(tr, tg, tb) .. " has been muted for spam", getRootElement(), 255, 255, 0,true) 

Then add this to somewhere to script:

function playerChat(message, messageType) 
    if messageType == 0 then 
        cancelEvent() 
        local r, g, b = getPlayerNametagColor(source) 
        outputChatBox(RGBToHex(r, g, b) .. "" .. getPlayerNameTag(source)..": ".. message, root, r, g, b, true) 
    end 
end 
addEventHandler("onPlayerChat", root, playerChat) 

And you need this function every script you use colored messages:

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 

Share this post


Link to post
Maybe this:

add to start:

addEventHandler("onPlayerJoin", root, 
function() 
    local team = getPlayerTeam(source) 
    local tr, tg, tb = getTeamColor(team) 
    setPlayerNameTagColor(tr, tg, tb) 
end 
) 

Mute message:

local team = getPlayerTeam(source) 
local tr, tg, tb = getTeamColor(team) 
outputChatBox("#ffffff"..getPlayerNametagText(source).. "" .. RGBToHex(tr, tg, tb) .. " has been muted for spam", getRootElement(), 255, 255, 0,true) 

Then add this to somewhere to script:

function playerChat(message, messageType) 
    if messageType == 0 then 
        cancelEvent() 
        local r, g, b = getPlayerNametagColor(source) 
        outputChatBox(RGBToHex(r, g, b) .. "" .. getPlayerNameTag(source)..": ".. message, root, r, g, b, true) 
    end 
end 
addEventHandler("onPlayerChat", root, playerChat) 

And you need this function every script you use colored messages:

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 

oh. just coloured name and so hard. ty.

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.