How do i change the player model

Hi facepunch.

Can someone tell me how to change the players model with lua?

Thanks in advance

You need to get a player’s player object and apply SetModel() to it.

The best way to do it is inside a gamemode hook such as PlayerSpawn.

[lua]hook.Add(“PlayerSpawn”,“PlayerModelHook”, function(ply) – Here ply is the player’s object of the player who has just spawned.
ply:SetModel(“path/to/model.mdl”) – Change that to a valid model
:eng101: <-- We use Entity.SetModel because a player is an entity


Also a direct way to grab a player’s object without hooks is player.GetByID().

So you could do this in console to change your model :

player.GetByID(1):SetModel("path/to/model.mdl") -- Change that to a valid model  

for k,v in pairs(models) do
	local icon = vgui.Create( "SpawnIcon", IconList ) 
	icon:SetModel( v )
	icon.DoClick = function( icon ) surface.PlaySound( "vo/npc/male01/thislldonicely01.wav" ) ply:SetModel( v )  end 
 	IconList:AddItem( icon )

This does not work


And could you also tell me how to add plain text to a derma (Not a text box)

This doesn’t work because it is clientside and ply is not a defined value.
Clientside the client’s object is obtained with LocalPlayer() but that won’t help you since you need to do all model changes serverside. So you would have the player run a console command with the model as an argument.

This should work, but is untested :

[lua]local v = “path/to/model.mdl”
RunConsoleCommand(“modelchange”, v)[/lua]

[lua]function ChangePlayerModel( ply, command, arguments )
local model = arguments[1]

concommand.Add( “modelchange”, ChangePlayerModel)[/lua]

For text use this :

and you should probably take a look at the library :

Thank you