Randomized SetPlayerModel on Intial Spawn.

Hey guys, I’ve posted a few times on here in the past day or so and I’m here again with another question.

I’m working on a simple code for a gamemode that will give a player one of five pre-determined HL2 Citizen skins on their first spawn into the server. Unfortunately, I’m getting lua errors with the code when spawning in. I could have sworn I was doing it right but obviously I’m not; I am very, very new to lua and pretty much coding in general.

Anyone know where I went wrong? Thanks in advance!

ply:SetPlayerColor’s first argument should be a color. Not a vector, which is a position. Do you want to set player’s colour to something else than default anyway?

The code below probably fixes your lua error, but also removes the custom colour, whereof I’m not sure you want to customise it anyway.

if i == 1 then

You’re missing an end for the function; this would be easy to see if you used tabs. Try following some coding standard, here’s mine as an example: https://dl.dropboxusercontent.com/u/26074909/tutoring/_tutorial_quizzes/_coding_standards.lua.html

Please read the top, you may encounter many different coding standards and mixed styles. Try to adhere to one for each project; as long as they are uniform in a project, you should be ok with increasing readability.

The most important thing for you, is to use tabs, then it is very easy to see mistakes like this.

So, any time you define a function, use then, do, etc… tab in. When end is called, tab out.

[editline]8th May 2014[/editline]

SetPlayerColor uses a Vector, not a color. He’s running it properly in terms of that; he created his own hook ( GM function ) in order to simplify the work.

From the wiki: Player:SetPlayerColor( Vector Color )

A Vector color is a essentially:

[lua]function ColorToVector( _color )
if ( !IsTable( _color ) || table.Count( _color ) != 4 || !_color.r || !_color.g || !_color.b || !_color.a ) then return Vector( 1, 1, 1 ); end
return Vector( _color.r / 255, _color.g / 255, _color.b / 255 );

// Loss of information, Alpha for returning to color
function VectorToColor( _vector )
if ( !isvector( _vector ) ) then return Color( 255, 255, 255, 255 ); end
return Color( _vector.x * 255, _color.y * 255, _color.z * 255, 255 );

Thank you once again, working flawlessly now. (Although some of the models come up as errors, but that’s my own fault for not selecting the right path)

Where EXACTLY would I look for the HL2 Citizen player models? Or all possible player models in general? If I get the models from the HL2 Directory the just T pose as the character animation. Some of the ones that are in my code currently work just fine, others don’t (Error sign). And I was only able to go off that because I looked up an example of the refugee ones. (Ones with white clothes by default are the ones I want, I know where the other blue city 17 outfits and rebel ones are, but I want the ones specifically for the white clothes)

It’s a bit off topic but I’ll be damned if I can’t find it anywhere.

[editline]8th May 2014[/editline]

Nevermind, I just used the C17 blue citizens and vectored their clothes white. I’m all good.

Thanks again!