Garry's Mod Wiki

Using Viewmodel Hands

Scripted Weapons

To make your SWEP use the viewmodel hands, add this code:

SWEP.UseHands = true

Note that your SWEP must also use a C model for its viewmodel:

SWEP.ViewModel = "models/weapons/c_smg1.mdl"

Custom Gamemodes

If you want to use the Viewmodel Hands system in your gamemode, you must put some code into your gamemode.

Without Player Classes

Serverside: ( This MUST go into a GM:PlayerSpawn function, paste it to the end )

function GM:PlayerSpawn( ply ) -- Your code ply:SetupHands() -- Create the hands and call GM:PlayerSetHandsModel end -- Choose the model for hands according to their player model. function GM:PlayerSetHandsModel( ply, ent ) local simplemodel = player_manager.TranslateToPlayerModelName( ply:GetModel() ) local info = player_manager.TranslatePlayerHands( simplemodel ) if ( info ) then ent:SetModel( info.model ) ent:SetSkin( ) ent:SetBodyGroups( info.body ) end end

Using Player Classes

Serverside: ( Again, must be put into GM:PlayerSpawn after you set players class )

function GM:PlayerSpawn( ply ) -- Set your player class ply:SetupHands() -- Create the hands and call GM:PlayerSetHandsModel end

By default GM:PlayerSetHandsModel calls GetHandsModel of players current player class.

Clientside code

If you haven't overridden GM:PostDrawViewModel, this step is optional.

This code makes the hands draw. It must be clientside.

function GM:PostDrawViewModel( vm, ply, weapon ) if ( weapon.UseHands || !weapon:IsScripted() ) then local hands = LocalPlayer():GetHands() if ( IsValid( hands ) ) then hands:DrawModel() end end end

Player Class

If you want a specific player class to use specific hands then add this function.

function PLAYER:GetHandsModel() return { model = "models/weapons/c_arms_cstrike.mdl", skin = 1, body = "0100000" } end

Player Models

If you're adding a player model and want to add custom hands then use this code.

player_manager.AddValidHands( "css_arctic", "models/weapons/c_arms_cstrike.mdl", 0, "00000000" )

Where 'css_arctic' is the name you used when calling player_manager.AddValidModel — the two numbers are respectively the skin and bodygroup values.

If a player model doesn't have a corresponding hands entry, it will default to the civilian hands.

Model creators

Here's an example c_model that shows how things need to be set up in your QC and SMD files. This is the source files of the medkit SWEP that is packed by default with Gmod.

Here are the source files for the c_arms_citizen model, if you need some reference for compiling arms:

Here's the citizen arms on a CAT animation rig.

If you need SMD files for these arms (making your own animation rigs, etc.), here they are.

The arms mesh should never be in the weapon model itself; that defeats the entire purpose of the system!

Remember to include c_arms_definebones.qci from the medkit example, as otherwise StudioMDL will optimise away the arm bones that you've included and then it won't work.