Jump to content

Nametagcolor


Recommended Posts

Posted

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

Posted

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 !

Posted (edited)

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
Posted

Nah, I've set a timer for it to run every 10secs to see if every player is still in the server so there's no lose ends of the script.

Posted

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) 

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

Posted
ok, try this:

<...>

Where is the 2nd argument of the function createBlipAttachedTo.

only 1 argument is required, others are optional

Nah, I've set a timer for it to run every 10secs to see if every player is still in the server so there's no lose ends of the script.

You can use onPlayerQuit for that, you dont need timer.

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

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

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

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