'catch' error models and replace them?

Hey there, explaining why I want to do this might take a little while - so I’m going to cut to the point.

Client A and Client B have a playermodel file installed on their gmod, but Client C doesn’t. If Client A has the playermodel equipped, Client B should be able to see it, but Client C will see a big red error. Is there anyway to convert this error to a different playermodel that the client does have installed? and if so, how would you detect that there is a model error (checking validity of the model on the client?). And would this cause network issues like hitboxes.
Thanks, if this isn’t clear enough I can clarify.

Can’t you just attempt to install the playermodel on client C with resource.AddFile or resource.AddWorkshop?

No, the point is to have low downloads to the server with the option for each player to install the pointshop playermodels if they want to. If they dont want to, they just see regular models on everyone.

[del]Well, try searching through all players (serverside) and check if their model is ‘models/error.mdl’ and then do player:SetModel to change it to another model.

I tested player:GetModel() with a missing model and it seems to always return ‘models/error.mdl’[/del]
Try searching through players and doing util.IsValidModel before replacing the model and changing the convar ‘cl_playermodel’

Good answer, that’s what I was looking for, thanks

Wait, I’m testing more stuff and I think it doesn’t always- try using util.IsValidModel instead
Also, you need to change the client convar cl_playermodel to a different thing

[editline]31st October 2015[/editline]

Try this (there’s probably a more efficient way, though):

hook.Add( 'Think', 'ReplaceModels', function()
	for k, ply in pairs( player.GetAll() ) do
		if !util.IsValidModel( ply:GetModel() ) then
			ply:SetModel( 'models/player/kleiner.mdl' )
			ply:ConCommand( 'cl_playermodel Kleiner' )
end )

That example just replaces whatever model doesn’t work with Kleiner.

OR this if you only want to check on spawn (which appears to be the only time when the playermodels actually get updated, at least I think):

hook.Add( 'PlayerSpawn', 'ReplaceModels', function( ply )
	if !util.IsValidModel( ply:GetModel() ) then
		ply:SetModel( 'models/player/kleiner.mdl' )
		ply:ConCommand( 'cl_playermodel Kleiner' )
end )

You could probably also do a check on the models of the playermodel manager to see if any were errors and just remove them (so they don’t even come up in the playermodel selection menu).

Never change the client setting

ply:ConCommand( 'cl_playermodel Kleiner' )

It’s defined in player_default.lua class in the base gamemode

function PLAYER:SetModel()

	local cl_playermodel = self.Player:GetInfo( "cl_playermodel" )
	local modelname = player_manager.TranslatePlayerModel( cl_playermodel )
	util.PrecacheModel( modelname )
	self.Player:SetModel( modelname )


So all you have to do is to create a new class that overide this, and does the check

The fixes you guys have put are all server side. I think he ment client side that is would show the correct model if the has it or default to another if they client does not have it.

Oh, didn’t think about that… nevermind about anything I said then (in case the post above seems a bit too confusing, the OP meant that the models wouldn’t be errors for everyone, only some clients, and he wanted to know how to replace the model being seen by one client without it (or more) to another.

I remember ErrorCleanse just made meshes and tried to approximate the error model. I wish it was still supported.

I’m not very good with lua but I believe you could use http://wiki.garrysmod.com/page/file/Exists to see if the model file exists on the client side.