Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook: Added hook "TTT2PlayDeathScream" for deathscreams #1668

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

### Fixed

Expand Down
34 changes: 23 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,19 @@
}
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)],
}

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

Check failure on line 685 in gamemodes/terrortown/gamemode/server/sv_player.lua

View workflow job for this annotation

GitHub Actions / doc-check

Missing essential param --> "Missing '@realm' in hook 'GM:TTT2PlayDeathScream'"

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

---
Expand Down Expand Up @@ -786,16 +793,10 @@

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 +1652,17 @@
-- @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
Loading