How do I create an "hl2mp_ragdoll"?

	if ( m_hRagdoll )
		UTIL_RemoveImmediate( m_hRagdoll );
		m_hRagdoll = NULL;

	// If we already have a ragdoll, don't make another one.
	CHL2MPRagdoll *pRagdoll = dynamic_cast< CHL2MPRagdoll* >( m_hRagdoll.Get() );
	if ( !pRagdoll )
		// create a new one
		pRagdoll = dynamic_cast< CHL2MPRagdoll* >( CreateEntityByName( "hl2mp_ragdoll" ) );

	if ( pRagdoll )
		pRagdoll->m_hPlayer = this;
		pRagdoll->m_vecRagdollOrigin = GetAbsOrigin();
		pRagdoll->m_vecRagdollVelocity = GetAbsVelocity();
		pRagdoll->m_nModelIndex = m_nModelIndex;
		pRagdoll->m_nForceBone = m_nForceBone;
		pRagdoll->m_vecForce = m_vecTotalBulletForce;
		pRagdoll->SetAbsOrigin( GetAbsOrigin() );

	// ragdolls will be removed on round restart automatically
	m_hRagdoll = pRagdoll;

This is the C++ code.
I tried to make a binary module to do this, but I suck at making binary modules.
How would I do this in lua?

Btw, this is all server-sided. I just want to make a client-sided ragdoll.

Have it so when a player dies this runs
[lua]function Rag(ply)
local rag = ents.Create(“hl2mp_ragdoll”)
ply.rag = rag
hook.Add(“PlayerDeath”, Rag)
Then when the player spawns
function Spawn(ply)
if ply.rag:IsValid() then
ply.rag = nil
hook.Add(“PlayerSpawn”, Spawn)
thats the best I can do, it will take a bit more work to get all the forces applied like your C code.

EDIT: oops, just do the functions above on the client in a function called by a usermessage sent in the hooks. forgot you wanted it clientside

I’m doing it for an NPC.

hl2mp_ragdoll doesn’t work that way.

You can’t just set the position. The entity isn’t a ragdoll entity, it’s a handler for spawning client ragdolls.

Well then, you would need a custom SNPC that creates a ragdoll on the client when it is killed. And, why would it not work that way? There shouldn’t be anything with the code that won’t make it work.

Because it isn’t a physical ragdoll entity. The entity sends networked positions, angles, models, bones, and entity indexes to all clients so that the client creates the entity “C_ClientRagdoll”, which is impossible to spawn from client-side lua.

It does not create a ragdoll, it creates an entity that sends ragdoll creation data to the client.
If there exists a method to create hl2mp_ragdoll, then server-handled client-side ragdolls are possible.
I can’t find a method to do this, other than use binary modules.

I hope that you actually tested your code to see if it actually works, because in theory, it shouldn’t.

Well, could you explain to me how the entity is supposed to link up with the clientside ragdoll?

SendPropVector( SENDINFO(m_vecRagdollOrigin), -1, SPROP_COORD ),
SendPropEHandle( SENDINFO( m_hPlayer ) ),
SendPropModelIndex( SENDINFO( m_nModelIndex ) ),
SendPropInt ( SENDINFO(m_nForceBone), 8, 0 ),
SendPropVector ( SENDINFO(m_vecForce), -1, SPROP_NOSCALE ),
SendPropVector( SENDINFO( m_vecRagdollVelocity ) )

Client gets table, creates a C_ClientRagdoll, which doesn’t have an entity factory and doesn’t use the traditional “CreatebyClassname” function, sets up the positions, angles, and bones, as well as the model, and then initializes client-side physics.

My mistake, it creates C_HL2MPRagdoll

Well, the only way that I can think of doing this is by finding each ragdoll and then making applying the hl2 ragdoll to it. The problem is sometimes the bones might not match up with some NPCs.

A hacky way I came up with was to kill a bunch of NPC’s, grab their client ragdoll entity, then set their models.

It didn’t work out too awesomely, though.