Jump to content

Team Blip Color


Krex

Recommended Posts

Can anyone please help me with this code, it supposed to change a player's name and blip color to the color of  their team when they switch team's. But the problem is, when i change my team the blip color changes for all players, even though their not in my team. 

function setTeamColor()
for _,player in ipairs(getElementsByType("player")) do
for _,blip in ipairs(getElementsByType("blip")) do
local team = getPlayerTeam(player) 
if (team) then 
local r,g,b = getTeamColor(team)   
setPlayerNametagColor(player,r,g,b)
setBlipColor(blip,r,g,b,255)
      end
    end
  end
end
setTimer(setTeamColor,500,0)

 

 

Edited by jhxp
Link to comment
function setBlipsToTeamColor()
  for _,player in ipairs(getElementsByType("player")) do
    for _,blip in ipairs(getElementsByType("blip")) do
      local team = getPlayerTeam(player) 
      if (team and getElementAttachedTo(blip) == player) then  -- only if this blip is attached to `player`
        local r,g,b = getTeamColor(team)   
        setPlayerNametagColor(player,r,g,b)
        setBlipColor(blip,r,g,b,255)
      end
    end
  end
end
setTimer(setBlipsToTeamColor,500,0)

Also I've renamed the function since you should avoid naming your function with the same name as existing hardcoded functions (namely, setTeamColor) as that makes them inaccessible.

Edited by MrTasty
  • Like 1
  • Thanks 1
Link to comment
14 minutes ago, MrTasty said:

function setBlipsToTeamColor()
  for _,player in ipairs(getElementsByType("player")) do
    for _,blip in ipairs(getElementsByType("blip")) do
      local team = getPlayerTeam(player) 
      if (team and getElementAttachedTo(blip) == player) then  -- only if this blip is attached to `player`
        local r,g,b = getTeamColor(team)   
        setPlayerNametagColor(player,r,g,b)
        setBlipColor(blip,r,g,b,255)
      end
    end
  end
end
setTimer(setBlipsToTeamColor,500,0)

Also I've renamed the function since you should avoid naming your function with the same name as existing hardcoded functions (namely, setTeamColor) as that makes them inaccessible.

Thank's, it works well now :D

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