Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.47 KB | None | 0 0
  1. // How many gib particles to emit (careful, 1 gib particle emits like 30 giblets, so don't set this number super high)
  2. local TTTGore_GibsParticle = 3
  3.  
  4. // How many blood streams to make
  5. local TTTGore_BloodStreams = 10
  6.  
  7. // How many little gib models to spawn
  8. local TTTGore_GibModels = 8
  9.  
  10. // How many times to create the blood effect after losing a limb
  11. local TTTGore_BloodMissingLimbDuration = 50
  12.  
  13. // Doesn't look very good because of how source ragdolls work, but attempts to separate the limbs when exploded
  14. local TTTGore_SeparateLimbs = true
  15.  
  16. // Should ragdolls leave blood decals when damaged
  17. local TTTGore_RagdollBlood = true
  18.  
  19. // Should ragdolls emit blood squirts when shot
  20. local TTTGore_RagdollBloodSquirt = true
  21.  
  22.  
  23.  
  24.  
  25.  
  26. /*=================================================================================================
  27. DO NOT TOUCH ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING!
  28. =================================================================================================*/
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. hook.Add("TTTOnCorpseCreated", "TTTGoreRagdoll", function(rag, ply)
  36.  
  37. if (bit.band(rag.dmgtype, DMG_BLAST) == DMG_BLAST || bit.band(rag.dmgtype, DMG_FALL) == DMG_FALL) then
  38. local limbstoremove
  39. if bit.band(rag.dmgtype, DMG_BLAST) == DMG_BLAST then
  40. limbstoremove = 4-math.floor(ply.TTTGore_DamageDistance/64)
  41. else
  42. limbstoremove = math.Clamp(math.floor(ply.TTTGore_DamageTaken/25), 0, 4)
  43. end
  44.  
  45. if limbstoremove <= 0 then
  46. return
  47. end
  48.  
  49. if limbstoremove == 4 then
  50. local pos = rag:GetPos()
  51. for i=1, TTTGore_GibsParticle do
  52. local effectdata = EffectData()
  53. effectdata:SetStart( pos )
  54. effectdata:SetOrigin( pos )
  55. util.Effect( "gibs", effectdata )
  56. end
  57.  
  58. for i=1, TTTGore_BloodStreams do
  59. local vPoint = pos
  60. local effectdata = EffectData()
  61. effectdata:SetOrigin( vPoint )
  62. util.Effect("bloodstream",effectdata)
  63. end
  64. if SERVER then
  65. for i=1,TTTGore_GibModels do
  66. TTTGoreCreateGib("models/monstermash/gibs/gib_"..((i%8)+1)..".mdl", pos, rag:GetAngles(), rag)
  67. end
  68.  
  69. rag:Remove()
  70. end
  71. else
  72. if bit.band(rag.dmgtype, DMG_BLAST) == DMG_BLAST then
  73. sound.Play("deathgibs/explosion"..math.random(1,3)..".mp3", ply:GetShootPos(), 90, 100)
  74. end
  75.  
  76. local limbtable = {"LeftLeg", "LeftArm", "RightLeg", "RightArm"}
  77. for i=1, limbstoremove do
  78. local limb = table.Random(limbtable)
  79. local limbside = string.sub( limb, 1, 1 )
  80. table.remove(limbtable, table.KeyFromValue(limbtable, limb))
  81.  
  82. if string.find(limb, "Leg") then
  83. rag:ManipulateBoneScale( rag:LookupBone( "ValveBiped.Bip01_"..limbside.."_Thigh" ), Vector(0,0,0) )
  84. rag:ManipulateBoneScale( rag:LookupBone( "ValveBiped.Bip01_"..limbside.."_Calf" ), Vector(0,0,0) )
  85. rag:ManipulateBoneScale( rag:LookupBone( "ValveBiped.Bip01_"..limbside.."_Foot" ), Vector(0,0,0) )
  86. rag:ManipulateBoneScale( rag:LookupBone( "ValveBiped.Bip01_"..limbside.."_Toe0" ), Vector(0,0,0) )
  87. TTTGoreEmitBlood(rag, i, "ValveBiped.Bip01_"..limbside.."_Thigh")
  88. elseif string.find(limb, "Arm") then
  89. rag:ManipulateBoneScale( rag:LookupBone( "ValveBiped.Bip01_"..limbside.."_UpperArm" ), Vector(0,0,0) )
  90. rag:ManipulateBoneScale( rag:LookupBone( "ValveBiped.Bip01_"..limbside.."_Forearm" ), Vector(0,0,0) )
  91. if rag:LookupBone( "ValveBiped.Bip01_"..limbside.."_Ulna" ) then
  92. rag:ManipulateBoneScale( rag:LookupBone( "ValveBiped.Bip01_"..limbside.."_Ulna" ), Vector(0,0,0) )
  93. end
  94. if rag:LookupBone( "ValveBiped.Bip01_"..limbside.."_Wrist" ) then
  95. rag:ManipulateBoneScale( rag:LookupBone( "ValveBiped.Bip01_"..limbside.."_Wrist" ), Vector(0,0,0) )
  96. end
  97. rag:ManipulateBoneScale( rag:LookupBone( "ValveBiped.Bip01_"..limbside.."_Hand" ), Vector(0,0,0) )
  98. TTTGoreEmitBlood(rag, i, "ValveBiped.Bip01_"..limbside.."_UpperArm")
  99. TTTGoreCreateLimb(rag, ply, limb)
  100. end
  101. end
  102. end
  103. return
  104. end
  105.  
  106. end)
  107.  
  108.  
  109. local RedBloodEffect = {
  110. "blood_advisor_pierce_spray",
  111. "blood_advisor_pierce_spray_b",
  112. "blood_advisor_pierce_spray_c",
  113. "blood_advisor_puncture_withdraw",
  114. "blood_zombie_split_spray"
  115. }
  116.  
  117. local YellowBloodEffect = {
  118. "blood_advisor_shrapnel_impact",
  119. }
  120.  
  121. hook.Add("EntityTakeDamage", "TTTGoreDamage", function(target, dmginfo)
  122.  
  123. if target:IsPlayer() then
  124. target.TTTGore_DamageTaken = dmginfo:GetDamage()
  125. target.TTTGore_DamageDistance = target:GetPos():Distance(dmginfo:GetInflictor():GetPos())
  126. end
  127.  
  128. if (target:GetClass() == "prop_ragdoll" ) && TTTGore_RagdollBlood then
  129.  
  130. local startp = dmginfo:GetDamagePosition()
  131. local traceinfo = {start = startp, endpos = startp - Vector(0,0,50), filter = target, mask = MASK_SOLID_BRUSHONLY}
  132. local trace = util.TraceLine(traceinfo)
  133. local todecal1 = trace.HitPos + trace.HitNormal
  134. local todecal2 = trace.HitPos - trace.HitNormal
  135.  
  136. local BloodEffect = nil
  137. if target:GetMaterialType() == 70 || target:GetMaterialType() == 66 then
  138. util.Decal("Blood", todecal1, todecal2)
  139. local effect = EffectData()
  140. local origin = dmginfo:GetDamagePosition()
  141. effect:SetOrigin( origin )
  142. util.Effect( "bloodimpact", effect )
  143.  
  144. BloodEffect = table.Random(RedBloodEffect)
  145.  
  146. elseif target:GetMaterialType() == 65 || target:GetMaterialType() == 72 then
  147. util.Decal("YellowBlood", todecal1, todecal2)
  148.  
  149. BloodEffect = table.Random(YellowBloodEffect)
  150. end
  151.  
  152. if BloodEffect == nil || !dmginfo:IsBulletDamage() || !TTTGore_RagdollBloodSquirt then return end
  153.  
  154. local BloodTrail = ents.Create( "info_particle_system" )
  155. BloodTrail:SetKeyValue( "effect_name", BloodEffect )
  156. BloodTrail:SetKeyValue( "start_active", tostring( 1 ) )
  157. BloodTrail:SetPos( dmginfo:GetDamagePosition() )
  158.  
  159. local AngleMark = target:GetPos() - dmginfo:GetAttacker():GetPos()
  160. AngleMark = AngleMark:Angle()
  161. AngleMark.p = -100
  162.  
  163. BloodTrail:SetAngles( AngleMark )
  164. BloodTrail:SetParent(target)
  165. BloodTrail:Spawn()
  166. BloodTrail:Activate()
  167. BloodTrail:Fire( "Kill", nil, 1 )
  168.  
  169. end
  170.  
  171. end)
  172.  
  173. function TTTGoreEmitBlood(rag, i, bone)
  174. timer.Create( "GoreBlood_"..tostring(rag)..tostring(i), 0.1, TTTGore_BloodMissingLimbDuration, function()
  175. if !IsValid(rag) then return end
  176. local effect = EffectData()
  177. local origin = rag:GetBonePosition(rag:LookupBone( bone ))
  178. effect:SetOrigin( origin )
  179. util.Effect( "BloodImpact", effect )
  180. end)
  181. end
  182.  
  183. function TTTGoreCreateLimb(rag, ply, limb)
  184. if CLIENT then return end
  185. if TTTGore_SeparateLimbs then
  186. local limbside = string.sub( limb, 1, 1 )
  187.  
  188. local limbragdoll = ents.Create("prop_ragdoll")
  189. if not IsValid(limbragdoll) then return nil end
  190.  
  191. limbragdoll:SetPos(rag:GetPos())
  192. limbragdoll:SetModel(rag:GetModel())
  193. limbragdoll:SetSkin(rag:GetSkin())
  194. for key, value in pairs(rag:GetBodyGroups()) do
  195. limbragdoll:SetBodygroup(value.id, rag:GetBodygroup(value.id))
  196. end
  197. limbragdoll:SetAngles(rag:GetAngles())
  198. limbragdoll:SetColor(rag:GetColor())
  199. limbragdoll:Spawn()
  200. limbragdoll:Activate()
  201.  
  202. local playerColor = ply:GetPlayerColor()
  203. limbragdoll.GetPlayerColor = function()
  204. return playerColor
  205. end
  206.  
  207. local num = limbragdoll:GetPhysicsObjectCount()-1
  208. for i=0, num do
  209. local bone = limbragdoll:GetPhysicsObjectNum(i)
  210. if IsValid(bone) then
  211. local bp, ba = limbragdoll:GetBonePosition(limbragdoll:TranslatePhysBoneToBone(i))
  212. if bp and ba then
  213. bone:SetPos(bp)
  214. bone:SetAngles(ba)
  215. end
  216. bone:SetVelocity(rag:GetVelocity())
  217. end
  218. end
  219.  
  220. local numbones = limbragdoll:GetBoneCount()
  221. for i=1, numbones do
  222. limbragdoll:ManipulateBoneScale( i, Vector(0,0,0) )
  223. end
  224.  
  225. if string.find(limb, "Leg") then
  226.  
  227. limbragdoll:ManipulateBoneScale( limbragdoll:LookupBone( "ValveBiped.Bip01_"..limbside.."_Thigh" ), Vector(1,1,1) )
  228. limbragdoll:ManipulateBoneScale( limbragdoll:LookupBone( "ValveBiped.Bip01_"..limbside.."_Calf" ), Vector(1,1,1) )
  229. limbragdoll:ManipulateBoneScale( limbragdoll:LookupBone( "ValveBiped.Bip01_"..limbside.."_Foot" ), Vector(1,1,1) )
  230. limbragdoll:ManipulateBoneScale( limbragdoll:LookupBone( "ValveBiped.Bip01_"..limbside.."_Toe0" ), Vector(1,1,1) )
  231. TTTGoreEmitBlood(limbragdoll, math.random(9001, 90010), "ValveBiped.Bip01_"..limbside.."_Thigh")
  232. elseif string.find(limb, "Arm") then
  233. limbragdoll:ManipulateBoneScale( limbragdoll:LookupBone( "ValveBiped.Bip01_"..limbside.."_UpperArm" ), Vector(1,1,1) )
  234. limbragdoll:ManipulateBoneScale( limbragdoll:LookupBone( "ValveBiped.Bip01_"..limbside.."_Forearm" ), Vector(1,1,1) )
  235. if limbragdoll:LookupBone( "ValveBiped.Bip01_"..limbside.."_Ulna" ) then
  236. limbragdoll:ManipulateBoneScale( limbragdoll:LookupBone( "ValveBiped.Bip01_"..limbside.."_Ulna" ), Vector(1,1,1) )
  237. end
  238. if limbragdoll:LookupBone( "ValveBiped.Bip01_"..limbside.."_Wrist" ) then
  239. limbragdoll:ManipulateBoneScale( limbragdoll:LookupBone( "ValveBiped.Bip01_"..limbside.."_Wrist" ), Vector(1,1,1) )
  240. end
  241. limbragdoll:ManipulateBoneScale( limbragdoll:LookupBone( "ValveBiped.Bip01_"..limbside.."_Hand" ), Vector(1,1,1) )
  242. TTTGoreEmitBlood(limbragdoll, math.random(9001, 90010), "ValveBiped.Bip01_"..limbside.."_UpperArm")
  243. end
  244.  
  245. end
  246. end
  247.  
  248. function TTTGoreCreateGib(path,vector,angle,victim)
  249. if CLIENT then return end
  250. local ent = ents.Create("prop_physics")
  251. ent:SetPos(vector)
  252. ent:SetModel(path)
  253. ent:SetAngles(angle)
  254. ent:SetSkin(victim:GetSkin())
  255. ent:SetMaterial(victim:GetMaterial())
  256. ent:Spawn()
  257.  
  258. local phys = ent:GetPhysicsObject()
  259. if ( !IsValid( phys ) ) then ent:Remove() return end
  260. phys:ApplyForceCenter( Vector( math.random(-200,200), math.random(-200,200), 100 ) )
  261.  
  262. local num = math.Rand(1,3)
  263. for i = 0.1, num, 0.1 do
  264. timer.Simple(i,function()
  265. if !IsValid(ent) then return end
  266. local effectdata = EffectData()
  267. effectdata:SetOrigin( ent:GetPos() )
  268. util.Effect( "BloodImpact", effectdata )
  269. end)
  270. end
  271. if victim:IsOnFire() then ent:Ignite(math.Rand(6, 8), 0) end
  272. local color = Color( 105, 0, 0, 255 )
  273. local trail = util.SpriteTrail(ent, 0, color, false, 7, 1, 1, 1/(15+1)*0.5, "effects/bloodstream.vmt")
  274.  
  275. ent:SetCollisionGroup(COLLISION_GROUP_WEAPON or COLLISION_GROUP_DEBRIS_TRIGGER)
  276. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement