Dramatic Ragdoll death

Hi, I am trying to modify my murder gamemode so when a user gets killed, it will dramatically launch the dead body opposite direction of were they were stabbed (Stabbed in the back, gets launch forward) I know murder turns you into a ragdoll when you die but ive been trying for hours, So i decided to come here. Idk if this is all i need, but here,

cl_ragdoll:


local PlayerMeta = FindMetaTable("Player")
local EntityMeta = FindMetaTable("Entity")

PlayerMeta.GetRagdollEntityOld = PlayerMeta.GetRagdollEntity
function PlayerMeta:GetRagdollEntity()
	local ent = self:GetNWEntity("DeathRagdoll")
	if IsValid(ent) then
		return ent
	end
	return self:GetRagdollEntityOld()
end

PlayerMeta.GetRagdollOwnerOld = PlayerMeta.GetRagdollOwner
function EntityMeta:GetRagdollOwner()
	local ent = self:GetNWEntity("RagdollOwner")
	if IsValid(ent) then
		return ent
	end
	return self:GetRagdollOwnerOld()
end

sv_ragdoll:


local PlayerMeta = FindMetaTable("Player")
local EntityMeta = FindMetaTable("Entity")

local dtypes = {}
dtypes[DMG_GENERIC]=""
dtypes[DMG_CRUSH]="Blunt Force"
dtypes[DMG_BULLET]="Bullet"
dtypes[DMG_SLASH]="Laceration"
dtypes[DMG_BURN]="Fire"
dtypes[DMG_VEHICLE]="Blunt Force"
dtypes[DMG_FALL]="Fall force"
dtypes[DMG_BLAST]="Explosion"
dtypes[DMG_CLUB]="Blunt Force"
dtypes[DMG_SHOCK]="Shock"
dtypes[DMG_SONIC]="Sonic"
dtypes[DMG_ENERGYBEAM]="Enery"
dtypes[DMG_DROWN]="Hydration"
dtypes[DMG_PARALYZE]="Paralyzation"
dtypes[DMG_NERVEGAS]="Nervegas"
dtypes[DMG_POISON]="Poison"
dtypes[DMG_RADIATION]="Radiation"
dtypes[DMG_DROWNRECOVER]=""
dtypes[DMG_ACID]="Acid"
dtypes[DMG_PLASMA]="Plasma"
dtypes[DMG_AIRBOAT]="Energy"
dtypes[DMG_DISSOLVE]="Energy"
dtypes[DMG_BLAST_SURFACE]=""
dtypes[DMG_DIRECT]="Fire"
dtypes[DMG_BUCKSHOT]="Bullet"


local DeathRagdollsPerPlayer = 3
local DeathRagdollsPerServer = 22

PlayerMeta.CreateRagdollOld = PlayerMeta.CreateRagdoll
function PlayerMeta:CreateRagdoll(attacker, dmginfo)
	local ent = self:GetNWEntity("DeathRagdoll")

	// remove old player ragdolls
	if !self.DeathRagdolls then self.DeathRagdolls = {} end
	local countPlayerRagdolls = 1
	for k,rag in pairs(self.DeathRagdolls) do
		if IsValid(rag) then
			countPlayerRagdolls = countPlayerRagdolls + 1
		else
			self.DeathRagdolls[k] = nil
		end
	end
	if DeathRagdollsPerPlayer >= 0 && countPlayerRagdolls > DeathRagdollsPerPlayer then
		for i = 0,countPlayerRagdolls do
			if countPlayerRagdolls > DeathRagdollsPerPlayer then
				self.DeathRagdolls[1]:Remove()
				table.remove(self.DeathRagdolls,1)
				countPlayerRagdolls = countPlayerRagdolls - 1
			else
				break
			end
		end
	end

	// remove old server ragdolls
	local c2 = 1
	for k,rag in pairs(GAMEMODE.DeathRagdolls) do
		if IsValid(rag) then
			c2 = c2 + 1
		else
			GAMEMODE.DeathRagdolls[k] = nil
		end
	end
	if DeathRagdollsPerServer >= 0 && c2 > DeathRagdollsPerServer then
		for i = 0,c2 do
			if c2 > DeathRagdollsPerServer then
				GAMEMODE.DeathRagdolls[1]:Remove()
				table.remove(GAMEMODE.DeathRagdolls,1)
				c2 = c2 - 1
			else
				break
			end
		end
	end

	local Data = duplicator.CopyEntTable( self )

	local ent = ents.Create( "prop_ragdoll" )
		duplicator.DoGeneric( ent, Data )
	ent:Spawn()
	ent:SetCollisionGroup(COLLISION_GROUP_WORLD)
	ent:Fire("kill","",60 * 8)
	if ent.SetPlayerColor then
		ent:SetPlayerColor(self:GetPlayerColor())
	end
	ent:SetNWEntity("RagdollOwner", self)
	
	ent.Corpse = {}
	ent.Corpse.Name = self:Nick()
	ent.Corpse.CauseDeath = ""
	if dmginfo then
		local t = dmginfo:GetDamageType()
		// do bitmasks
	end
	ent.Corpse.Attacker = ""
	if IsValid(attacker) && attacker:IsPlayer() then
		if attacker == self then
			if ent.Corpse.CauseDeath == "" then
				ent.Corpse.CauseDeath = "Suicide"
			end
		else
			ent.Corpse.Attacker = attacker:Nick()
		end
		local wep = dmginfo:GetInflictor()
		-- inflicter doesn't work, do on GM:PlayerDeath
	end

	// set velocities
	local Vel = self:GetVelocity()

	local iNumPhysObjects = ent:GetPhysicsObjectCount()
	for Bone = 0, iNumPhysObjects-1 do

		local PhysObj = ent:GetPhysicsObjectNum( Bone )
		if IsValid(PhysObj) then

			local Pos, Ang = self:GetBonePosition( ent:TranslatePhysBoneToBone( Bone ) )
			PhysObj:SetPos( Pos )
			PhysObj:SetAngles( Ang )
			PhysObj:AddVelocity( Vel )

		end

	end

	// finish up
	self:SetNWEntity("DeathRagdoll", ent )
	table.insert(self.DeathRagdolls,ent)
	table.insert(GAMEMODE.DeathRagdolls,ent)
