MsgC( Color( 255 , 0 , 255 ) , "MyHands v8.1 Fixed by Wgis\n" ) if ( SERVER ) then AddCSLuaFile() return end -- Table that holds all data relevant to My Hands. MyHands = MyHands or {} -- Only draw your playermodel hands if set to 1. MyHands.Enabled = MyHands.Enabled or CreateClientConVar( "myhands_enabled" , "1" , true , false ) -- Offset for the clipping plane which cuts off the rest of the players model. MyHands.Clip = MyHands.Clip or CreateClientConVar( "myhands_clip" , "0" , true , false ) -- Table of main bones to keep visible. MyHands.Bones = { -- Right Arm "ValveBiped.Bip01_R_Clavicle", "ValveBiped.Bip01_R_UpperArm", "ValveBiped.Bip01_R_Forearm", "ValveBiped.Bip01_R_Hand", "ValveBiped.Bip01_R_Ulna", "ValveBiped.Bip01_R_Wrist", "ValveBiped.Bip01_R_Shoulder", "ValveBiped.Bip01_R_Elbow", "ValveBiped.Bip01_R_Bicep", "ValveBiped.Bip01_R_Trapezius", -- Left Arm "ValveBiped.Bip01_L_Clavicle", "ValveBiped.Bip01_L_UpperArm", "ValveBiped.Bip01_L_Forearm", "ValveBiped.Bip01_L_Hand", "ValveBiped.Bip01_L_Ulna", "ValveBiped.Bip01_L_Wrist", "ValveBiped.Bip01_L_Shoulder", "ValveBiped.Bip01_L_Elbow", "ValveBiped.Bip01_L_Bicep", "ValveBiped.Bip01_L_Trapezius", -- Right Fingers "ValveBiped.Bip01_R_Finger4", "ValveBiped.Bip01_R_Finger41", "ValveBiped.Bip01_R_Finger42", "ValveBiped.Bip01_R_Finger3", "ValveBiped.Bip01_R_Finger31", "ValveBiped.Bip01_R_Finger32", "ValveBiped.Bip01_R_Finger2", "ValveBiped.Bip01_R_Finger21", "ValveBiped.Bip01_R_Finger22", "ValveBiped.Bip01_R_Finger1", "ValveBiped.Bip01_R_Finger11", "ValveBiped.Bip01_R_Finger12", "ValveBiped.Bip01_R_Finger0", "ValveBiped.Bip01_R_Finger01", "ValveBiped.Bip01_R_Finger02", -- Left Fingers "ValveBiped.Bip01_L_Finger4", "ValveBiped.Bip01_L_Finger41", "ValveBiped.Bip01_L_Finger42", "ValveBiped.Bip01_L_Finger3", "ValveBiped.Bip01_L_Finger31", "ValveBiped.Bip01_L_Finger32", "ValveBiped.Bip01_L_Finger2", "ValveBiped.Bip01_L_Finger21", "ValveBiped.Bip01_L_Finger22", "ValveBiped.Bip01_L_Finger1", "ValveBiped.Bip01_L_Finger11", "ValveBiped.Bip01_L_Finger12", "ValveBiped.Bip01_L_Finger0", "ValveBiped.Bip01_L_Finger01", "ValveBiped.Bip01_L_Finger02", } -- Table of player models and there bones to hide. MyHands.Models = {} -- Table of bones that need to be hidden. MyHands.Hidden = {} -- Table of entities to draw models onto. MyHands.Entity = {} for k , v in pairs( MyHands.Entity ) do SafeRemoveEntity( v ) end -- Clean command to reset the state of MyHands, good if a model got garbled. concommand.Add( "myhands_reset" , function() table.Empty( MyHands.Models ) table.Empty( MyHands.Hidden ) for k , v in pairs( MyHands.Entity ) do SafeRemoveEntity( v ) end table.Empty( MyHands.Entity ) end ) -- All the complex code is done here to setup MyHands and draw them. local T , P , M , I MyHands.Draw = function( V , U , W ) -- Make sure 'myhands_enabled' is '1'. if ( MyHands.Enabled:GetBool() ~= true ) then return end -- Fix that prevents the model from getting garbled. if ( FrameTime() == 0 ) then return end -- Get the correct player to fetch the model from. P = ( IsValid( W:GetOwner() ) and W:GetOwner() or U ) if ( not IsValid( P ) ) then return end I = P:UserID() if ( not I ) then return end -- Setup the MyHands.Entity which will be used. if ( not IsValid( MyHands.Entity[ I ] ) ) then SafeRemoveEntity( MyHands.Entity[ I ] ) MyHands.Entity[ I ] = ClientsideModel( "models/error.mdl" ) MyHands.Entity[ I ]:SetNoDraw( true ) MyHands.Entity[ I ]:AddEffects( EF_BONEMERGE ) MyHands.Entity[ I ].GetPlayerColor = function() return P:GetPlayerColor() end return end -- Make sure the model is set to the players. if ( MyHands.Entity[ I ]:GetModel() ~= P:GetModel() ) then MyHands.Hidden[ I ] = false MyHands.Entity[ I ]:SetModel( P:GetModel() ) M = string.lower( P:GetModel() ) return end -- Make sure the skin is set to the players. if ( MyHands.Entity[ I ]:GetSkin() ~= P:GetSkin() ) then MyHands.Entity[ I ]:SetSkin( P:GetSkin() ) return end -- Setup bodygroups. for group = 0 , MyHands.Entity[ I ]:GetNumBodyGroups() - 1 do if ( MyHands.Entity[ I ]:GetBodygroup( group ) ~= P:GetBodygroup( group ) ) then MyHands.Entity[ I ]:SetBodygroup( group , P:GetBodygroup( group ) ) end end -- Setup the parent of MyHands and local orientation. if ( MyHands.Entity[ I ]:GetParent() ~= V ) then MyHands.Entity[ I ]:SetParent( V ) MyHands.Entity[ I ]:SetLocalPos( Vector( -256 , 0 , -54 ) ) MyHands.Entity[ I ]:SetLocalAngles( Angle( 0 , 0 , 0 ) ) return end -- Setup the table of bones that should be hidden. if ( not MyHands.Models[ M ] ) then local bones = {} for bone = 0 , MyHands.Entity[ I ]:GetBoneCount() do table.insert( bones , bone ) end local valid = {} for k , name in pairs( MyHands.Bones ) do local bone = MyHands.Entity[ I ]:LookupBone( name ) if ( not bone ) then continue end table.insert( valid , bone ) end for i = 1 , 3 do for k , bone in pairs( valid ) do for k2 , child in pairs( MyHands.Entity[ I ]:GetChildBones( bone ) ) do table.insert( valid , child ) end end end for k , bone in pairs( valid ) do table.RemoveByValue( bones , bone ) end MyHands.Models[ M ] = bones return end -- Make sure the list of bones to hide is correct. if ( not MyHands.Hidden[ I ] ) then MyHands.Hidden[ I ] = MyHands.Models[ M ] return end -- Hide all the bones that should be hidden. local bone for i = 1 , #MyHands.Hidden[ I ] do bone = MyHands.Hidden[ I ][ i ] local pos , ang = MyHands.Entity[ I ]:GetBonePosition( bone ) if ( not pos or not ang ) then continue end local matrix = MyHands.Entity[ I ]:GetBoneMatrix( bone ) if ( not matrix ) then continue end MyHands.Entity[ I ]:SetBonePosition( bone , pos + ( P:EyeAngles():Forward() * -256 ) , ang ) end -- Apply the clipping plane and render MyHands. local state = render.EnableClipping( true ) local normal = P:GetAimVector() local plane = normal:Dot( P:EyePos() + ( P:GetAimVector() * ( MyHands.Clip:GetFloat() ) ) ) render.PushCustomClipPlane( normal , plane ) MyHands.Entity[ I ]:DrawModel() render.PopCustomClipPlane() render.EnableClipping( state ) -- Make sure the default viewmodel hands dont draw. return true end -- All the usual stuff normally done in 'PostDrawViewModel' is done here plus MyHands specific code. MyHands.Call = function( G , V , U , W ) -- Make sure all relevant Entities are valid. if ( not IsValid( V ) ) then return false end if ( not IsValid( U ) ) then return false end if ( not IsValid( W ) ) then return false end -- All the usual stuff thats in 'PostDrawViewModel'. if ( not W:IsScripted() or W.UseHands ) then local H = U:GetHands() if ( IsValid( H ) ) then if ( not hook.Call( "PreDrawPlayerHands" , G , H , V , U , W ) ) then if ( W.ViewModelFlip ) then render.CullMode( MATERIAL_CULLMODE_CW ) end -- Draw my playermodel hands or the default ones. if ( not MyHands.Draw( V , U , W ) ) then H:DrawModel() end render.CullMode( MATERIAL_CULLMODE_CCW ) end hook.Call( "PostDrawPlayerHands" , G , H , V , U , W ) end end player_manager.RunClass( U , "PostDrawViewModel" , V , W ) if ( W.PostDrawViewModel == nil ) then return false end return W:PostDrawViewModel( V , W , U ) end -- This hook should always be called last and as such should not interfere with other hooks. hook.Add( "PostDrawViewModel" , string.char( 0 ) , function( ... ) local vm,pl,weap = ... if !IsValid(weap) then return end if weapons.IsBasedOn( weap:GetClass(), "tfa_gun_base" ) then return end return MyHands.Call( GAMEMODE , ... ) end )