Jump to content

getPlayerTeamColor


Recommended Posts

Posted

i use this Script which makes you have the team Color like if Team color is Yellow you get the same Color when you are in that

Team, but i had a Problem why the player must Reconnect to take the team color why can't he get the teamcolor without reconnect ? Or he must Logout Then Login , I hate that every time i must /restart play to get the player team color :'(

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 
  
local blip = {} 
  
local randomColor = { 
 [1] = {255,255,255}, 
 [2] = {255,0,255}, 
 [3] = {0,255,0} 
} 
  
addEventHandler("onPlayerLogin", root, 
function () 
     if not isElement(blip[source]) then 
        blip[source] = createBlipAttachedTo(source) 
    end 
    local theTeam = getPlayerTeam(source) 
    if theTeam then 
        local r, g, b = getTeamColor(theTeam) 
        setPlayerNametagColor(source, r, g, b) 
        setBlipColor(blip[source], r, g, b, 255) 
  setPlayerName(source,getPlayerName(source):gsub('#%x%x%x%x%x%x',RGBToHex(r,g,b))) 
    else 
        outputChatBox("YOU HAVE NO TEAM", source) 
  rr,gg,bb = unpack(randomColor[math.random(#randomColor)]) 
  setBlipColor(blip[source], rr,gg,bb,255) 
  setPlayerName(source,getPlayerName(source):gsub('#%x%x%x%x%x%x',RGBToHex(rr,gg,bb))) 
        setPlayerNametagColor(source, rr,gg,bb) 
  end 
 end 
) 
  
addEventHandler("onPlayerQuit", root, 
function() 
    if isElement(blip[source]) then 
        destroyElement(blip[source]) 
  end 
 end 
) 

Posted

Spider, You will never understand, For me (no offence) Maybe it's somebody else script, Anyway Line 20 change 'onPlayerLogin' and create an event name it 'onPlayerTeamChange' and use it.

Posted (edited)
  
addEvent("onPlayerTeamChange"); 
local _setPlayerTeam = setPlayerTeam; 
setPlayerTeam = function(player,team) 
    local PreviousTeam = getPlayerTeam(player); 
    local Result = _setPlayerTeam(player,team); 
    if Result then 
        triggerEvent("onPlayerTeamChange",player,PreviousTeam,team); 
    end; 
    return Result; 
end; 
  
addEventHandler("onPlayerTeamChange",root,function(_,team) 
    local Color = getTeamColorName(team); 
    Color = Color and Color or {255,255,255}; 
    local Name = getPlayerName(source); 
    Name = ("#%.2X%.2X%.2X"):format(Color[1],Color[2],Color[3])..Name:gsub("#%x%x%x%x%x%x",""); 
    setPlayerName(source,Name); 
end); 
  

Edited by Guest
Posted

its n't working i removed Line 20 and now i don't even have team color, and no errors in Debug Script

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 
  
local blip = {} 
  
local randomColor = { 
 [1] = {255,255,255}, 
 [2] = {255,0,255}, 
 [3] = {0,255,0} 
} 
  
addEventHandler("onPlayerTeamChange", root, 
function () 
     if not isElement(blip[source]) then 
        blip[source] = createBlipAttachedTo(source) 
    end 
    local theTeam = getPlayerTeam(source) 
    if theTeam then 
        local r, g, b = getTeamColor(theTeam) 
        setPlayerNametagColor(source, r, g, b) 
        setBlipColor(blip[source], r, g, b, 255) 
  setPlayerName(source,getPlayerName(source):gsub('#%x%x%x%x%x%x',RGBToHex(r,g,b))) 
    else 
        outputChatBox("YOU HAVE NO TEAM", source) 
  rr,gg,bb = unpack(randomColor[math.random(#randomColor)]) 
  setBlipColor(blip[source], rr,gg,bb,255) 
  setPlayerName(source,getPlayerName(source):gsub('#%x%x%x%x%x%x',RGBToHex(rr,gg,bb))) 
        setPlayerNametagColor(source, rr,gg,bb) 
  end 
 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...