From 0ec8d99a035fcfe8b1f9ecb4d589ce2e1641aff9 Mon Sep 17 00:00:00 2001 From: Konstantin Gitschthaler Date: Wed, 15 Jan 2025 16:03:04 +0100 Subject: [PATCH 01/12] Fixed potential error in new Ammo drop --- CHANGELOG.md | 1 + gamemodes/terrortown/gamemode/server/sv_player_ext.lua | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25b9eaa48..f031cb34e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Fixed the mute button in the scoreboard not working (by @TW1STaL1CKY) - Fixed a few errors in shop error messages (by @Histalek) - Fixed `markerVision`'s registry table being able to contain duplicate obsolete entries, thus fixing potential syncing issues with markers (by @TW1STaL1CKY) +- Fixed issue in new Ammo dropping that could cause an error when dropping for modified weapon bases. (by @MrXonte) ### Changed diff --git a/gamemodes/terrortown/gamemode/server/sv_player_ext.lua b/gamemodes/terrortown/gamemode/server/sv_player_ext.lua index 91b6b9dc1..dfe409f16 100644 --- a/gamemodes/terrortown/gamemode/server/sv_player_ext.lua +++ b/gamemodes/terrortown/gamemode/server/sv_player_ext.lua @@ -1465,7 +1465,7 @@ function plymeta:DropAmmo(wep, useClip, amt) if useClip then amt = wep:Clip1() else - amt = math.min(wep.AmmoEnt.AmmoAmount, self:GetAmmoCount(wep.Primary.Ammo)) + amt = math.min(box.AmmoAmount, self:GetAmmoCount(wep.Primary.Ammo)) end end local hook_data = { amt } From f34152a77a2375d51696fed2ae449e8290feb8b3 Mon Sep 17 00:00:00 2001 From: Konstantin Gitschthaler Date: Tue, 21 Jan 2025 13:17:57 +0100 Subject: [PATCH 02/12] Score Points for Winning Added a win score for winning and a matching LANG entry and score parameter in the role base --- lua/terrortown/entities/roles/ttt_role_base/shared.lua | 5 ++++- lua/terrortown/events/finish.lua | 2 ++ lua/terrortown/lang/de.lua | 2 ++ lua/terrortown/lang/en.lua | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lua/terrortown/entities/roles/ttt_role_base/shared.lua b/lua/terrortown/entities/roles/ttt_role_base/shared.lua index 4beaf9cbb..9013b7be3 100644 --- a/lua/terrortown/entities/roles/ttt_role_base/shared.lua +++ b/lua/terrortown/entities/roles/ttt_role_base/shared.lua @@ -40,9 +40,12 @@ ROLE.score = { -- round ended with nobody winning, usually a negative number. timelimitMultiplier = 0, - -- The amount of points gained by killing yourself. Should be a + -- The amount of score points gained by killing yourself. Should be a -- negative number for most roles. suicideMultiplier = -1, + + -- The amount of score points gained when your team wins. + winMultiplier = 1, } ROLE.karma = { diff --git a/lua/terrortown/events/finish.lua b/lua/terrortown/events/finish.lua index 2cb8bb09f..7702bfffc 100644 --- a/lua/terrortown/events/finish.lua +++ b/lua/terrortown/events/finish.lua @@ -122,6 +122,8 @@ function EVENT:CalculateScore() score_timelimit = wintype == WIN_TIMELIMIT and math.ceil( otherAlivePlayers * roleData.score.timelimitMultiplier ) or 0, + score_win = wintype == team and roleData.score.winMultiplier + or 0, }) end end diff --git a/lua/terrortown/lang/de.lua b/lua/terrortown/lang/de.lua index fd32b6256..763aa67de 100644 --- a/lua/terrortown/lang/de.lua +++ b/lua/terrortown/lang/de.lua @@ -1170,6 +1170,7 @@ L.tooltip_karma_gained = "Karmaänderungen für diese Runde:" L.tooltip_score_gained = "Punkteänderungen für diese Runde:" L.tooltip_roles_time = "Rollenwechsel für diese Runde:" +L.tooltip_finish_score_win = "Gewinner: {score}" L.tooltip_finish_score_alive_teammates = "Lebende Teammitglieder: {score}" L.tooltip_finish_score_alive_all = "Lebende Spieler: {score}" L.tooltip_finish_score_timelimit = "Zeit vorbei: {score}" @@ -1177,6 +1178,7 @@ L.tooltip_finish_score_dead_enemies = "Tote Gegner: {score}" L.tooltip_kill_score = "Mord: {score}" L.tooltip_bodyfound_score = "Leichenfund: {score}" +L.finish_score_win = "Gewinner:" L.finish_score_alive_teammates = "Lebende Teammitglieder:" L.finish_score_alive_all = "Lebende Spieler:" L.finish_score_timelimit = "Zeit vorbei:" diff --git a/lua/terrortown/lang/en.lua b/lua/terrortown/lang/en.lua index f4510e0d6..787c314af 100644 --- a/lua/terrortown/lang/en.lua +++ b/lua/terrortown/lang/en.lua @@ -1170,6 +1170,7 @@ L.tooltip_karma_gained = "Karma changes for this round:" L.tooltip_score_gained = "Score changes for this round:" L.tooltip_roles_time = "Role changes for this round:" +L.tooltip_finish_score_win = "Win: {score}" L.tooltip_finish_score_alive_teammates = "Alive teammates: {score}" L.tooltip_finish_score_alive_all = "Alive players: {score}" L.tooltip_finish_score_timelimit = "Time is up: {score}" @@ -1177,6 +1178,7 @@ L.tooltip_finish_score_dead_enemies = "Dead enemies: {score}" L.tooltip_kill_score = "Kill: {score}" L.tooltip_bodyfound_score = "Body found: {score}" +L.finish_score_win = "Win:" L.finish_score_alive_teammates = "Alive teammates:" L.finish_score_alive_all = "Alive players:" L.finish_score_timelimit = "Time is up:" From 1f93a22ea4e1d46a88ab53a4617087b6df1f83c9 Mon Sep 17 00:00:00 2001 From: Konstantin Gitschthaler Date: Tue, 21 Jan 2025 13:19:37 +0100 Subject: [PATCH 03/12] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 837118037..9fc344ffc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Added support for "toggle_zoom" binds to trigger the radio commands menu (by @TW1STaL1CKY) - Added option to use right click to enable/disable roles in the role layering menu (by @TimGoll) - Added option to enable team name next to role name on the HUD (by @milkwxter) +- Added score event for winning with configurable role parameter (by @MrXonte) ### Fixed From 1aca4d367a472a4b0749b4a8e2b31f060d021165 Mon Sep 17 00:00:00 2001 From: Konstantin Gitschthaler Date: Tue, 21 Jan 2025 13:24:06 +0100 Subject: [PATCH 04/12] appeasing the lint gods --- lua/terrortown/entities/roles/ttt_role_base/shared.lua | 4 ++-- lua/terrortown/events/finish.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/terrortown/entities/roles/ttt_role_base/shared.lua b/lua/terrortown/entities/roles/ttt_role_base/shared.lua index 9013b7be3..b7ec8b605 100644 --- a/lua/terrortown/entities/roles/ttt_role_base/shared.lua +++ b/lua/terrortown/entities/roles/ttt_role_base/shared.lua @@ -44,8 +44,8 @@ ROLE.score = { -- negative number for most roles. suicideMultiplier = -1, - -- The amount of score points gained when your team wins. - winMultiplier = 1, + -- The amount of score points gained when your team wins. + winMultiplier = 1, } ROLE.karma = { diff --git a/lua/terrortown/events/finish.lua b/lua/terrortown/events/finish.lua index 7702bfffc..9f04ba74b 100644 --- a/lua/terrortown/events/finish.lua +++ b/lua/terrortown/events/finish.lua @@ -122,8 +122,8 @@ function EVENT:CalculateScore() score_timelimit = wintype == WIN_TIMELIMIT and math.ceil( otherAlivePlayers * roleData.score.timelimitMultiplier ) or 0, - score_win = wintype == team and roleData.score.winMultiplier - or 0, + score_win = wintype == team and roleData.score.winMultiplier + or 0, }) end end From b73a0f238d5fdce1376d24ff10db6ee30e50c84d Mon Sep 17 00:00:00 2001 From: Konstantin Gitschthaler Date: Tue, 21 Jan 2025 13:27:30 +0100 Subject: [PATCH 05/12] appeasing the style gods --- lua/terrortown/events/finish.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/terrortown/events/finish.lua b/lua/terrortown/events/finish.lua index 9f04ba74b..12d89bf36 100644 --- a/lua/terrortown/events/finish.lua +++ b/lua/terrortown/events/finish.lua @@ -122,8 +122,7 @@ function EVENT:CalculateScore() score_timelimit = wintype == WIN_TIMELIMIT and math.ceil( otherAlivePlayers * roleData.score.timelimitMultiplier ) or 0, - score_win = wintype == team and roleData.score.winMultiplier - or 0, + score_win = wintype == team and roleData.score.winMultiplier or 0, }) end end From e36d39cd49b4be158a1afc799ebe8d5c1c7f1b60 Mon Sep 17 00:00:00 2001 From: Konstantin Gitschthaler Date: Tue, 21 Jan 2025 13:44:14 +0100 Subject: [PATCH 06/12] 3 score default for winning --- lua/terrortown/entities/roles/ttt_role_base/shared.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/terrortown/entities/roles/ttt_role_base/shared.lua b/lua/terrortown/entities/roles/ttt_role_base/shared.lua index b7ec8b605..9d07f01b6 100644 --- a/lua/terrortown/entities/roles/ttt_role_base/shared.lua +++ b/lua/terrortown/entities/roles/ttt_role_base/shared.lua @@ -45,7 +45,7 @@ ROLE.score = { suicideMultiplier = -1, -- The amount of score points gained when your team wins. - winMultiplier = 1, + winMultiplier = 3, } ROLE.karma = { From 868beebc191377380d9e7d921f6281b65cb4ec31 Mon Sep 17 00:00:00 2001 From: Konstantin Gitschthaler Date: Thu, 23 Jan 2025 15:23:45 +0100 Subject: [PATCH 07/12] not need for or due to expected value --- lua/terrortown/events/finish.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/terrortown/events/finish.lua b/lua/terrortown/events/finish.lua index 12d89bf36..547f1371a 100644 --- a/lua/terrortown/events/finish.lua +++ b/lua/terrortown/events/finish.lua @@ -122,7 +122,7 @@ function EVENT:CalculateScore() score_timelimit = wintype == WIN_TIMELIMIT and math.ceil( otherAlivePlayers * roleData.score.timelimitMultiplier ) or 0, - score_win = wintype == team and roleData.score.winMultiplier or 0, + score_win = wintype == team and roleData.score.winMultiplier, }) end end From 1075e2aba8dd31dcecf9b193c7b720056797c182 Mon Sep 17 00:00:00 2001 From: Konstantin Gitschthaler Date: Thu, 23 Jan 2025 17:35:25 +0100 Subject: [PATCH 08/12] C4 Explosion Damage Rework --- .../entities/entities/ttt_c4/shared.lua | 57 +---------------- lua/ttt2/libraries/game_effects.lua | 62 ++++++++++++++++++- 2 files changed, 63 insertions(+), 56 deletions(-) diff --git a/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua b/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua index 0773b41ea..a282e6689 100644 --- a/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua +++ b/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua @@ -145,55 +145,6 @@ function ENT.SafeWiresForTime(t) end end ---- --- @param Entity dmgowner --- @param Vector center --- @param number radius --- @realm shared -function ENT:SphereDamage(dmgowner, center, radius) - -- It seems intuitive to use FindInSphere here, but that will find all ents - -- in the radius, whereas there exist only ~16 players. Hence it is more - -- efficient to cycle through all those players and do a Lua-side distance - -- check. - - local r = radius * radius -- square so we can compare with dot product directly - - -- pre-declare to avoid realloc - local d = 0.0 - local diff = nil - local dmg = 0 - - local plys = playerGetAll() - for i = 1, #plys do - local ply = plys[i] - if ply:Team() ~= TEAM_TERROR then - continue - end - - -- dot of the difference with itself is distance squared - diff = center - ply:GetPos() - d = diff:Dot(diff) - - if d >= r then - continue - end - - -- deadly up to a certain range, then a quick falloff within 100 units - d = math.max(0, math.sqrt(d) - 490) - dmg = -0.01 * (d * d) + 125 - - local dmginfo = DamageInfo() - dmginfo:SetDamage(dmg) - dmginfo:SetAttacker(dmgowner) - dmginfo:SetInflictor(self) - dmginfo:SetDamageType(DMG_BLAST) - dmginfo:SetDamageForce(center - ply:GetPos()) - dmginfo:SetDamagePosition(ply:GetPos()) - - ply:TakeDamageInfo(dmginfo) - end -end - local c4boom = Sound("c4.explode") --- @@ -243,12 +194,8 @@ function ENT:Explode(tr) r_inner = r_inner / 2.5 r_outer = r_outer / 2.5 end - - -- damage through walls - self:SphereDamage(dmgowner, pos, r_inner) - - -- explosion damage - util.BlastDamage(self, dmgowner, pos, r_outer, self:GetDmg()) + + gameEffects.ExplosiveSphereDamage(dmgowner, self, self:GetDmg(), pos, r_outer, r_inner, true) local effect = EffectData() effect:SetStart(pos) diff --git a/lua/ttt2/libraries/game_effects.lua b/lua/ttt2/libraries/game_effects.lua index e76d38f88..2295971e0 100644 --- a/lua/ttt2/libraries/game_effects.lua +++ b/lua/ttt2/libraries/game_effects.lua @@ -148,6 +148,66 @@ function gameEffects.RadiusDamage(dmginfo, pos, radius, inflictor) end end + + +-- Creates explosion damage in a sphere through walls. Very useful for making explosives that aren't line of sight based. +-- @param Player dmgowner The player that causes this explosion. +-- @param Entity source The entity that causes this explosion. +-- @param number damage The maximum damage done by this explosion. +-- @param Vector origin The center of the explosion. +-- @param number outerRadius The outer border for the explosion damage and its falloff. +-- @param number innerRadius The inner border for the explosion damage where falloff starts. +-- @param boolean exponentialFalloff If the damage falloff should be FALSE: Linear, TRUE: exponential. +-- @internal +-- @realm server +function gameEffects.ExplosiveSphereDamage(dmgowner, source, damage, origin, outerRadius, innerRadius, exponentialFalloff) + -- It seems intuitive to use FindInSphere here, but that will find all ents + -- in the radius, whereas there exist only ~16 players. Hence it is more + -- efficient to cycle through all those players and do a Lua-side distance + -- check. + + if outerRadius < innerRadius then + ErrorNoHalt("[Game Effects Explosive Sphere Damage] Outer radius too high! Setting both radi to outer radius.") + innerRadius = outerRadius + end + + -- pre-declare to avoid realloc + local d = 0.0 + local dFraction = 0.0 + local diff = nil + local dmg = 0 + local radiDiff = (outerRadius - innerRadius) + for _, ply in pairs(player.GetAll()) do + if IsValid(ply) and ply:Team() == TEAM_TERROR then + + diff = origin - ply:GetPos() + --we are using Length on purpose here. We would need a sqrt somewhere anyway and with this we dont need to square the radi + d = diff:Length() + --we now turn this into a % of damage based of the value of d + --100% from 0 to innerRadius + --100% to 0% from innerRadius to outerRadius + --<0% from outerRadius to infinity + dFraction = 1.0 - math.max((d - innerRadius) / radiDiff,0.0) + + --Next Iteration if we are outside the radius + if dFraction < 0.0 then + continue + end + + dmg = math.Round(damage * dFraction * ((exponentialFalloff and dFraction) or 1)) + + local dmginfo = DamageInfo() + dmginfo:SetDamage(dmg) + dmginfo:SetAttacker(dmgowner) + dmginfo:SetInflictor(source) + dmginfo:SetDamageType(DMG_BLAST) + dmginfo:SetDamageForce(diff) + dmginfo:SetDamagePosition(ply:GetPos()) + ply:TakeDamageInfo(dmginfo) + end + end +end + -- vFIRE INTEGRATION if SERVER then @@ -185,4 +245,4 @@ if SERVER then hook.Remove("EntityTakeDamage", "vFireFixExplosion") hook.Add("EntityTakeDamage", "vFireFixExplosionReplacement", vFireTakeDamageReplacement) end) -end +end \ No newline at end of file From 6551db81812cb125a65e198328cc8f43567c840c Mon Sep 17 00:00:00 2001 From: Konstantin Gitschthaler Date: Thu, 23 Jan 2025 17:40:48 +0100 Subject: [PATCH 09/12] appeasing the lint gods --- CHANGELOG.md | 2 + .../entities/entities/ttt_c4/shared.lua | 4 +- lua/ttt2/libraries/game_effects.lua | 90 +++++++++---------- 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fc344ffc..772c92862 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Added option to use right click to enable/disable roles in the role layering menu (by @TimGoll) - Added option to enable team name next to role name on the HUD (by @milkwxter) - Added score event for winning with configurable role parameter (by @MrXonte) +- Added ExplosiveSphereDamage game effect for easy calculation of explosion damage through walls (by @MrXonte) ### Fixed @@ -59,6 +60,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Moved all role-related admin options into the "Roles" menu (by @nike4613) - Improved description of role layering (by @nike4613) - Improved the role layering menu by showing which role is enabled and which is disabled (by @TimGoll) +- Reworked C4 damage calculation with new gameEffect ExplosiveSphereDamage (by @MrXonte) ## [v0.14.0b](https://github.com/TTT-2/TTT2/tree/v0.14.0b) (2024-09-20) diff --git a/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua b/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua index a282e6689..d2d4bcc55 100644 --- a/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua +++ b/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua @@ -194,8 +194,8 @@ function ENT:Explode(tr) r_inner = r_inner / 2.5 r_outer = r_outer / 2.5 end - - gameEffects.ExplosiveSphereDamage(dmgowner, self, self:GetDmg(), pos, r_outer, r_inner, true) + + gameEffects.ExplosiveSphereDamage(dmgowner, self, self:GetDmg(), pos, r_outer, r_inner, true) local effect = EffectData() effect:SetStart(pos) diff --git a/lua/ttt2/libraries/game_effects.lua b/lua/ttt2/libraries/game_effects.lua index 2295971e0..d3f90cb2b 100644 --- a/lua/ttt2/libraries/game_effects.lua +++ b/lua/ttt2/libraries/game_effects.lua @@ -161,51 +161,51 @@ end -- @internal -- @realm server function gameEffects.ExplosiveSphereDamage(dmgowner, source, damage, origin, outerRadius, innerRadius, exponentialFalloff) - -- It seems intuitive to use FindInSphere here, but that will find all ents - -- in the radius, whereas there exist only ~16 players. Hence it is more - -- efficient to cycle through all those players and do a Lua-side distance - -- check. - - if outerRadius < innerRadius then - ErrorNoHalt("[Game Effects Explosive Sphere Damage] Outer radius too high! Setting both radi to outer radius.") - innerRadius = outerRadius - end - - -- pre-declare to avoid realloc - local d = 0.0 - local dFraction = 0.0 - local diff = nil - local dmg = 0 - local radiDiff = (outerRadius - innerRadius) - for _, ply in pairs(player.GetAll()) do - if IsValid(ply) and ply:Team() == TEAM_TERROR then - - diff = origin - ply:GetPos() - --we are using Length on purpose here. We would need a sqrt somewhere anyway and with this we dont need to square the radi - d = diff:Length() - --we now turn this into a % of damage based of the value of d - --100% from 0 to innerRadius - --100% to 0% from innerRadius to outerRadius - --<0% from outerRadius to infinity - dFraction = 1.0 - math.max((d - innerRadius) / radiDiff,0.0) - - --Next Iteration if we are outside the radius - if dFraction < 0.0 then - continue - end - - dmg = math.Round(damage * dFraction * ((exponentialFalloff and dFraction) or 1)) - - local dmginfo = DamageInfo() - dmginfo:SetDamage(dmg) - dmginfo:SetAttacker(dmgowner) - dmginfo:SetInflictor(source) - dmginfo:SetDamageType(DMG_BLAST) - dmginfo:SetDamageForce(diff) - dmginfo:SetDamagePosition(ply:GetPos()) - ply:TakeDamageInfo(dmginfo) - end - end + -- It seems intuitive to use FindInSphere here, but that will find all ents + -- in the radius, whereas there exist only ~16 players. Hence it is more + -- efficient to cycle through all those players and do a Lua-side distance + -- check. + + if outerRadius < innerRadius then + ErrorNoHalt("[Game Effects Explosive Sphere Damage] Outer radius too high! Setting both radi to outer radius.") + innerRadius = outerRadius + end + + -- pre-declare to avoid realloc + local d = 0.0 + local dFraction = 0.0 + local diff = nil + local dmg = 0 + local radiDiff = (outerRadius - innerRadius) + for _, ply in pairs(player.GetAll()) do + if IsValid(ply) and ply:Team() == TEAM_TERROR then + + diff = origin - ply:GetPos() + --we are using Length on purpose here. We would need a sqrt somewhere anyway and with this we dont need to square the radi + d = diff:Length() + --we now turn this into a % of damage based of the value of d + --100% from 0 to innerRadius + --100% to 0% from innerRadius to outerRadius + --<0% from outerRadius to infinity + dFraction = 1.0 - math.max((d - innerRadius) / radiDiff,0.0) + + --Next Iteration if we are outside the radius + if dFraction < 0.0 then + continue + end + + dmg = math.Round(damage * dFraction * ((exponentialFalloff and dFraction) or 1)) + + local dmginfo = DamageInfo() + dmginfo:SetDamage(dmg) + dmginfo:SetAttacker(dmgowner) + dmginfo:SetInflictor(source) + dmginfo:SetDamageType(DMG_BLAST) + dmginfo:SetDamageForce(diff) + dmginfo:SetDamagePosition(ply:GetPos()) + ply:TakeDamageInfo(dmginfo) + end + end end -- vFIRE INTEGRATION From b62083333cf40f9a130e0c128a7236af7cb30f62 Mon Sep 17 00:00:00 2001 From: Konstantin Gitschthaler Date: Thu, 23 Jan 2025 17:42:24 +0100 Subject: [PATCH 10/12] more lint --- lua/ttt2/libraries/game_effects.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/ttt2/libraries/game_effects.lua b/lua/ttt2/libraries/game_effects.lua index d3f90cb2b..7d11c442f 100644 --- a/lua/ttt2/libraries/game_effects.lua +++ b/lua/ttt2/libraries/game_effects.lua @@ -190,13 +190,13 @@ function gameEffects.ExplosiveSphereDamage(dmgowner, source, damage, origin, out dFraction = 1.0 - math.max((d - innerRadius) / radiDiff,0.0) --Next Iteration if we are outside the radius - if dFraction < 0.0 then - continue + if dFraction < 0.0 then + continue end dmg = math.Round(damage * dFraction * ((exponentialFalloff and dFraction) or 1)) - local dmginfo = DamageInfo() + local dmginfo = DamageInfo() dmginfo:SetDamage(dmg) dmginfo:SetAttacker(dmgowner) dmginfo:SetInflictor(source) From ff7111502fa7ac03692d6d20e6ac351c645f5a52 Mon Sep 17 00:00:00 2001 From: Konstantin Gitschthaler Date: Thu, 23 Jan 2025 17:46:26 +0100 Subject: [PATCH 11/12] style me up --- .../entities/entities/ttt_c4/shared.lua | 10 +++++++++- lua/ttt2/libraries/game_effects.lua | 19 +++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua b/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua index d2d4bcc55..3ff94ef7b 100644 --- a/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua +++ b/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua @@ -195,7 +195,15 @@ function ENT:Explode(tr) r_outer = r_outer / 2.5 end - gameEffects.ExplosiveSphereDamage(dmgowner, self, self:GetDmg(), pos, r_outer, r_inner, true) + gameEffects.ExplosiveSphereDamage( + dmgowner, + self, + self:GetDmg(), + pos, + r_outer, + r_inner, + true + ) local effect = EffectData() effect:SetStart(pos) diff --git a/lua/ttt2/libraries/game_effects.lua b/lua/ttt2/libraries/game_effects.lua index 7d11c442f..6da9e5acd 100644 --- a/lua/ttt2/libraries/game_effects.lua +++ b/lua/ttt2/libraries/game_effects.lua @@ -148,8 +148,6 @@ function gameEffects.RadiusDamage(dmginfo, pos, radius, inflictor) end end - - -- Creates explosion damage in a sphere through walls. Very useful for making explosives that aren't line of sight based. -- @param Player dmgowner The player that causes this explosion. -- @param Entity source The entity that causes this explosion. @@ -160,14 +158,24 @@ end -- @param boolean exponentialFalloff If the damage falloff should be FALSE: Linear, TRUE: exponential. -- @internal -- @realm server -function gameEffects.ExplosiveSphereDamage(dmgowner, source, damage, origin, outerRadius, innerRadius, exponentialFalloff) +function gameEffects.ExplosiveSphereDamage( + dmgowner, + source, + damage, + origin, + outerRadius, + innerRadius, + exponentialFalloff +) -- It seems intuitive to use FindInSphere here, but that will find all ents -- in the radius, whereas there exist only ~16 players. Hence it is more -- efficient to cycle through all those players and do a Lua-side distance -- check. if outerRadius < innerRadius then - ErrorNoHalt("[Game Effects Explosive Sphere Damage] Outer radius too high! Setting both radi to outer radius.") + ErrorNoHalt( + "[Game Effects Explosive Sphere Damage] Outer radius too high! Setting both radi to outer radius." + ) innerRadius = outerRadius end @@ -179,7 +187,6 @@ function gameEffects.ExplosiveSphereDamage(dmgowner, source, damage, origin, out local radiDiff = (outerRadius - innerRadius) for _, ply in pairs(player.GetAll()) do if IsValid(ply) and ply:Team() == TEAM_TERROR then - diff = origin - ply:GetPos() --we are using Length on purpose here. We would need a sqrt somewhere anyway and with this we dont need to square the radi d = diff:Length() @@ -187,7 +194,7 @@ function gameEffects.ExplosiveSphereDamage(dmgowner, source, damage, origin, out --100% from 0 to innerRadius --100% to 0% from innerRadius to outerRadius --<0% from outerRadius to infinity - dFraction = 1.0 - math.max((d - innerRadius) / radiDiff,0.0) + dFraction = 1.0 - math.max((d - innerRadius) / radiDiff, 0.0) --Next Iteration if we are outside the radius if dFraction < 0.0 then From 773498cb185145811f6fad3c5cfa521d9610c7bc Mon Sep 17 00:00:00 2001 From: Konstantin Gitschthaler Date: Thu, 23 Jan 2025 17:49:14 +0100 Subject: [PATCH 12/12] liiiiiiiiiiiint --- .../entities/entities/ttt_c4/shared.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua b/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua index 3ff94ef7b..4a3853f5b 100644 --- a/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua +++ b/gamemodes/terrortown/entities/entities/ttt_c4/shared.lua @@ -196,14 +196,14 @@ function ENT:Explode(tr) end gameEffects.ExplosiveSphereDamage( - dmgowner, - self, - self:GetDmg(), - pos, - r_outer, - r_inner, - true - ) + dmgowner, + self, + self:GetDmg(), + pos, + r_outer, + r_inner, + true + ) local effect = EffectData() effect:SetStart(pos)