Player Model in DarkRP HUD Help

I’ve tried:


local function PlayerModel()

	PlayerModel = vgui.Create("DModelPanel")
	PlayerModel:SetModel( LocalPlayer():GetModel() )
	function PlayerModel:LayoutEntity( Entity ) return end
	PlayerModel:SetPos(40, ScrH()-40-150)
	PlayerModel:SetAnimated(false)
	PlayerModel:SetSize(75, 150)
	PlayerModel:SetCamPos(Vector( 16, 0, 65 ))
	PlayerModel:SetLookAt(Vector( 0, 0, 65 ))
   
	timer.Create( "UpdatePlayerModel", 1, 0, function()
			if LocalPlayer():GetModel() ~= PlayerModel.Entity:GetModel() then
					PlayerModel:Remove()
					PlayerModel = vgui.Create("DModelPanel")         
					PlayerModel:SetModel( LocalPlayer():GetModel())
					function PlayerModel:LayoutEntity( Entity ) return end
					PlayerModel:SetPos(40, ScrH()-40-150)
					PlayerModel:SetAnimated(false)
					PlayerModel:SetSize(75, 150)
					PlayerModel:SetCamPos(Vector( 16, 0, 65 ))
					PlayerModel:SetLookAt(Vector( 0, 0, 65 ))
			end
	end)

end
hook.Add("HUDPaint", "PlayerModel", PlayerModel)

When I use that, it makes my game laggy, and when I pull up any menu, it makes my mouse blink and I can’t click anything.

DO NOT use vgui.Create in HUDPaint; it will just be created over and over again.

What should I use?

Do it outside of the hook, or make an if statement ( if !vguiframe ) then create the frame end…

Also, why is this in the middle of another function?


	function PlayerModel:LayoutEntity( Entity ) return end

[editline]7th July 2014[/editline]

Two times actually; what?

I found it…I didn’t really know what else to do with it

The timer shouldn’t be in the hook either, and it isn’t needed…


hook.Add("HUDPaint", "PlayerModel", function( )
	local _p = LocalPlayer( );

	// Make sure valid player, otherwise model won't work
	if ( !IsValid( _p ) ) then return; end

	// Useful vars we reuse...
	local _model = _p:GetModel( );

	// Make sure the vgui element hasn't been made...
	if ( !PlayerModel || !ispanel( PlayerModel ) ) then
		PlayerModel = vgui.Create( "DModelPanel" );
		PlayerModel:SetModel( _model );
		PlayerModel.__Model = _model;
		PlayerModel:SetPos( 40, ScrH( ) - 40 - 150 );
		PlayerModel:SetAnimated( false );
		PlayerModel:SetSize( 75, 150 )
		PlayerModel:SetCamPos( Vector( 16, 0, 65 ) );
		PlayerModel:SetLookAt( Vector( 0, 0, 65 ) );
		PlayerModel:ParentToHUD( ); -- If it is used on the hud...
	end

	// Update the model if it changes
	if ( _p:GetModel( ) != PlayerModel.__Model ) then
		PlayerModel:SetModel( _model );   
		PlayerModel.__Model = _model;
	end

	// Draw it....
	-- up to you.
end );

Thanks, that worked, but the model is still animated and it rotates

For some reason it checks .bAnimated value instead of GetAnimated, but not sure why it isn’t setting it using the Accessor funcs…


hook.Add("HUDPaint", "PlayerModel", function( )
	local _p = LocalPlayer( );

	// Make sure valid player, otherwise model won't work
	if ( !IsValid( _p ) ) then return; end

	// Useful vars we reuse...
	local _model = _p:GetModel( );

	// Make sure the vgui element hasn't been made...
	if ( !PlayerModel || !ispanel( PlayerModel ) ) then
		PlayerModel = vgui.Create( "DModelPanel" );
		PlayerModel:SetModel( _model );
		PlayerModel.__Model = _model;
		PlayerModel:SetPos( 40, ScrH( ) - 40 - 150 );
		PlayerModel:SetAnimated( false );
		PlayerModel.bAnimated = false; -- SetAnimated should access this, but not sure why it doesn't.. May be a parent panel that takes it over, this should be corrected and I'll look into a fix for it.
		PlayerModel:SetSize( 75, 150 )
		PlayerModel:SetCamPos( Vector( 16, 0, 65 ) );
		PlayerModel:SetLookAt( Vector( 0, 0, 65 ) );
		PlayerModel:ParentToHUD( ); -- If it is used on the hud...
	end

	// Update the model if it changes
	if ( _p:GetModel( ) != PlayerModel.__Model ) then
		PlayerModel:SetModel( _model );
		PlayerModel.__Model = _model;
	end

	// Draw it....
	-- up to you.
end );

Just wondering because I have struggled with this a lot and am still learning lua and I am only making a hud for a personal community. Is it possible to move and resize this playermodel thing? Ive tried with the current lua and nothing is happening. Please help <3