Creating weapon HUD menu

I want to create a custom HUD weapon menu from this :

http://puu.sh/h9FeP.png

Something that looks like a TTT weapon menu or something that just works, however I don’t know what functions do I have to use.

From my experience:
try to use http://wiki.garrysmod.com/page/cam/Start2D , http://wiki.garrysmod.com/page/Global/RunConsoleCommand with use and GetClass of wep.
Also the correct hook would be http://wiki.garrysmod.com/page/GM/PlayerBindPress with checks if bind is equal '+attack* for select, invprev / invnext for scrolling.

When I Hide “CHudWeaponSelection” I can’t use invprev/invnext.

mhh? are you sure?
since i hide them and can use them without any problems, did you returned true?

I think so

[lua]
local HideHUD = { “CHudHealth”, “CHudBattery”, “CHudAmmo”, “CHudSecondaryAmmo”, “CHudCrosshair”, “CHudWeaponSelection” }
function GM:HUDShouldDraw(name)

for k, v in pairs(HideHUD) do

  if name == v then return false end

end

return true

end
[/lua]

i mean in PlayerBindPress

[lua]
function GM:PlayerBindPress( ply, bind, pressed )

if ( string.find( bind, "invprev" ) ) then

net.Start("nextwep")
net.SendToServer()

end

if ( string.find( bind, "invnext" ) ) then

net.Start("prevwep")
net.SendToServer()

end

end
[/lua]

Also now I just played with it a bit and came to this :

[lua]
//SERVER CODE
util.AddNetworkString( “nextwep” )
util.AddNetworkString( “prevwep” )

function NextWeapon( len, ply )

for k, v in pairs( ply:GetWeapons() ) do

	if ply:GetActiveWeapon() == v then

		ply:SetNWInt( "curwep"..ply:UserID() , k )
	
	end

end

local function CurWep()

	for k, v in pairs( ply:GetWeapons() ) do
	
		if ply:GetActiveWeapon() == v then
		
			return k
		
		end
	
	end

end

local function StopWep( k )

	if ply:GetNWInt( "curwep"..ply:UserID() ) + 1 == k then
		return true
		
	end

	return false
end

for k, v in pairs( ply:GetWeapons() ) do

	if CurWep() == #ply:GetWeapons() then
	
		if k == 1 then
	
			ply:SelectWeapon( v:GetClass() )
			
			return
		
		end
		
	end

	if CurWep() != k and StopWep( k ) then
	

		ply:SelectWeapon( v:GetClass() )
	
	end

end

end

function PrevWeapon( len, ply )

for k, v in pairs( ply:GetWeapons() ) do

	if ply:GetActiveWeapon() == v then

		ply:SetNWInt( "curwep"..ply:UserID() , k )
	
	end

end

local function CurWep()

	for k, v in pairs( ply:GetWeapons() ) do
	
		if ply:GetActiveWeapon() == v then
		
			return k
		
		end
	
	end

end

local function StopWep( k )

	if ply:GetNWInt( "curwep"..ply:UserID() ) - 1 == k then
		return true
		
	end

	return false
end

for k, v in pairs( ply:GetWeapons() ) do

	if CurWep() - 1 == 0 and ply:GetNWInt( "curwep"..ply:UserID() ) == 1 then
	
		if k == #ply:GetWeapons() then
	
			ply:SelectWeapon( v:GetClass() )
			
			return
		
		end
		
	end

	if CurWep() != k and StopWep( k ) then
	
		ply:SelectWeapon( v:GetClass() )
	
	end

end

end


net.Receive( “nextwep”, NextWeapon )
net.Receive( “prevwep”, PrevWeapon )
[/lua]

Idk if this would be the best one of all other options but it works.

PlayerBindPress is CL, not SV. So no need for networking.
[lua] if bind == ‘invprev’ then
WeaponSelectionSelected = WeaponSelectionSelected - 1
if WeaponSelectionSelected < 1 then
WeaponSelectionSelected = #ply:GetWeapons()
end
end

	if bind == 'invnext' then
		WeaponSelectionSelected = WeaponSelectionSelected + 1
		if WeaponSelectionSelected &gt; #ply:GetWeapons() then
			WeaponSelectionSelected = 1
		end
	end

if bind == '+attack'  then
	RunConsoleCommand( 'use', ply:GetWeapons()[WeaponSelectionSelected]:GetClass() )
	return true
end

[/lua]

The thing is I have the selecting code in my init.lua code since ply:SelectWeapon was only serverside, but I will try yours too.

[editline]11th April 2015[/editline]

I have a problem with your code, it overrides +attack function of weapons so they can’t fire, meaning that I can’t use it like this.