Skip to content

Commit

Permalink
vFire: Improved Integration (#1549)
Browse files Browse the repository at this point in the history
With TTT2 v0.13.0 we started supporting vFire in TTT2. This pullrequest
improves the integration by reworking the game effects function to use
the vFire particles when vFire is installed. I added a `0.5` modifier to
the vFire fire particles as they were quite large and almost
overwhelming. Now they are more tuned to TTT2. However I doubled the
damage ticks so it more closely matches that of normal TTT.

This PR also adds a hook replacement to the vFire explosion handling
reported in #1478. The issue here is that it was applied to all
entities, but it shouldn't be applied to players. I couldn't really test
this one as I was unable to reproduce the issue due to loading order.
See the issue for more details.

Also maybe it is a good idea if @EntranceJew could take a look at this
as well because he worked more with vFire than I did.

vFire docs:
https://docs.google.com/document/d/1GbSrWMqJYI0f4pP0pYBiG2TsKUCXifQLjCqC0qHA9a0/edit
  • Loading branch information
TimGoll authored Aug 17, 2024
1 parent 8068f21 commit dad1262
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Added `admin.IsAdmin(ply)` as a wrapper that automatically calls `GM:TTT2AdminCheck` (by @TimGoll)
- Made sure this new function is used in our whole codebase for all admin checks
- Added `ENTITY:IsPlayerRagdoll` to check if a corpse is a real player ragdoll (by @TimGoll)
- Added improved vFire integration for everything in TTT2 that spawns fire (by @TimGoll and @EntranceJew)
- Added the `SWEP.DryFireSound` field to the weapon base to allow the dryfire sound to be easily changed (by @TW1STaL1CKY)
- Added role derandomization options for perceptually fairer role distribution

Expand Down Expand Up @@ -90,6 +91,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Fixed weapon dryfire sound interrupting the weapon's gunshot sound (by @TW1STaL1CKY)
- Fixed incendiaries sometimes exploding without fire (by @TimGoll)
- Fixed scoreboard not showing any body search info on players that changed to forced spec during a round (by @TimGoll)
- Fixed vFire explosions killing a player even if they have `NoExplosionDamage` equipped (by @TimGoll)
- Fixed a nil error in the PreDrop function in weapon_ttt_cse (by @mexikoedi)
- Fixed `table.FullCopy(tbl)` behaviour when `tbl` contained a Vector or Angle (by @Histalek)
- Fixed the bodysearch showing a wrong player icon when searching a fake body (by @TimGoll)
Expand Down
52 changes: 52 additions & 0 deletions lua/ttt2/libraries/game_effects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ function gameEffects.StartFires(
local vstart = pos + tr.HitNormal * 64
local ttl = lifetime + math.Rand(-lifetimeVariance, lifetimeVariance)

if vFireInstalled then
flames[#flames + 1] = CreateVFireBall(
ttl,
0.5 * size,
vstart,
0.5 * ang:Forward() * forceSpread,
dmgowner
)

continue
end

local flame = ents.Create("ttt_flame")
flame:SetPos(vstart)
flame:SetFlameSize(size)
Expand Down Expand Up @@ -135,3 +147,43 @@ function gameEffects.RadiusDamage(dmginfo, pos, radius, inflictor)
end
end
end

-- vFIRE INTEGRATION

if SERVER then
-- This is a replacement hook for the explosion damage hook in vFire. The difference here is
-- that it is only applied if the damage is for non-player entities.
--
-- original doc: Fix fire dependent entities' behaviors, for instance:
-- Explosive barrels rely on being ignited to explode after damaged by an explosion themselves
-- Because vFire removes default fires, we need to encourage more chain explosions
local function vFireTakeDamageReplacement(ent, dmg)
---
-- @realm server
-- stylua: ignore
if hook.Run("vFireSuppressExplosionBehavior") then
return
end

if not IsValid(ent) or not ent:IsPlayer() or not dmg:IsExplosionDamage() then
return
end

local hp = ent:Health()
if hp < dmg:GetDamage() and hp > 0 and math.random(1, 3) == 1 then
ent:SetHealth(0)
end
end

hook.Add("TTT2FinishedLoading", "TTT2TweakvFire", function()
if not vFireInstalled then
return
end

-- increase the think rate of fires to increase the damage dealt by fire
vFireBurnThinkTickRate = 0.75

hook.Remove("EntityTakeDamage", "vFireFixExplosion")
hook.Add("EntityTakeDamage", "vFireFixExplosionReplacement", vFireTakeDamageReplacement)
end)
end

0 comments on commit dad1262

Please sign in to comment.