end

PlayerMeta.GetRagdollEntityOld = PlayerMeta.GetRagdollEntity
function PlayerMeta:GetRagdollEntity()
	local ent = self:GetNWEntity("DeathRagdoll")
	if IsValid(ent) then
		return ent
	end
	return self:GetRagdollEntityOld()
end

PlayerMeta.GetRagdollOwnerOld = PlayerMeta.GetRagdollOwner
function EntityMeta:GetRagdollOwner()
	local ent = self:GetNWEntity("RagdollOwner")
	if IsValid(ent) then
		return ent
	end
	return self:GetRagdollOwnerOld()
end

function GM:RagdollSetDeathDetails(victim, inflictor, attacker) 
	local rag = victim:GetRagdollEntity()
	if rag then
		if IsValid(inflictor) && inflictor:IsWeapon() then
			if inflictor.PrintName then
				rag.Corpse.inflictor = inflictor.PrintName
			else
				rag.Corpse.inflictor = inflictor:GetClass()
			end
		end
	end
end

Thanks in advanced :slight_smile:

So, uh… What’s the problem?

I would like to make the deaths more dramatic, Like when you get stabbed or shot or killed from fall damage (only possible deaths) It will launch you FAST in a certain direction, E.g you get shot in the back, Your Body LAUNCHES forward, Stabbed in the face, your body launches backwards… Thing is i cant figuer out how to do this. I have look at this code for hours. Please help

So, essentially you did nothing, and want us to do it?

I tried to do it, But i have no idea how to. If you feel like doing it then go ahead. I appreciate anything i can get.

Take a look at the fists that come standard with Garrys Mod. I believe they have an example of damage force.

If you can’t figure it out from that then you need some other types of help…

P.S. You are looking for the WEAPONS code not the players code. The weapon is where force is applied.

You could get the normal of the attack direction; and right here:

[lua] – position the bones
local num = rag:GetPhysicsObjectCount()-1
local v = ply:GetVelocity()

– bullets have a lot of force, which feels better when shooting props,
– but makes bodies fly, so dampen that here
if dmginfo:IsDamageType(DMG_BULLET) or dmginfo:IsDamageType(DMG_SLASH) then
v = v / 5
end

for i=0, num do
local bone = rag:GetPhysicsObjectNum(i)
if IsValid(bone) then
local bp, ba = ply:GetBonePosition(rag:TranslatePhysBoneToBone(i))
if bp and ba then
bone:SetPos(bp)
bone:SetAngles(ba)
end

     -- not sure if this will work:
     bone:SetVelocity(v)
  end

end[/lua]

Is where TTT handles throwing the ragdoll / continuing motion, transferring bone positions, etc.

Instead of dividing out the velocity, you could multiply. this is in corpse.lua for terrortown, to give you some ideas on your system.

Hmmmm Thanks :slight_smile: