Jump to content

Nametagcolor


Recommended Posts

Hello all,

I want a little script, if player was in team Test he's nametagcolor and blip must be same as team color, i want to make a script like that.

Well, i tried this using this but need some functions,

r, g, b = getTeamColor(teamElement) 
setPlayerNametagColor(playerElement, r, g ,b) 

Can somebody help me with a code or someting elser thanks :)

Link to comment

didn't test, but should work:

  
blip = {} 
  
function spawn(posX, posY, posZ, spawnRotation, theTeam, theSkin, theInterior, theDimension) 
    if(not isElement(blip[getPlayerName(source)])) then blip[getPlayerName(source)] = createBlipAttachedTo(source) end 
    if(getTeamName(theTeam) == 'test') then 
        local r, g, b = getTeamColor(theTeam) 
        setPlayerNametagColor(source, r, g, b) 
        setBlipColor(blip[getPlayerName(source)], r, g, b, 255) 
    end 
end 
  
addEventHandler('onPlayerSpawn', getRootElement(), spawn) 
  

this is server-side script !

Link to comment

What if the player changes their name?

The table wont free it until the resource is restarted/stopped.

Anyways, try this:

local blip = {} 
  
addEventHandler('onPlayerSpawn',root, function(_, _, _, _, theTeam) 
    if (not isElement(blip[source])) then blip[source] = createBlipAttachedTo(source) end 
    if(getTeamName(theTeam) == 'test') then 
        local r, g, b = getTeamColor(theTeam) 
        setPlayerNametagColor(source, r, g, b) 
        setBlipColor(blip[source], r, g, b, 255) 
    end 
end) 
setTimer(function() 
    for source,b in pairs(blip)do 
        if not isElement(source) then 
            destroyElement(b) 
            blip[source] = false 
        end 
    end 
end,10000,0) 

Edited by Guest
Link to comment

ok, try this:

local blip = {} 
  
addEventHandler('onPlayerSpawn',root, function(_, _, _, _, theTeam) 
    if (not isElement(blip[source])) then blip[source] = createBlipAttachedTo(source) end 
    local r, g, b = getTeamColor(theTeam) 
    setPlayerNametagColor(source, r, g, b) 
    setBlipColor(blip[source], r, g, b, 255) 
end) 
setTimer(function() 
    for source,b in pairs(blip)do 
        if not isElement(source) then 
            destroyElement(b) 
            blip[source] = false 
        end 
    end 
end,10000,0) 

Link to comment
ok, try this:
local blip = {} 
  
addEventHandler('onPlayerSpawn',root, function(_, _, _, _, theTeam) 
    if (not isElement(blip[source])) then blip[source] = createBlipAttachedTo(source) end 
    local r, g, b = getTeamColor(theTeam) 
    setPlayerNametagColor(source, r, g, b) 
    setBlipColor(blip[source], r, g, b, 255) 
end) 
setTimer(function() 
    for source,b in pairs(blip)do 
        if not isElement(source) then 
            destroyElement(b) 
            blip[source] = false 
        end 
    end 
end,10000,0) 

Where is the 2nd argument of the function createBlipAttachedTo.

Link to comment
local blip = { } 
  
addEventHandler ( "onPlayerLogin", root, 
    function ( ) 
        if ( not isElement ( blip [ source ] ) ) then 
            blip [ source ] = createBlipAttachedTo ( source ) 
        end 
  
        local theTeam = getPlayerTeam ( source ) 
        if ( not theTeam ) then 
            return 
        end 
  
        local r, g, b = getTeamColor ( theTeam ) 
        setPlayerNametagColor ( source, r, g, b ) 
        setBlipColor ( blip [ source ], r, g, b, 255 ) 
    end 
) 
  
addEventHandler ( "onPlayerQuit", root, 
    function ( ) 
        if isElement ( blip [ source ] ) then 
            destroyElement ( blip [ source ] ) 
        end 
    end 
) 

Link to comment
local blip = { } 
  
addEventHandler ( "onPlayerLogin", root, 
    function ( ) 
        if ( not isElement ( blip [ source ] ) ) then 
            blip [ source ] = createBlipAttachedTo ( source ) 
        end 
  
        local theTeam = getPlayerTeam ( source ) 
        if ( not theTeam ) then 
            outputChatBox ( "YOU HAVE NO TEAM", source ) 
            return 
        end 
  
        local r, g, b = getTeamColor ( theTeam ) 
        setPlayerNametagColor ( source, r, g, b ) 
        setBlipColor ( blip [ source ], r, g, b, 255 ) 
    end 
) 
  
addEventHandler ( "onPlayerQuit", root, 
    function ( ) 
        if isElement ( blip [ source ] ) then 
            destroyElement ( blip [ source ] ) 
        end 
    end 
) 

Try that and see what it says when you login.

Link to comment
local blip = { } 
  
addEvent ( "onPlayerTeamChanged", true ) 
addEventHandler ( "onPlayerTeamChanged", root, 
    function ( theTeam ) 
        if ( not theTeam ) then 
            return 
        end 
  
        if ( not isElement ( blip [ source ] ) ) then 
            blip [ source ] = createBlipAttachedTo ( source ) 
        end 
  
        local r, g, b = getTeamColor ( theTeam ) 
        setPlayerNametagColor ( source, r, g, b ) 
        setBlipColor ( blip [ source ], r, g, b, 255 ) 
    end 
) 
  
addEventHandler ( "onPlayerQuit", root, 
    function ( ) 
        if isElement ( blip [ source ] ) then 
            destroyElement ( blip [ source ] ) 
        end 
    end 
) 

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