Custom Weapon Selection HUD

So another thing I’d like to have in my mode would be a custom weapon selection HUD. Currently it looks like this:

The crowbar icon has been manually set to be brighter, but I’d like it to dynamically change as the player changes weapons. As a more or less beginner in Lua for Garry’s Mod, I rely a lot on the wiki articles, and looking at other gamemodes’ codes. But this is a problem I have been unable to solve just by looking at what other people did to accomplish this. So does anyone here know how to set up such a weapon switching HUD? I want the Mouse Wheel to scroll through the weapons just like normal, and keys 1 through 3 to select them in the order that they appear on (Which is not the order that their slots are in), and it should also act like a fast weapon switch, where you don’t have to press LMB to equip it, but just scroll past to deploy.

This is an example of the code I’ve been using to set the darkness of the icons. Both of these chunks of code is in a HUD function that is hooked with “HUDPaint”, run in cl_hud.lua.


if LocalPlayer():GetActiveWeapon() == "weapon_stunstick" then 
	stunState = 255
	jailState = 25
elseif LocalPlayer():GetActiveWeapon() == "cr_jail" then 
	jailState = 255
	stunState = 25
end


if LocalPlayer():Team() == 5 or LocalPlayer():Team() == 1 then
	surface.SetMaterial( Material("copsandrunners/Stunstick.png") )
	surface.SetDrawColor(stunState, stunState, stunState, 255)
	surface.DrawTexturedRect( (((ScrW() - (ScrW() / 80)) - (ScrW() / 4)) + 100) - 20, (((ScrH() / 10) * 8) - 25) + 100, 100, 100)
end

I’ve tried to set a variable “activewep” in shared.lua in a function that is hooked to “KeyPress”. That hook however doesn’t work with KEY_ and MOUSE_ keys, and I need those for the Mouse Wheel and 1-3 keys. I need to make code both to highlight the equipped weapon’s icon and to switch weapons on the appropriate keys, since I’ve disabled the CHUDWeaponSelection.

[editline]21st June 2014[/editline]

Okay solved the first part about the icons not highlighting the correct equipped weapon. Apparantly I had to do


if LocalPlayer():GetActiveWeapon():GetClass() == "weapon_stunstick" then

So adding :GetClass() to it. Now it works if I enable the default weapon switching HUD, but I still don’t know how to switch weapons once that has been disabled. I guess it must be some server side code, but checking if any KEY_ or MOUSE_ keys are pressed is only run on the client, but SetActiveWeapon is only run on the server, how can I run these together? Even in shared they create errors.

Essentially it just has to check what weapon I currently hold, then what button I press, then set my active weapon to be the next or previous weapon, depening on what button I pressed.