Changing a player's model

I have this on my init.lua as a command.
[lua]
function ChangeModel( ply, args )

if( args[1] ) then

	ply:SetModel( args[1] );

end

end
concommand.Add( “rp_changemodel”, ChangeModel );
[/lua]

Then a table on the shared.lua with a few model paths.

Then I have this on the cl_init.lua
[lua]
for k, v in pairs( ModelTable ) do

	local Icon = vgui.Create( "SpawnIcon", IconList );
	
	Icon:SetModel( v );
	IconList:AddItem( Icon );
	
	Icon.DoClick = function( Icon, args )

		RunConsoleCommand( "rp_changemodel", v );
		
	end 	

end
[/lua]

I’m basicly adding spawn icons, and when you click them it changes your model, however, when you press it or try it in the console (rp_changemodel modelpath) nothing happens, aka it doesent change your model. Any idea why?

function ChangeModel( Player, Command, Arguments )

Edit:

You may also need to translate and precache the model.

E.g.
[lua]local ModelName = player_manager.TranslatePlayerModel( “kleiner” );
util.PrecacheModel( ModelName );
Player:SetModel( ModelName );[/lua]

Edit:

Also whenever a command doesn’t work try printing out the argument and seeing if it is valid and the code is executing.

in the cl_init.lua I have printed out the loop/table arguements:
[lua]
print( v )
[/lua]
And it worked, it prints out each model in the console, so I guess it’s the model change command.

I’ve tried pre caching the model (in the model change command) and added ‘cmd’ in the arguements. It seems it has worked. However, the models are T-Posed with no animations.

You sure your using the right models?

models/player/breen.mdl for example.

[lua]
ModelTable = {

	"models/Barney.mdl",
	"models/breen.mdl",
	"models/Humans/Group01/male_02.mdl",
	"models/Humans/Group02/Female_02.mdl",
	"models/Humans/Group02/Female_03.mdl"

};

[/lua]

Those are the ones I’m using, should I not be using those type?

E:
[lua]
“models/player/Barney.mdl”,
“models/player/breen.mdl”,
[/lua]
Those dont seem to T-Pose but the others do. Are there specific HL2 ‘Player’ Models?

[lua]ModelTable = {

	"models/player/Barney.mdl",
	"models/player/breen.mdl",
	"models/player/Group01/male_02.mdl",
	"models/player/Group02/Female_02.mdl",
	"models/player/Group02/Female_03.mdl"

};[/lua]

Many thanks, however I get lag when I click the spawn icon when using the util.precache. I could precache them before that, like on the loop right?

I meant print the argument in the init file.

print( args[1] ) for example.

However you fixed that how by fixing your functions parameters. Just thought I’d clear up what I meant.

I pm’d you hours ago. Use ply, cmd, args rather than ply, args.

I already told him that and he already did it and fixed that bit, please read the rest of his thread before replying. :stuck_out_tongue: