Player model and spwaning.

[lua]function GM:PlayerSetModel(pl)
if pl.Model then
pl:SetModel( pl.Model )

in init.lua

It does set the model, however, the arms are spread out with the crowbar sticking out like a penis, and there are no player animations.

I really have no idea why the player animations are broken, but I’ve been trying to fix it.

After you die, I wait a frame, then make the player spectate OBS_MODE_ROAMING
It works fine, but then when it comes time to spawn again, you spawn where your spectating body is.

Say you go outside of the map for no reason when you spectate, then next round you will spawn outside of the map, not at a spawnpoint. I even tried to KillSilent RIGHT before the player was unspectated and spawned, but it doesn’t seem to work at all.

Any ideas?

Make sure it’s a player model

To add to this, make sure it’s a model in “models/player”.

For the player model make sure it’s in the player folder. An example would be “models/player/alyx.mdl”.

For your respawning problem I suggest you just SetPos when comes time to respawn.

To check for a list of all the player models use GCFScape if you don’t have it it’s on Nem’s Tools.

Then you can check the gmod content in the “garrysmod content.gcf” file. Then go to the player model folder as mentioned already.

Or just use the browse tab in your q menu.

Personally prefer to use GCFScape. Means if my Gmod is closed I don’t have to load it just to code.

Also, it makes it a lot easier to find other models and sounds later instead of just using the q menu all the time.

Wow thanks… I can’t believe I didn’t realize that.

But will this fix the spawning too?


Also the models I was using were in the Humans folder, so its all good now :smiley:

Won’t fix the spawning, maybe you need to make the player Unspectate before spawning? Or as I said you can simply set their position to a spawnpoint.

I did Unspectate, but Ill just have to do the position thing :confused:

Might be useful to post a snippet of your code so we can get a better idea of what you’re doing.

Your model is not precahced ( Well, every time this has happened to me, PrecahceModel has fixed it ) Probibly because you need to tell the engine to ‘Load’ the animations. No animations = ‘Minge’ style gun-out-of-happy-area etc
[lua]util.PrecacheModel( <Model Path> )
ply:SetModel( <Model Path> )[/lua]

I had the intention that Precaching a model doesent work and lags.

Precaching things is all good! It makes sure you don’t have to load them on the fly. Try spamming a few Citizen NPCs in sandbox to see the effect of uncached models.

But then all the players that are spawned will lag until they happen to get the same model again.

My code is poorly arranged, so I wont post it, but its basically giving everyone a random citizen/rebel/medic (yes I made sure I have a medic playermodel) playermodel, but no 2 people will have the same model.
Is it possible to precache the models before the player spawns? It would be annoying to get a model that hasen’t been used yet, then lag while spawning because it is trying to precache it.

[lua]Models = { “male1”, “female1”, “kleiner” };

function GM:PlayerSetModel( Player )
local ModelName = player_manager.TranslatePlayerModel( Models[math.random( #Models )] );
util.PrecacheModel( ModelName );
Player:SetModel( ModelName );

This method works for me on some of my older work. Hope it helps.

For the spawning, you can always do
[lua]SpecSpawn = ents.FindByClass(“info_player_start”)[/lua]

then when you want them to be able to spawn. Just set their position to table.Random(SpecSpawn)

[lua] SpecSpawn = ents.FindByClass(“info_player_start”)
for num, pl in pairs(AllPlayers) do

Yet it just breaks with no error.
Any ideas on how stupid I’m being and what I’m getting wrong?

AllPlayers = Player.GetAll() right?

Yeah, but thats besides the point.

Just how would I teleport them, cause this doesnt work.