HUDPaint - Displaying Team

Hello,

I’ve just started lua scripting for garrysmod and have just run into a brick wall as I was designing my HUD for a game mode I decide to display the team name to the player and it just doesn’t display. Heres my code:




if pl:Team() == TEAM_NOBODY then		surface.SetTextColor( team.GetColor(1) );
		surface.SetTextPos( 20, ScrH() - 40 );
		surface.DrawText( "Nobody" );
	end
	if pl:Team() == TEAM_INFECTED then
		surface.SetTextColor( team.GetColor(2) );
		surface.SetTextPos( 20, ScrH() - 40 );
		surface.DrawText( "Infected Hobo" );
	end
	if pl:Team() == TEAM_HUMAN then
		surface.SetTextColor( team.GetColor(3) );
		surface.SetTextPos( 20, ScrH() - 40 );
		surface.DrawText( "Human" );
	end


I did also add elseif’s at first but changed them to 3 ifs because it didn’t seem to work.

If any one could help, I would very much appreciate it.

That looks all fine, could you show us the rest of the script?

Also do you get any errors at all in your console?

Thanks for the reply, Yeah there are no errors in console and heres the rest of the cl_init.lua




include( 'shared.lua' )


function GM:PlayerInitialSpawn( pl )
	
	pl:SetTeam( 1 );
	pl:StripWeapons();
	
end

function GM:PlayerSpawn( pl )
	
end 

function GM:HUDShouldDraw( name )
	for k, v in pairs( {"CHudHealth", "CHudBattery"} ) do
		if name == v then
			return false
		end
	end	
	return true
end


function GM:HUDPaint()
	local w = 169;
	local h = 91;
	
	local pl = LocalPlayer();
	local playerHealth = pl:Health();
	
	surface.SetDrawColor( 255, 255, 255, 255 );
	surface.SetTexture( surface.GetTextureID( "Infection/hud/health" ) );
	surface.DrawTexturedRect( 10, ScrH() - 110, w, h );
	
	surface.SetDrawColor( 255, 255, 255, 255 );
	surface.DrawRect( 42, ScrH() - 68, playerHealth, 20 );
	
	
	if pl:Team() == 1 then
		surface.SetTextColor( 255, 255, 255, 255 );
		surface.SetTextPos( 20, ScrH() - 40 );
		surface.DrawText( "Nobody" );
	end
	if pl:Team() == 2 then
		surface.SetTextColor( 0, 238, 118, 255  );
		surface.SetTextPos( 20, ScrH() - 40 );
		surface.DrawText( "Infected" );
	end
	if pl:Team() == 3 then
		surface.SetTextColor( 28, 134, 238, 255 );
		surface.SetTextPos( 20, ScrH() - 40 );
		surface.DrawText( "Human" );
	end
		
end




Shouldn’t you use elseif instead of if end, if end, etc.

So:
[lua]
elseif ( pl:Team() == 2 ) then
[/lua]

I did that. The code I uploaded was the code I decided to create after I thought maybe 3 ifs…

PlayerInitialSpawn and PlayerSpawn are both serverside only.

So everything draws fine apart from the team?

Yeah

EDIT: FIXED, thanks Drakehawke I thought PlayerinitialSpawn and Playerspawn were client side so it wasn’t setting the players team xD so just moved them to init.lua, thanks again.

No problem :slight_smile: