Skip to content

Commit 5413e42

Browse files
wgetJaneTimGoll
andauthored
Let TTTLastWordsMsg hook override default behaviour (#1784)
from Facepunch/garrysmod#2227 --------- Co-authored-by: Tim Goll <github@timgoll.de>
1 parent b5b7ec1 commit 5413e42

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
99
- Added C4 cvars for adjusting the range & falloff of C4 explosions (by @Spanospy)
1010
- C4 explosions will now also respect the weapon's configured damage scaling
1111
- Added option to select preferred unit of length for distance displays (by @wgetJane)
12+
- Added `GM:TTTLastWordsMsg` hook from base TTT (Facepunch/garrysmod/pull/2227, by @wgetJane)
1213
- Port new TTT entity ttt_filter_role to TTT2 (Facepunch/garrysmod/pull/2225 by @figardo, ported by @wgetJane)
1314

1415
### Changed

gamemodes/terrortown/gamemode/server/sv_gamemsg.lua

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,16 @@ local function LastWordsMsg(ply, words)
426426
-- add optional context relating to death type
427427
local context = LastWordContext[ply.death_type] or ""
428428

429-
net.Start("TTT_LastWordsMsg")
430-
net.WritePlayer(ply)
431-
net.WriteString(words .. (final and "" or "--") .. context)
432-
net.Broadcast()
429+
local lastWordsStr = words .. (final and "" or "--") .. context
430+
431+
---
432+
-- @realm server
433+
if hook.Run("TTTLastWordsMsg", ply, lastWordsStr, words) ~= true then
434+
net.Start("TTT_LastWordsMsg")
435+
net.WritePlayer(ply)
436+
net.WriteString(lastWordsStr)
437+
net.Broadcast()
438+
end
433439
end
434440

435441
local function deathrec(ply, cmd, args)
@@ -552,6 +558,16 @@ concommand.Add("_ttt_radio_send", ttt_radio_send)
552558
-- @realm server
553559
function GM:TTTPlayerRadioCommand(ply, msgName, msgTarget) end
554560

561+
---
562+
-- Called when a player tries to speak their last words on death
563+
-- @param Player ply The player that is sending their last words
564+
-- @param string msg The last words that is about to be sent
565+
-- @param string msgOriginal The original unmodified message
566+
-- @return[default=nil] boolean Return true to block last words
567+
-- @hook
568+
-- @realm server
569+
function GM:TTTLastWordsMsg(ply, msg, msgOriginal) end
570+
555571
---
556572
-- Whether or not the @{Player} can receive the chat message.
557573
-- @param Player reader The @{Player} who can receive chat

0 commit comments

Comments
 (0)