HL2 Ragdoll fix

Source programming is hard enough without the abundance of crazy bugs already existing in the code that exist without your having ever done anything. One such bug is found when you try to join a game already in progress, and its a real piece of work. Your client spawns ~ 40-400 ragdolls before even opening up the MOTD notice, leading to a full stop of all possible interaction. Its a real irritating situation and it was bringing Firearms: Source to a halt server joining. .


The project tried to patch it a couple times but unfortunately things didn’t work out very well. The good news is we bit our lips and went to work on fixing it the weekend before last and achieved our goal, and even took things to the next level, but I’m getting ahead of myself – I have a tendency to do that.

The fix we have implemented blocks ragdolls from spawning for the first 2 seconds from joining the server, and hot wires it when you reach the team menu to turn them on. From the lay persons position its pretty straight forward – They see no ragdolls and don’t think anything of it. From the coders perspective, as the other coder i work with put it,

<@SteveUK> quite a simple solution too (if it works)


This is the second time he has been borderline complementing me, so excuse me if i bask in the glow. Below is the code change that lead to this fix.

Inside gameclientfasc_fas_player.cpp

void C_FASRagdoll::CreateRagdoll()
	// First, initialize all our data. If we have the player's entity on our client,
	// then we can make ourselves start out exactly where the player is.
	C_FASPlayer *pPlayer = dynamic_cast< C_FASPlayer* >( m_hPlayer.Get() );

	if (!C_FASPlayer::GetLocalFASPlayer()->CanSpawnRagdoll())
		DevMsg("No Ragdollsn");

Inside gameclientfasc_fas_player.h

bool CanSpawnRagdoll() { return !m_bInitialSetup && (m_fBufferTime < gpGlobals->curtime); }
void CanSpawnRagdoll(float flInterval) { m_fBufferTime = gpGlobals->curtime + flInterval; }
bool m_bInitialSetup;
float m_fBufferTime;

Inside C_FASPlayer::ClientThink() I check the InitialSetup boolean and set the buffer time to a value of 2 seconds. This works because the boolean value is set on creation of the new client class, which happens when you join the server. Once the buffer is set it is pretty straight forward, once it is passed by the current time on the server true is returned and the ragdolls are spawned =D.

Many other mods have tried to stop things but end up with a ragdoll posed player model at the origin of the map (which is actually more irritating than the ragdolls imo). Feel free to pass this fix around to other mods trying to increase the player count on their servers.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.