Put another head's model in my head and remove original.

Dear Guys,

I have started my project on switching heads. But many ways I have tried and I have found I cant get added clientsidemodel head as scaled as it should be. Because with bonemerge the head will be scaled down like my original head.

local bonelist = {

hook.Add( “PostPlayerDraw” , “manual_model_draw_example” , function( ply )

/*Should Work*/

--local boneindex = ply:LookupBone("ValveBiped.Bip01_Head1")
--local bonematrix = ply:GetBoneMatrix(ply:LookupBone("ValveBiped.Bip01_Head1"))
--ply:ManipulateBoneScale( boneindex, Vector(0,0,0) )
--ply:SetBoneMatrix( boneindex , bonematrix )

--if IsValid(ply.MaskMDL) then SafeRemoveEntity( ply.MaskMDL ) end
--if IsValid(ply.MaskMDL) then
--ply.MaskMDL = ClientsideModel( "models/player/Group01/male_06.mdl")
--local MaskMDL = ply.MaskMDL	
--MaskMDL:SetParent( ply )
local headboneindex = MaskMDL:LookupBone("ValveBiped.Bip01_Head1")
local headbonematrix = MaskMDL:GetBoneMatrix(MaskMDL:LookupBone("ValveBiped.Bip01_Head1"))
MaskMDL:ManipulateBoneScale( headboneindex, Vector(1,1,1) )
MaskMDL:SetBoneMatrix( headboneindex , headbonematrix )

if IsValid(ply.MaskMDL) then
ply.MaskMDL = ClientsideModel( "models/player/Group01/male_06.mdl")
local MaskMDL = ply.MaskMDL	
local headmatrix = ply:GetBoneMatrix(ply:LookupBone("ValveBiped.Bip01_Head1"))
for key, bone in pairs(bonelist) do
	local index = MaskMDL:LookupBone(bone)  
	--if !isnumber(MaskMDL:GetBoneMatrix(index)) then print(MaskMDL:GetBoneMatrix(index)) end
	local matrix = MaskMDL:GetBoneMatrix(index)
	if isnumber(matrix) then
	MaskMDL:SetBoneMatrix(index, matrix) 

local position, angles = ply:GetBonePosition(ply:LookupBone("ValveBiped.Bip01_Head1"))
local x = angles:Up() * 0  
local y = angles:Right() * 0
local z = angles:Forward() * -65

angles:RotateAroundAxis(angles:Forward(), -90)  
angles:RotateAroundAxis(angles:Right(), -90)  
angles:RotateAroundAxis(angles:Up(), 0)  

MaskMDL:SetPos(position + x + y + z)

end )


I searched on inter for others who solved this problem. Actually nobody. I only found 7 years old codes.
As far as I know maybe I need to use [LUA]GM:PostDrawOpaqueRenderables( boolean bDrawingDepth, boolean bDrawingSkybox )[/LUA] Because I had also problem with the model appeared on viewmodel also. I am using hat modify function on postplayerdraw they are working perfectly. Just the head change isnt.

Also my script is on CLIENT side.

i recall tiramisu 2 having this feature, maybe see how it was done there?

The version i have found from github says dont use. Really outdated. I will check it today. Anybody has any other idea? I can remove the head but cant put the model where to the body is. And only head appear for other model.

Okay i searched so much. Im not clever than before. No feature that can manipulate the extra model to attach right to the original player model. And other part of the model disappear.

So no new idea? In Gmod no developer who ever did this. It will be secret 4ever? No tips?

This is a little dumb but it can work: if you’re sure that the arms and hands will never go above the neck, you can use render clip planes.

this isnt a problem. I wanna place head into the original model heads pos. Thats what I am trying to do. Without bonemerge. Bonemerge not the best.

You’re welcome to create this and then share how did you achieve this! No one here is forced to share this kind of technique, and i’m sure that a good developer even not knowing it, with 20 minutes to think something out of the box, would get a good solution

But expecting people to just come out and tell you how stuff it’s done, it’s useless

Well I just gave you an idea of how to do this, so what are you asking?

Nobody asked copy paste the code. Just tips. And I will tell you it helped or not.

As i’ve stated…Nobody here knows how to do that, but if you give to a good developer this task, he’ll sit and think about this a good amount of time until he finds how to complete this task
Just do a brainstorm…Think about 2 models attached and parented, scale every bone except neck and head, use a clip plane…I don’t know, think something, don’t expect us to know about everything, that’s the spoonfed behavior that we really hate here

Heads = Heads or {}
function ClearHeads()
for k, v in pairs(Heads) do
if #Hats > 0 then

		--table.RemoveByValue( Heads, v )
		--SafeRemoveEntity( v )
for k, v in pairs( Heads ) do
	if not IsValid( v ) then
		Heads[ k ] = nil
	elseif not IsValid( v.Owner ) then
		print("Removing Head")
		SafeRemoveEntity( v )
		Heads[ k ] = nil


function AddHead(name,ply)
SafeRemoveEntity( ply.head )
–if IsValid(ply.head) then return ply.Hat end
local head
print(“Creating Head”)
head = ClientsideModel( name )
ply.Head = head
head.Owner = ply

table.insert(Heads, head )
--return head


function ModifyHead()
if IsValid(LocalPlayer().Head) then
if IsValid(LocalPlayer().Head.Owner) then
LocalPlayer().Head.Owner = nil
LocalPlayer().Head = nil

--SafeRemoveEntity( LocalPlayer().Head )

if IsValid(LocalPlayer().Head) then
SafeRemoveEntity( LocalPlayer().Head )
--LocalPlayer().Head.Owner = nil
SafeRemoveEntity( LocalPlayer().Head )
if IsValid(LocalPlayer().Head) then
LocalPlayer().Head = nil
if IsValid(LocalPlayer().Head) then
LocalPlayer().Head = nil


hook.Add( “PostPlayerDraw”, “Test_Switch_Head”, function( ply )
if !IsValid(ply) or ply:Team() != TEAM_ALIVE or !ply:Alive() then return end

if not IsValid( ply.Head ) then

	local bone = ply:LookupBone("ValveBiped.Bip01_Head1")
	local vm = ply:GetBoneMatrix(bone)
	vm:Scale(Vector(0.01, 0.01, 0.01))
	ply:SetBoneMatrix(bone, vm)
	AddHead( "models/player/group01/female_01.mdl", ply )
	ply.Head:AddEffects( EF_BONEMERGE )
	for i = 0, ply.Head:GetBoneCount()-1 do
		if ply.Head:GetBoneName( i ) == "ValveBiped.Bip01_Head1" 
			local vm = ply.Head:GetBoneMatrix(i)
			vm:Scale( Vector( 1, 1, 1 ) ) -- 1/0.01
			ply.Head:SetBoneMatrix( i, vm )
		elseif ply.Head:GetBoneName( i ) != "__INVALIDBONE__" and 
		ply.Head:GetBoneName( i ) != "ValveBiped.Bip01_Head1" 
			local vm = ply.Head:GetBoneMatrix( i )
			vm:Scale( Vector( 0.01, 0.01, 0.01 ) )
			ply.Head:SetBoneMatrix( i, vm )
ply.Head:SetNoDraw( false )


I cant understand why scale not working. I will try with manipulate tomorrow.