Created
July 25, 2017 13:51
-
-
Save Grissess/6b08217bd3ec1ae95f02c1c5fcda07cf to your computer and use it in GitHub Desktop.
Garry's Mod fix for real death ragdolls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
Deathfix -- a simple Garry's Mod script for making real death ragdolls | |
(drop into <game root>/garrysmod/lua/autorun/server) | |
It's been too long for me to remember the original author, but I can safely | |
say that I've modified it quite a bit anyway. Notwithstanding the other author's | |
claim on this file, I hereby grant this file to the public domain. | |
]]-- | |
if SERVER then | |
SetGlobalBool("RunningDeathFix", true) | |
--AddCSLuaFile("sh_Deathfix.lua") | |
Msg("DeathFix loaded :D\n") | |
elseif (not game.SinglePlayer()) and CLIENT and (not GetGlobalBool("RunningDeathFix")) then | |
return | |
end | |
local MaxRagdolls = 3 | |
local meta = FindMetaTable("Player") | |
local old_CreateRagdoll=meta.CreateRagdoll | |
local dodeathfix=CreateConVar("sv_deathfix", "1") | |
local function CC_MaxDeathRagdolls(ply, cmd, arg) | |
if not (ply:IsAdmin() and arg[1]) then return end | |
local val = tonumber(arg[1]) | |
MaxRagdolls = (val and (val > 0)) and val or MaxRagdolls | |
end | |
concommand.Add("sbox_maxdeathragdolls", CC_MaxDeathRagdolls) | |
local function RemoveFromDeathRagdollTbl(self,tbll) | |
return table.remove(tbll.tbl, tbll.idx) | |
end | |
local modelmap = { | |
["models/mlp/player_default_base.mdl"] = "models/mlp/player_default_base_ragdoll.mdl", | |
["models/mlp/player_default_base_nj.mdl"] = "models/mlp/player_default_base_ragdoll.mdl", | |
["models/mlp/player_high_base.mdl"] = "models/mlp/player_default_base_ragdoll.mdl", | |
["models/mlp/player_mature_base.mdl"] = "models/mlp/player_default_base_ragdoll.mdl" | |
} | |
function meta:CreateRagdoll() | |
if CLIENT then return end | |
if dodeathfix:GetInt()==0 then return old_CreateRagdoll(self) end | |
if not (self and self.IsValid and self.IsPlayer and self:IsValid() and self:IsPlayer()) then return Error("No player given.\n") end | |
self.DeathRagdolls = self.DeathRagdolls or {} | |
if #self.DeathRagdolls >= MaxRagdolls then | |
if self.DeathRagdolls[1].IsValid and self.DeathRagdolls[1]:IsValid() then | |
self.DeathRagdolls[1]:Remove() | |
end | |
end | |
local ply_pos = self:GetPos() | |
local ply_ang = self:GetAngles() | |
local ply_mdl = self:GetModel() | |
local probably_pony=false | |
--Msg(ply_mdl) | |
if string.EndsWith(ply_mdl, "_player.mdl") then | |
new_ply_mdl, _=string.gsub(ply_mdl, "_player", "") | |
if util.IsValidModel(new_ply_mdl) then | |
ply_mdl=new_ply_mdl | |
probably_pony=true | |
--new_ply_mdl, _=string.gsub(ply_mdl, "models/", "models/vn_") | |
--if util.IsValidModel(new_ply_mdl) then | |
-- ply_mdl=new_ply_mdl | |
--end | |
end | |
--Msg(ply_mdl) | |
end | |
if modelmap[ply_mdl]~=nil then | |
ply_mdl=modelmap[ply_mdl] | |
end | |
local ply_skn = self:GetSkin() | |
local ply_col = self:GetColor() | |
local ply_mat = self:GetMaterial() | |
local ent = ents.Create("prop_ragdoll") | |
ent:SetPos(ply_pos) | |
ent:SetAngles(ply_ang - Angle(ply_ang.p,0,0)) | |
ent:SetModel(ply_mdl) | |
ent:SetSkin(ply_skn) | |
ent:SetMaterial(ply_mat) | |
ent:Spawn() | |
if not ent:IsValid() then return end | |
ent.DeathRagdollsIdx = table.insert(self.DeathRagdolls, ent) | |
ent:CallOnRemove("DeathRagdollsRemoval", RemoveFromDeathRagdollTbl, {idx = ent.DeathRagdollsIdx, tbl = self.DeathRagdolls}) | |
local plyvel = self:GetVelocity() | |
for i = 1, ent:GetPhysicsObjectCount() do | |
local bone = ent:GetPhysicsObjectNum(i) | |
if bone and bone.IsValid and bone:IsValid() then | |
local bonepos, boneang = self:GetBonePosition(ent:TranslatePhysBoneToBone(i)) | |
bone:SetPos(bonepos) | |
bone:SetAngles(boneang) | |
bone:AddVelocity(plyvel) | |
bone:SetMass(4*bone:GetMass()) | |
end | |
end | |
if self:IsOnFire() then ent:Ignite(math.Rand(6, 8), 0) end | |
if probably_pony then | |
ent:SetFlexWeight(17, 0.85) | |
ent:SetEyeTarget(Vector(53, 2, 28)) | |
end | |
self:SpectateEntity(ent) | |
self:Spectate(OBS_MODE_CHASE) | |
if GoreModCreateEntityRagdoll then | |
GoreModCreateEntityRagdoll(self, ent) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment