Non-vector player colour

I’m running a heavily customized version of DarkRP and I’m trying to make it so that when a player changes jobs, their player colour changes too. Some of the playermodels I use for specific jobs have no custom viewmodel hands, so I’m trying to at least make the colour of the standard ‘citizen’ sleeves they see match their playermodel. (Said playermodel has no actual colour options for its world model, but changing the player colour will still change the colour of the standard sleeves in viewmodel, obviously.)

Now, the problem isn’t getting this to work. I did. The problem is that the function SetPlayerColor only takes a “vector” value, which seems to be an RGB colour absolute. As in each colour value is a binary. (1, 0, 0) for red, (1, 0, 1) for purple, and so forth. It is obviously designed for gamemodes with team-based play in mind, designating each team with a unique colour that’s easily visually identifiable.

Is there any way to circumvent this? I could set the ‘colour’ of the player as an entity but that’s not going to have the desired effect of colouring their viewmodel sleeves and will just look weird on the world model so that won’t work.

Surely since players can set a non-vector playercolour in-game, there must be a way to do it through lua??? :why:

Wait, why not just divide the color values by 255 and set that as a vector?



local color = Color( 255, 0, 0, 255 )
local vectorcolor = Vector( color.r / 255, color.g / 255, color.b / 255 )

ply:SetPlayerColor( vectorcolor  )


But then SetPlayerColour isn’t going to accept the value? Or it will default to white/black. That’s what happened when I tried to set each value to anything other than 0 or 1.

But if you divide the color by 255 then you’re making it out of a total of 1, so then it should accept it, right?

Why don’t you think it would work? The function expects a vector with values between 0 and 1, and the maximum color number for a channel is 255, so by dividing it by that, you’re making it out of a total of 1. Then by using the Vector function to create a vector based on the values that are now between 0 and 1, it should work since the function wants that

Wait, I’m a little confused, so which one am I setting to the actual RGB values? Say I wanted a sort of muddy green like 100, 135, 95

If you wanted that, you could make a new color with those values



local color = Color( 100, 135, 95 )


Then you could do



local vector = Vector( color.r / 255, color.g / 255, color.b / 255 )


And that’d get make each coordinate of the vector out of 0 and 1

Or, you could just do



ply:SetPlayerColor( Vector( 100 / 255, 135 / 255, 95 / 255 ) )


For maximum efficiency

Really, all that needs to be done is that the r,g and b values of the color need to be divided by 255, then put in as a vector

Here’s a little helper function if you want it:



local function SetPlayerColorAsRGB( ply, r, g, b )
    ply:SetPlayerColor( Vector( r / 255, g / 255, b / 255 ) )
end


Then to get it to work for the colors you want, you could just do



SetPlayerColorAsRGB( someplayer, 100, 135, 95 )


Holy shit. It worked. How does that work?? Even if you disguise it as a different value, isn’t it still either a 0, a 1, or invalid? I don’t understand. But thank you. (Can’t rate posts, still below 30 post count, but consider yourself rated highly. :pudge:)

I wasn’t disguising the number as anything, only dividing it by the total or the maximum it can get up to.

If you divide a value by it’s total/maximum then it gives you a number between 0 and 1, so all I did was divide a number (the color you want) by the total (255, the maximum number you can use for colors), so it gives you a number between 0 and 1, which is what the function wants.

The SetPlayerColor function works with ANY number between 0 and 1 by the way

Sorry, this is a pretty terrible explanation

Oooh, I see. I assumed because it said “each color should be between 0 and 1” that it had to be a binary, I didn’t consider 0.50 and that kind of thing. (What are they called, decimals? Not sure.) Thanks for both helping and explaining. :slight_smile: