From 304df8a55dbaecebc5e7bc356b86bb8392b9fe4e Mon Sep 17 00:00:00 2001 From: march <106459595+marchc1@users.noreply.github.com> Date: Mon, 2 Sep 2024 22:38:42 -0700 Subject: [PATCH 1/3] Make players die funnier --- lua/acf/damage/damage_sv.lua | 44 +++++++++++++++++++++++++++++- lua/acf/damage/overpressure_sv.lua | 11 ++++++-- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/lua/acf/damage/damage_sv.lua b/lua/acf/damage/damage_sv.lua index 2dfe27aa2..2c28827b1 100644 --- a/lua/acf/damage/damage_sv.lua +++ b/lua/acf/damage/damage_sv.lua @@ -40,6 +40,45 @@ function Damage.getBulletDamage(Bullet, Trace) return DmgResult, DmgInfo end + +util.AddNetworkString("ACF_SquishyKill") + +--- Used to kill and fling the player because it's funny. +--- Returns true if the damage has killed the player, false if it has not. +function Damage.doSquishyFlingKill(Entity, Damage, HitPos, Attacker, Inflictor, Direction, Explosive) + local Health = Entity:Health() + + if Damage > Health then + local SourceDamage = DamageInfo() + SourceDamage:SetAttacker(Attacker) + SourceDamage:SetInflictor(Inflictor) + SourceDamage:SetDamage(Damage) + SourceDamage:SetDamageForce(Direction * 200000000) + if Explosive then + SourceDamage:SetDamageType(DMG_BLAST) + end + Entity:TakeDamageInfo(SourceDamage) + + local E1 = EffectData() + E1:SetOrigin(HitPos) + E1:SetNormal(Direction) + E1:SetFlags(3) + E1:SetScale(14) + util.Effect("bloodspray", E1, true, true) + + local E2 = EffectData() + E2:SetOrigin(HitPos) + E2:SetNormal(Direction) + E2:SetFlags(3) + E2:SetScale(14) + util.Effect("BloodImpact", E2, true, true) + + return true + end + + return false +end + --- Used to inflict damage to any entity that was tagged as "Squishy" by ACF.Check. -- This function will be internally used by ACF.Damage.dealDamage, you're not expected to use it. -- @param Entity The entity that will get damaged. @@ -78,8 +117,11 @@ function Damage.doSquishyDamage(Entity, DmgResult, DmgInfo) end end - Entity:TakeDamage(Damage, DmgInfo:GetAttacker(), DmgInfo:GetInflictor()) + local Attacker, Inflictor = DmgInfo:GetAttacker(), DmgInfo:GetInflictor() + if not ACF.Damage.doSquishyFlingKill(Entity, Damage, DmgInfo.HitPos, Attacker, Inflictor, (DmgInfo.HitPos - DmgInfo.Origin):GetNormalized(), DmgInfo.Type == DMG_BLAST) then + Entity:TakeDamage(Damage, Attacker, Inflictor) + end HitRes.Kill = false return HitRes diff --git a/lua/acf/damage/overpressure_sv.lua b/lua/acf/damage/overpressure_sv.lua index ef885407f..a4d5045cb 100644 --- a/lua/acf/damage/overpressure_sv.lua +++ b/lua/acf/damage/overpressure_sv.lua @@ -45,8 +45,9 @@ function ACF.Overpressure(Origin, Energy, Inflictor, Source, Forward, Angle) for V in pairs(Squishies) do local Position = V:EyePos() + local Direction = (Position - Origin):GetNormalized() - if math.acos(Forward:Dot((Position - Origin):GetNormalized())) < Angle then + if math.acos(Forward:Dot(Direction)) < Angle then local D = Position:Distance(Origin) if D / 39.37 <= Radius then @@ -56,7 +57,9 @@ function ACF.Overpressure(Origin, Energy, Inflictor, Source, Forward, Angle) if CanSee(V, Data) then local Damage = Energy * 175000 * (1 / D^3) - V:TakeDamage(Damage, Inflictor, Source) + if not ACF.Damage.doSquishyFlingKill(V, Damage, V:GetPos() + Vector(0, 0, 30), Inflictor, Source, Direction, true) then + V:TakeDamage(Damage, Inflictor, Source) + end end end end @@ -75,7 +78,9 @@ function ACF.Overpressure(Origin, Energy, Inflictor, Source, Forward, Angle) if CanSee(V, Data) then local Damage = Energy * 150000 * (1 / D^3) - V:TakeDamage(Damage, Inflictor, Source) + if not ACF.Damage.doSquishyFlingKill(V, Damage, V:GetPos() + Vector(0, 0, 30), Inflictor, Source, (Source:GetPos() - V:GetPos()):GetNormalized(), true) then + V:TakeDamage(Damage, Inflictor, Source) + end end end end From 854b9d413e527e7eea94ce0e1a48b02b244e2540 Mon Sep 17 00:00:00 2001 From: march <106459595+marchc1@users.noreply.github.com> Date: Mon, 2 Sep 2024 22:38:54 -0700 Subject: [PATCH 2/3] Remove this --- lua/acf/damage/damage_sv.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/lua/acf/damage/damage_sv.lua b/lua/acf/damage/damage_sv.lua index 2c28827b1..bc11b97ba 100644 --- a/lua/acf/damage/damage_sv.lua +++ b/lua/acf/damage/damage_sv.lua @@ -41,8 +41,6 @@ function Damage.getBulletDamage(Bullet, Trace) return DmgResult, DmgInfo end -util.AddNetworkString("ACF_SquishyKill") - --- Used to kill and fling the player because it's funny. --- Returns true if the damage has killed the player, false if it has not. function Damage.doSquishyFlingKill(Entity, Damage, HitPos, Attacker, Inflictor, Direction, Explosive) From bf1d40d6b37aedfa1ab13ef5837baf0985241919 Mon Sep 17 00:00:00 2001 From: thecraftianman <64441307+thecraftianman@users.noreply.github.com> Date: Thu, 14 Nov 2024 00:22:32 -0500 Subject: [PATCH 3/3] Add docs + lower force multiplier --- lua/acf/damage/damage_sv.lua | 42 ++++++++++++++++++------------ lua/acf/damage/overpressure_sv.lua | 7 ++--- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/lua/acf/damage/damage_sv.lua b/lua/acf/damage/damage_sv.lua index f67872d6d..7e0cb4865 100644 --- a/lua/acf/damage/damage_sv.lua +++ b/lua/acf/damage/damage_sv.lua @@ -1,6 +1,7 @@ local ACF = ACF local Damage = ACF.Damage local Objects = Damage.Objects +local Effects = ACF.Utilities.Effects local Queue = {} util.AddNetworkString("ACF_Damage") @@ -87,34 +88,41 @@ function Damage.getBulletDamage(Bullet, Trace) end --- Used to kill and fling the player because it's funny. ---- Returns true if the damage has killed the player, false if it has not. -function Damage.doSquishyFlingKill(Entity, Damage, HitPos, Attacker, Inflictor, Direction, Explosive) +--- @param Entity entity The entity to attempt to kill +--- @param Damage number The amount of damage to be dealt to the entity +--- @param HitPos vector The world position to display blood effects at +--- @param Attacker entity The entity that dealt the damage +--- @param Inflictor entity The entity that was used to deal the damage +--- @param Direction vector The normalized direction that the damage is pointing towards +--- @param Explosive boolean Whether this damage should be explosive or not +--- @return boolean # Returns true if the damage has killed the player, false if it has not +function Damage.DoSquishyFlingKill(Entity, Damage, HitPos, Attacker, Inflictor, Direction, Explosive) + if not Entity:IsPlayer() and not Entity:IsNPC() and not Entity:IsNextBot() then return false end + local Health = Entity:Health() if Damage > Health then local SourceDamage = DamageInfo() + local ForceMult = 25000 -- Arbitrary force multiplier; just change this to whatever feels the best + SourceDamage:SetAttacker(Attacker) SourceDamage:SetInflictor(Inflictor) SourceDamage:SetDamage(Damage) - SourceDamage:SetDamageForce(Direction * 200000000) + SourceDamage:SetDamageForce(Direction * ForceMult) if Explosive then SourceDamage:SetDamageType(DMG_BLAST) end Entity:TakeDamageInfo(SourceDamage) - local E1 = EffectData() - E1:SetOrigin(HitPos) - E1:SetNormal(Direction) - E1:SetFlags(3) - E1:SetScale(14) - util.Effect("bloodspray", E1, true, true) + local EffectTable = { + Origin = HitPos, + Normal = Direction, + Flags = 3, + Scale = 14, + } - local E2 = EffectData() - E2:SetOrigin(HitPos) - E2:SetNormal(Direction) - E2:SetFlags(3) - E2:SetScale(14) - util.Effect("BloodImpact", E2, true, true) + Effects.CreateEffect("bloodspray", EffectTable, true, true) + Effects.CreateEffect("BloodImpact", EffectTable, true, true) return true end @@ -161,10 +169,12 @@ function Damage.doSquishyDamage(Entity, DmgResult, DmgInfo) end local Attacker, Inflictor = DmgInfo:GetAttacker(), DmgInfo:GetInflictor() + local Direction = (DmgInfo.HitPos - DmgInfo.Origin):GetNormalized() - if not ACF.Damage.doSquishyFlingKill(Entity, Damage, DmgInfo.HitPos, Attacker, Inflictor, (DmgInfo.HitPos - DmgInfo.Origin):GetNormalized(), DmgInfo.Type == DMG_BLAST) then + if not ACF.Damage.DoSquishyFlingKill(Entity, Damage, DmgInfo.HitPos, Attacker, Inflictor, Direction, DmgInfo.Type == DMG_BLAST) then Entity:TakeDamage(Damage, Attacker, Inflictor) end + HitRes.Kill = false return HitRes diff --git a/lua/acf/damage/overpressure_sv.lua b/lua/acf/damage/overpressure_sv.lua index a4d5045cb..1d5719458 100644 --- a/lua/acf/damage/overpressure_sv.lua +++ b/lua/acf/damage/overpressure_sv.lua @@ -5,7 +5,7 @@ local ACF = ACF ACF.Squishies = ACF.Squishies or {} local Squishies = ACF.Squishies - +local HitPosOffset = Vector(0, 0, 30) -- InVehicle and GetVehicle are only for players, we have NPCs too! local function GetVehicle(Entity) @@ -57,7 +57,7 @@ function ACF.Overpressure(Origin, Energy, Inflictor, Source, Forward, Angle) if CanSee(V, Data) then local Damage = Energy * 175000 * (1 / D^3) - if not ACF.Damage.doSquishyFlingKill(V, Damage, V:GetPos() + Vector(0, 0, 30), Inflictor, Source, Direction, true) then + if not ACF.Damage.DoSquishyFlingKill(V, Damage, V:GetPos() + HitPosOffset, Inflictor, Source, Direction, true) then V:TakeDamage(Damage, Inflictor, Source) end end @@ -77,8 +77,9 @@ function ACF.Overpressure(Origin, Energy, Inflictor, Source, Forward, Angle) if CanSee(V, Data) then local Damage = Energy * 150000 * (1 / D^3) + local Direction = (Source:GetPos() - V:GetPos()):GetNormalized() - if not ACF.Damage.doSquishyFlingKill(V, Damage, V:GetPos() + Vector(0, 0, 30), Inflictor, Source, (Source:GetPos() - V:GetPos()):GetNormalized(), true) then + if not ACF.Damage.DoSquishyFlingKill(V, Damage, V:GetPos() + HitPosOffset, Inflictor, Source, Direction, true) then V:TakeDamage(Damage, Inflictor, Source) end end