Best way to attack a weapon to a ragdoll?

Attach**

Let’s make this simple.

Here’s my current fail code:
[lua]
local wep = ply:GetActiveWeapon();
if (wep:IsValid()) then
local ainfo = rag:GetAttachment(5); --anim_attachment_RH
local propwep = ents.Create(“prop_physics”);
propwep:SetModel(wep:GetModel():gsub(“v_”,“w_”));
propwep:SetPos(ainfo.Pos);
propwep:SetAngles(ainfo.Ang);
propwep:SetParent(rag);
propwep:Spawn();
propwep:Fire(“SetParentAttachmentMaintainOffset”, “anim_attachment_RH”);
end
[/lua]

The ragdoll is meant to be the player and I need to transfer his weapon to the ragdoll’s hand. The rag variable is a prop_ragdoll that was previously created.

This code has the same outcome as:
[lua]
local wep = self:GetActiveWeapon();
if (wep:IsValid()) then
local propwep = ents.Create(“prop_physics”);
propwep:SetModel(wep:GetModel():gsub(“v_”,“w_”));
propwep:SetParent(rag);
propwep:Spawn();
propwep:Fire(“SetParentAttachment”, “anim_attachment_RH”);
end
[/lua]

Which looks like:

I’m sure it has something to do with using the RH bone position of the weapon but I’m not sure how to do that math.

Update
So I spent the time trying to figure out the best way to do it. First I tried using what seemed like the correct bone (ValveBiped.Bip01_R_Hand on the weapon) found the difference between that bone pos and the prop’s origin and applied it to the ragdoll’s attachment, ect ect. Didn’t look right for everything but the smg which came close.

I also had to apply the weapon’s position 3 times total, once at creation, then 2 times after with 0.05 second spacing. Not sure why this is, something to do with the physics and how it updates I guess.

I settled for a preset table of vector and angle offsets that I found by hand. Fun stuff.

As well as I know the weapons word models have bones too. Usually only one, the position of the reagdolls left ( or right ) hand.

Check this site for more information: http://developer.valvesoftware.com/wiki/Creating_worldmodels_from_viewmodels

[lua]propwep:SetParent(rag)
propwep:AddEffects(EF_BONEMERGE)[/lua]

You should create propwep clientside with ClientsideModel.

So… rag mod only you actually have weapons on the rag doll? Cool beans, now we just need the guns to actually shoot where they are pointing rather than at the cross hair from the gun itself, a very hard and complex sounding idea I think.

Then again I’m just the ignorant passer by.

Not that hard, but annoying, because the games animation arent smooth enough.