Add player model to hud.

Hi, I’m making HUD. I need to put player model or texture to a corner of hud like :

Thanks for helping me.

You’ll need to use DModelPanel for that. Dont draw the model directly onto the hud in your cl_hud file, you will have to hook it to something

Try this out. You will also have to hook it.
[lua]
function ModelView()

local iconmodel = vgui.Create("DModelPanel")	
		iconmodel:SetModel( LocalPlayer():GetModel())
        function iconmodel:LayoutEntity( Entity ) return end
		iconmodel:SetPos(20, ScrH() - 195)
		iconmodel:SetAnimated(false)
		iconmodel:SetSize(100,100)
		iconmodel:SetCamPos( Vector( 14, 4, 65))
		iconmodel:SetLookAt( Vector( 0, 0, 66.5 ) )

end
[/lua]

Also, you’re using an RP script (probably DarkRP) so you’re going to want it to change when the player switches player model. Something like this:

[Lua]
hook.Add(“InitPostEntity”, “DrawPlayerModel”, function() – must be in initpostentity or it will say its a null entity
iconmodel = vgui.Create(“DModelPanel”)
iconmodel:SetModel( LocalPlayer():GetModel())
function iconmodel:LayoutEntity( Entity ) return end
iconmodel:SetPos(20, ScrH() - 195)
iconmodel:SetAnimated(false)
iconmodel:SetSize(100,100)
iconmodel:SetCamPos( Vector( 14, 4, 65))
iconmodel:SetLookAt( Vector( 0, 0, 66.5 ) )

timer.Create("RefreshAvatar", 1, 0, function()
	if LocalPlayer():GetModel() ~= iconmodel.Entity:GetModel() then
		iconmodel:Remove()
		
		iconmodel = vgui.Create("DModelPanel")
		iconmodel:SetModel( LocalPlayer():GetModel())
		function iconmodel:LayoutEntity( Entity ) return end
		iconmodel:SetPos(20, ScrH() - 195)
		iconmodel:SetAnimated(false)
		iconmodel:SetSize(100,100)
		iconmodel:SetCamPos( Vector( 14, 4, 65))
		iconmodel:SetLookAt( Vector( 0, 0, 66.5 ) )
	end
end)

end)
[/lua]

It worked thanks. But When pressing Q player model still shows up.

Well I can’t do everything for you :v:. However, is it that big of a problem?

Nope :S I’m doing a lot of lua things this week. So I have a lot of problems with 'em

It’s because you are using InitPostEntity instead of HUDPaint, you can use part of my code if you want to use HUDPaint.


local function DrawCustomHUD()
--
--
-- some shit you don't need
--
--
	if !DermaShown then
		PlayerIcon = vgui.Create("SpawnIcon")
		PlayerIcon:SetPos( 15, ScrH() - 75 )
		PlayerIcon:SetSize(60, 60)
		PlayerIcon:SetToolTip("")
		PlayerIcon:SetModel(LocalPlayer():GetModel())

		DermaShown = true

	end
	PlayerIcon:SetModel(LocalPlayer():GetModel() or "models/props_junk/watermelon01.mdl")
end
hook.Add("HUDPaint", "DrawCustomHUD", DrawCustomHUD)

Althought, doing SetModel all the time isn’t that smart.
I used SpawnIcon instead of DModelPanel as I didn’t really want it to animate

Going to try it thanks.