Skip to content

Commit

Permalink
bodysearch: TTT2GiveFoundCredits bugfix & new TTT2CanTakeCredits hook (
Browse files Browse the repository at this point in the history
…#1479)

Noticed in 9cff5af that the hook run got re-added with the old name!

Used this opportunity to re-evaluate the hook, too. Decided to split it
so that the original intention of the hook is intact whilst enabling the
ability to handle the side effects of the hook.
  • Loading branch information
Histalek authored Mar 27, 2024
2 parents 378537e + 4723236 commit 7f9390b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -26,6 +27,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- The binoculars now use the default crosshair as well
- Tracers are now drawn for every shot/pellet instead of only 25% of shots/pellets
- 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)
- Micro optimizations
- switched from `player.GetAll()` to `select(2, player.Iterator())`
- use `net.ReadPlayer` / `net.WritePlayer` if applicable instead of `net.Read|WriteEntity`
Expand Down
14 changes: 12 additions & 2 deletions gamemodes/terrortown/gamemode/server/sv_player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1627,10 +1627,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
Expand Down
14 changes: 11 additions & 3 deletions lua/ttt2/libraries/bodysearch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -83,8 +83,9 @@ function bodysearch.CanTakeCredits(ply, rag, isLongRange)
---
-- @realm shared
-- stylua: ignore
if hook.Run("TTT2CheckFindCredits", 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)
Expand Down Expand Up @@ -200,6 +201,13 @@ if SERVER then
return
end

---
-- @realm shared
-- stylua: ignore
if hook.Run("TTT2GiveFoundCredits", ply, rag) == false then
return false
end

local corpseNick = CORPSE.GetPlayerNick(rag)
local credits = CORPSE.GetCredits(rag, 0)

Expand Down

0 comments on commit 7f9390b

Please sign in to comment.