Skip to content

Commit

Permalink
Hook: Added hook "TTT2PlayDeathScream" for deathscreams (#1668)
Browse files Browse the repository at this point in the history
This hook allows to change the sound of the deathscream or cancel it
outright.

Maybe I'm mistaken but I thought the table approach would be the most
appropriate one here. Please correct me if not.


Changelog will follow when this is done.
  • Loading branch information
NickCloudAT authored Jan 3, 2025
1 parent 986aac9 commit 880ac92
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Added Korean translation (by @Kojap)
- Added diagnostic information to the addonchecker output.
- This also includes a Garry's Mod version check which triggers a warning if TTT2 is not compatible. First baseline version is '240313' (by @NickCloudAT)
- Added `GM:TTT2PlayDeathScream` hook to cancel or overwrite/change the deathscream sound that plays, when you die (by @NickCloudAT)
- Added support for "toggle_zoom" binds to trigger the radio commands menu (by @TW1STaL1CKY)

### Fixed
Expand Down
41 changes: 30 additions & 11 deletions gamemodes/terrortown/gamemode/server/sv_player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,23 @@ local deathsounds = {
}
local deathsounds_count = #deathsounds

local function PlayDeathSound(victim)
local function PlayDeathSound(victim, isSilent)
if not IsValid(victim) then
return
end

sound.Play(deathsounds[math.random(deathsounds_count)], victim:GetShootPos(), 90, 100)
local tbl = {
victim = victim,
sound = deathsounds[math.random(deathsounds_count)],
}

---
-- @realm server
if hook.Run("TTT2PlayDeathScream", tbl, isSilent) == false then
return
end

sound.Play(tbl["sound"], victim:GetShootPos(), 90, 100)
end

---
Expand Down Expand Up @@ -786,16 +797,13 @@ function GM:DoPlayerDeath(ply, attacker, dmginfo)

local killwep = util.WeaponFromDamage(dmginfo)

-- headshots, knife damage, and weapons tagged as silent all prevent death
-- sound from occurring
---@cast killwep -nil
if
not ply.was_headshot
and not dmginfo:IsDamageType(DMG_SLASH)
and not (IsValid(killwep) and killwep.IsSilent)
then
PlayDeathSound(ply)
end
PlayDeathSound(
ply,
ply.was_headshot
or dmginfo:IsDamageType(DMG_SLASH)
or (IsValid(killwep) and killwep.IsSilent)
)

credits.HandleKillCreditsAward(ply, attacker)
end
Expand Down Expand Up @@ -1651,6 +1659,17 @@ function GM:TTT2ShouldSkipHaste(victim, attacker) end
-- @realm server
function GM:TTT2PostPlayerDeath(victim, inflictor, attacker) end

---
-- Use this hook to change/cancel the deathscream sound.
-- @param table Table containing all data for the deathscream (victim, sound, isSilent).
-- @param boolean isSilent If this is true, the deathscream will be silenced.
-- @return[default=true] nil|boolean Return false to suppress the deathscream.
-- @hook
-- @realm server
function GM:TTT2PlayDeathScream(tbl, isSilent)
return not isSilent
end

---
-- Returns whether PVP is allowed
-- @return boolean
Expand Down

0 comments on commit 880ac92

Please sign in to comment.