Jump to content

[Help] Name tag colors in Race Mode


Recommended Posts

Hello, im new here and i would like to ask something. In race resource, i changed the name tag colour, i made it to check the name color of the player, and put the same color in the tag.

It was like that:

local r,g,b = 255,255,255

and i changed it to this:

local r,g,b = getPlayerNametagColor ( player )

but its not working, can somebody help me?

Link to comment

I mean IF ur name is read.. i want to automatically check the name color of every player, and put the right color for every player. if ur name is red, i want the text to appear red, if ur name is green, i want the text to appear green, thats what i mean..

Link to comment

EDIT: here it is

  
--serverside! 
function process() 
  local players=getElementsByType("player") 
  for _,v in pairs(players) do 
    processPlayer(v) 
  end 
end 
  
function processPlayer(p) 
  local Player=source or p 
  local nick=getPlayerName(Player) 
  local colorcode=nick:match("^#%x%x%x%x%x%x") 
  if colorcode then 
    local red,blue,green=getColorFromString(colorcode) 
    setPlayerNametagColor(Player,red,blue,green) 
  end 
  setPlayerName(Player,nick:gsub("#%x%x%x%x%x%x","")) 
end 
addEventHandler("onResouceStart",getResourceRootElement(),process) 
addEventHandler("onPlayerJoin",getRootElement(),processPlayer) 
addEventHandler("onPlayerChangeNick",getRootElement(),processPlayer) 
  

Edited by Guest
Link to comment

Yes but i want the code to put the name color on the top of the car, not on TAB or sth.. it works fine in TAB, but i want a code to read the color of the name, and put it on the top of the car, because now its always white even if the player name is red for example..

Link to comment

Well i dont think i need to do it like that. In Race it uses this:

dxDrawText (getPlayerName(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, "default", "center", "bottom", false, false, false )

so i need to use dxDrawText..

Link to comment

Can i try?

I don't tested,

Try this:

function carcolor() 
function ( thePlayer ) 
    local r, g, b = getPlayerNametagColor ( thePlayer ) 
    setVehicleColor ( thePlayer , r, b, g, 0 ) 
end 
addCommandHandler ( "namecolor", carcolor ) 

Try

Link to comment

ok try this

add the script i showed before serverside, and then do this:

  
r,g,b=getPlayerNametagColor(player) 
dxDrawText (getPlayerName(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, "default", "center", "bottom", false, false, false ) 
  

Link to comment

hmm you need car color be name color

function carcolor(thePlayer) 
local r = getVehicleColor(thePlayer) 
setPlayerName(thePlayer, r..getPlayerName(thePlayer)) 
end 
addCommandHandler("test",carcolor) 
  

___________

Sorry Guy i read what i writed at the other post and its wrong

Try:

function carcolor( thePlayer ) 
        local r, g, b = getPlayerNametagColor ( thePlayer ) 
        setVehicleColor ( thePlayer , r, b, g, 0 ) 
    end 
    addCommandHandler ( "namecolor", carcolor ) 

Link to comment
hmm you need car color be name color
function carcolor(thePlayer) 
local r = getVehicleColor(thePlayer) 
setPlayerName(thePlayer, r..getPlayerName(thePlayer)) 
end 
addCommandHandler("test",carcolor) 
  

___________

Sorry Guy i read what i writed at the other post and its wrong

Try:

function carcolor( thePlayer ) 
        local r, g, b = getPlayerNametagColor ( thePlayer ) 
        setVehicleColor ( thePlayer , r, b, g, 0 ) 
    end 
    addCommandHandler ( "namecolor", carcolor ) 

this makes zero sense, nor vehicle color id works on nicks, nor vehicles work on rgb(until 1.1).

and the fact is HE DIDNT EVEN ASK FOR VEHICLE COLOR

Link to comment

in nametags.lua i put this:

r,g,b=getPlayerNametagColor(player)

and then it has this code:

dxDrawText (getPlayerName(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, "default", "center", "bottom", false, false, false )

and in the same file, in the end, i added this:

function process()

players=getElementsByType("player")

for _,v in pairs(players) do

processPlayer(v)

end

end

function processPlayer(p)

local Player=source or p

local nick=getPlayerName(Player)

local colorcode=nick:match("^#%x%x%x%x%x%x")

if colorcode then

local red,blue,green=getColorFromString(colorcode)

setPlayerNametagColor(Player,red,blue,green)

end

setPlayerName(Player,nick:gsub("#%x%x%x%x%x%x",""))

end

addEventHandler("onResouceStart",getResourceRootElement(),process)

addEventHandler("onPlayerJoin",getRootElement(),processPlayer)

addEventHandler("onPlayerChangeNick",getRootElement(),processPlayer)

and with this it appears light green :S

Link to comment

please use

[ lua] code here [/lua] (whithout the space at front) 

or

[/code]

this have to be in clientside, in nametags.lua i suppose.

  
... 
  local r,g,b=getPlayerNametagColor(player) 
  dxDrawText (getPlayerName(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, "default", "center", "bottom", false, false, false ) 
... 
  

and this have to be serverside, in other script file.

  
function process() 
  players=getElementsByType("player") 
  for _,v in pairs(players) do 
    processPlayer(v) 
  end 
end 
  
function processPlayer(p) 
  local Player=source or p 
  local nick=getPlayerName(Player) 
  local colorcode=nick:match("^#%x%x%x%x%x%x") 
  if colorcode then 
    local red,blue,green=getColorFromString(colorcode) 
    setPlayerNametagColor(Player,red,blue,green) 
  end 
  setPlayerName(Player,nick:gsub("#%x%x%x%x%x%x","")) 
end 
  
addEventHandler("onResouceStart",getResourceRootElement(),process) 
addEventHandler("onPlayerJoin",getRootElement(),processPlayer) 
addEventHandler("onPlayerChangeNick",getRootElement(),processPlayer) 
  

[code=lua] code here 
Link to comment

oh, theres a inf loop, fixing it.

anyway you need the setname so you won't see the colorcodes in the textdraw

EDIT:heres the fix

countless more edits:optimizng

function process() 
  players=getElementsByType("player") 
  for _,v in pairs(players) do 
    processPlayer(v) 
  end 
end 
  
function processPlayer(p) 
  local Player=source or p 
  local nick=getPlayerName(Player) 
  local newnick=nick:gsub("#%x%x%x%x%x%x","") 
  local colorcode=nick:match("^#%x%x%x%x%x%x") 
  if newnick~=nick then 
    setPlayerName(Player,newnick) 
    if colorcode then 
      local red,green,blue=getColorFromString(colorcode) 
      setPlayerNametagColor(Player,red,green,blue) 
    end 
  end 
end 
  
addEventHandler("onResouceStart",getResourceRootElement(),process) 
addEventHandler("onPlayerJoin",getRootElement(),processPlayer) 
addEventHandler("onPlayerChangeNick",getRootElement(),processPlayer) 
  

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