From 7fc35dc7d63a2b5873d4c0637275a32bd2c7cdeb Mon Sep 17 00:00:00 2001 From: Spanospy Date: Sat, 9 Mar 2024 17:47:06 +0000 Subject: [PATCH 1/4] Bugfix: fixed TTT2GiveFoundCredits hook run --- lua/ttt2/libraries/bodysearch.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/ttt2/libraries/bodysearch.lua b/lua/ttt2/libraries/bodysearch.lua index 7abb8e5cd8..29698f4e95 100644 --- a/lua/ttt2/libraries/bodysearch.lua +++ b/lua/ttt2/libraries/bodysearch.lua @@ -83,7 +83,7 @@ function bodysearch.CanTakeCredits(ply, rag, isLongRange) --- -- @realm shared -- stylua: ignore - if hook.Run("TTT2CheckFindCredits", ply, rag) == false then + if hook.Run("TTT2GiveFoundCredits", ply, rag) == false then return false end From 71ae60d31d0d3a4d28e05e30dfbaf40dfc727d7a Mon Sep 17 00:00:00 2001 From: Spanospy Date: Sat, 9 Mar 2024 19:38:33 +0000 Subject: [PATCH 2/4] TTT2CanTakeCredits --- CHANGELOG.md | 2 ++ gamemodes/terrortown/gamemode/server/sv_player.lua | 14 ++++++++++++-- lua/ttt2/libraries/bodysearch.lua | 12 +++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 030e195668..aad22677b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Added sounds to multiple UI interactions (can be disabled in settings: Gameplay > Client-Sounds) - Added a globally audible sound when searching a body - Added the option to add a subtitle to a marker vision element +- Added `TTT2CanTakeCredits` hook for overriding whether a player is allowed to take credits from a given corpse. (by @Spanospy) ### Changed @@ -25,6 +26,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Hides item settings in the equipment editor that are only relevant for weapons - The binoculars now use the default crosshair as well - The ConVar "ttt_debug_preventwin" will now also prevent the time limit from ending the round (by @NickCloudAT) +- `TTT2GiveFoundCredits` hook is no longer called when checking whether a player is allowed to take credits from a given corpse. (by @Spanospy) ### Fixed diff --git a/gamemodes/terrortown/gamemode/server/sv_player.lua b/gamemodes/terrortown/gamemode/server/sv_player.lua index 0e5ea5fead..0cc9f46426 100644 --- a/gamemodes/terrortown/gamemode/server/sv_player.lua +++ b/gamemodes/terrortown/gamemode/server/sv_player.lua @@ -1626,10 +1626,20 @@ end function GM:TTT2CheckCreditAward(victim, attacker) end --- --- Use this hook to prevent the transfer of credits from a body to a player. +-- Use this hook to override whether a given player is allowed to take credits from a given corpse. +-- @param Player ply The player that tries to take credits +-- @param Entity rag The ragdoll where the credits should be taken from +-- @param[default=false] isLongRange Whether the search is a long range search +-- @return nil|boolean Return true/false to override if the player is able to take credits +-- @hook +-- @realm server +function GM:TTT2CanTakeCredits(ply, rag, isLongRange) end + +--- +-- Use this hook to prevent or override the transfer of credits from a corpse to a player. -- @param Entity rag The ragdoll that is inspected -- @param Player ply The @{Player} attempting to find credits from ragdoll --- @return nil|boolean Return false to prevent transfer +-- @return nil|boolean Return false to prevent normal transfer -- @hook -- @realm server function GM:TTT2GiveFoundCredits(ply, rag) end diff --git a/lua/ttt2/libraries/bodysearch.lua b/lua/ttt2/libraries/bodysearch.lua index 29698f4e95..9d3108bb29 100644 --- a/lua/ttt2/libraries/bodysearch.lua +++ b/lua/ttt2/libraries/bodysearch.lua @@ -74,7 +74,7 @@ end --- -- Checks if a given player is allowed to take credits from a given corpse- --- @param Payer ply The player that tries to take credits +-- @param Player ply The player that tries to take credits -- @param Entity rag The ragdoll where the credits should be taken from -- @param[default=false] isLongRange Whether the search is a long range search -- @return boolean Returns if the player is able to take credits @@ -83,8 +83,10 @@ function bodysearch.CanTakeCredits(ply, rag, isLongRange) --- -- @realm shared -- stylua: ignore - if hook.Run("TTT2GiveFoundCredits", ply, rag) == false then - return false + + local hookOverride = hook.Run("TTT2CanTakeCredits", ply, rag, isLongRange) + if hookOverride != nil then + return hookOverride end local credits = CORPSE.GetCredits(rag, 0) @@ -200,6 +202,10 @@ if SERVER then return end + if hook.Run("TTT2GiveFoundCredits", ply, rag) == false then + return false + end + local corpseNick = CORPSE.GetPlayerNick(rag) local credits = CORPSE.GetCredits(rag, 0) From 96cdacad85f42f94379fd8f2cdc1d7adfd910521 Mon Sep 17 00:00:00 2001 From: Spanospy Date: Sat, 9 Mar 2024 20:47:23 +0000 Subject: [PATCH 3/4] Lint fixing --- lua/ttt2/libraries/bodysearch.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lua/ttt2/libraries/bodysearch.lua b/lua/ttt2/libraries/bodysearch.lua index 9d3108bb29..eb35d49512 100644 --- a/lua/ttt2/libraries/bodysearch.lua +++ b/lua/ttt2/libraries/bodysearch.lua @@ -84,8 +84,8 @@ function bodysearch.CanTakeCredits(ply, rag, isLongRange) -- @realm shared -- stylua: ignore - local hookOverride = hook.Run("TTT2CanTakeCredits", ply, rag, isLongRange) - if hookOverride != nil then + local hookOverride = hook.Run("TTT2CanTakeCredits", ply, rag, isLongRange) + if hookOverride ~= nil then return hookOverride end @@ -202,9 +202,9 @@ if SERVER then return end - if hook.Run("TTT2GiveFoundCredits", ply, rag) == false then - return false - end + if hook.Run("TTT2GiveFoundCredits", ply, rag) == false then + return false + end local corpseNick = CORPSE.GetPlayerNick(rag) local credits = CORPSE.GetCredits(rag, 0) From 8ae6ad3e9621b2e354404b1022544aca7d06d2c4 Mon Sep 17 00:00:00 2001 From: Spanospy Date: Sat, 9 Mar 2024 20:50:24 +0000 Subject: [PATCH 4/4] Stylua fixes --- lua/ttt2/libraries/bodysearch.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/ttt2/libraries/bodysearch.lua b/lua/ttt2/libraries/bodysearch.lua index eb35d49512..b4b7daeebc 100644 --- a/lua/ttt2/libraries/bodysearch.lua +++ b/lua/ttt2/libraries/bodysearch.lua @@ -83,7 +83,6 @@ function bodysearch.CanTakeCredits(ply, rag, isLongRange) --- -- @realm shared -- stylua: ignore - local hookOverride = hook.Run("TTT2CanTakeCredits", ply, rag, isLongRange) if hookOverride ~= nil then return hookOverride @@ -202,6 +201,9 @@ if SERVER then return end + --- + -- @realm shared + -- stylua: ignore if hook.Run("TTT2GiveFoundCredits", ply, rag) == false then return false end