Tinting A Players Color With Lua

I have made a gamemode with two teams. I have tried


function GM:PlayerSpawn( ply )
	self.BaseClass:PlayerSpawn( ply )
	if ( ply:Team() == 1 ) then
		ply:SetColor( Color(250,153,153,255) )	
	end	
	if ( ply:Team() == 2 ) then
		ply:SetColor( Color(26,18,171,255) )	
	end	
	ply:SetGravity( 0.75 )  
	ply:SetMaxHealth( 100, true )  
	ply:SetWalkSpeed( 325 )  
	ply:SetRunSpeed( 450 ) 
end

but the players just become invisible after they respawn for some reason–weapons included, and on the first spawn the players are normal.

If you can’t tint a players color. Do you guys have any suggestions for how the teams can be distinguished. I was thinking of hats but I don’t know how to do that either.

I looked through the documentation but I didn’t see any player:SetColor().

I know it is possible, wire does it somehow, with the target finder the player turns red. I am a bit interested in how to tint a players color also.

No, it’s perfectly possible to set a player’s color. I’ve done it before. After all, players are entities.

Ah, I got it. Don’t set the player’s color as a color object, just use four integer arguments.

[lua]function GM:PlayerSpawn( ply )
self.BaseClass:PlayerSpawn( ply )
if ( ply:Team() == 1 ) then
ply:SetColor( 250,153,153,255 )
end
if ( ply:Team() == 2 ) then
ply:SetColor( 26,18,171,255 )
end
ply:SetGravity( 0.75 )
ply:SetMaxHealth( 100, true )
ply:SetWalkSpeed( 325 )
ply:SetRunSpeed( 450 )
end
[/lua]

Like that.

Alright, I looked through the wiki and didn’t see any SetColor for ply, I guess I didn’t think about players being entities.

:slight_smile:

ply:SetColor(0,0,0,255) works great for anyone wanting to use it.

I got it to work! I had to use


timer.Simple(0.5, ply.SetColor, ply, 26,18,171,255)

because it needed a delay. I suppose if it doesn’t work for you just increase the delay from 0.5 to 1 or 2 or whatever.

Thanks Guys

Look for entity:SetColor(r , g , b , a)

Since a player is an entity, alot of entity functions also apply to players.

A Player is not a Entity Entity = Prop / player = player.
[lua]
LocalPlayer():SetColor(255, 255, 255, 255)
[/lua]

Err, you misunderstand ecabc.

Pretty much everything in GMod is an “entity”, except the world (or the map). There are specific subsets of entities, such as NPCs, doors, players, bouncy balls, props, etc.

The term “entity” is a broad category encompassing players and props. I’m saying all props are entities, but not all entities are props.

@ecabc you are completely wrong. This is from the wiki ( http://wiki.garrymod.com/?title=player)

Ok then I know what an entity is Player IS not an Entity, and if it was why is there LocalPlayer() and not entity():…

Rambling i fixed your code.

Ecabc. A Player IS an Entity. Get your facts right.

I have yet to run into a entity function that wont work on a player.

[lua]
function PlayerSpawned( ply )
if ( ply:Team() == 1 ) then
ply:SetColor( Color(250,153,153,255) )
end
if ( ply:Team() == 2 ) then
ply:SetColor( Color(26,18,171,255) )
end
ply:SetGravity( 0.75 )
ply:SetMaxHealth( 100, true )
ply:SetWalkSpeed( 325 )
ply:SetRunSpeed( 450 )
end
hook.Add( “PlayerInitialSpawn”, “playerInitialSpawn”, PlayerSpawned )
hook.Add( “PlayerSpawn”, “playerSpawn”, PlayerSpawned )
[/lua]

also ecabc Players are entities LocalPlayer() returns the entity ID of the player



] lua_run_cl print(LocalPlayer())
Player [1][>(NoS] Aaron.torrent]


@ecabc
yes, you did. i forgot to mention that. Thanks.

All entity functions will work on players because the player metatable (where all the functions are stored) is derived from the entity metatable and therefore it inherits all its functions including SetColor.

All squares are rectangles, but not all rectangles are squares, regardless of how adamantly you deny that squares in fact NOT rectangles.

Yes i know Sarcastic

Use ScreenRender or w/e it is

The world is an entity too. It’s always Entity [0] which is ‘worldspawn’ (Changed to class C_World)



] lua_run_cl PrintTable(ents.GetAll())
1	=	Entity [0][class C_World]
2	=	Player [1][¦FlapJack¦]
3	=	Entity [10][class C_PlayerResource]
4	=	Entity [16][viewmodel]


OHHH yeh sorry i forgot the entity = Player DUHHH xD