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

Credits/Shop: Add hooks for credit related events. #1451

Merged
merged 16 commits into from
Aug 21, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Added the option to assign random unique models at round start (by @Exonen2)
- Added a new voice chat UI (by @TimGoll)
- Added `TTT2CanTakeCredits` hook for overriding whether a player is allowed to take credits from a given corpse. (by @Spanospy)
- Added `GM:TTT2OnGiveFoundCredits()` hook which is called when a player has been given credits for searching a corpse.
- Added `GM:TTT2OnReceiveKillCredits()` hook which is called when a player recieves credits for a kill.
- Added `GM:TTT2OnReceiveTeamAwardCredits()` hook which is called when a player recieves credits as a team award.
- Added `GM:TTT2OnTransferCredits()` hook which is called when a player has successfully transfered a credit to another player.
- Disabled locational voice during the preparing phase by default
- Added a ConVar `ttt_locational_voice_prep` to reenable it
- Added `SWEP.EnableConfigurableClip` and `SWEP.ConfigurableClip` to set the weapon's clip on buy via the equipment editor (by @TimGoll)
Expand Down
17 changes: 17 additions & 0 deletions gamemodes/terrortown/gamemode/server/sv_player_ext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1919,3 +1919,20 @@ function GM:TTT2SetDefaultCredits(ply) end
-- @hook
-- @realm server
function GM:TTT2ModifyDefaultTraitorCredits(ply, credits) end

---
-- Hook that is called when a player recieves credits for a kill.
-- @param Player ply The player who killed another player
-- @param Player victim The player who was killed
-- @param number credits The amount of credits the player received
-- @hook
-- @realm server
function GM:TTT2OnReceiveKillCredits(ply, victim, credits) end

---
-- Hook that is called when a player recieves credits as a team award.
-- @param Player ply The player who was awarded the credits
-- @param number credits The amount of credits the player received
-- @hook
-- @realm server
function GM:TTT2OnReceiveTeamAwardCredits(ply, credits) end
10 changes: 10 additions & 0 deletions gamemodes/terrortown/gamemode/server/sv_shop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ concommand.Add("ttt_cheat_credits", CheatCredits, nil, nil, FCVAR_CHEAT)
-- @realm server
function GM:TTT2CanTransferCredits(sender, recipient, credits_per_xfer) end

---
-- Called when a player has successfully transfered a credit to another player.
-- @param Player sender Player that has sent the credits.
-- @param Player recipient Player that has received the credits.
-- @param number credits Amount of credits that have been transferred.
-- @param boolean isRecipientDead If the recipient is dead or not.
-- @hook
-- @realm server
function GM:TTT2OnTransferCredits(sender, recipient, credits, isRecipientDead) end

local function TransferCredits(ply, cmd, args)
if #args ~= 2 then
return
Expand Down
12 changes: 12 additions & 0 deletions gamemodes/terrortown/gamemode/shared/sh_shop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ function shop.TryRerollShop(ply)
else
ply:SubtractCredits(GetGlobalInt("ttt2_random_shop_reroll_cost"))
shop.ForceRerollShop(ply)
---
-- @realm server
-- stylua: ignore
hook.Run("TTT2OrderedEquipment", ply, "reroll_shop", false, GetGlobalInt("ttt2_random_shop_reroll_cost"), false)
end

return true
Expand Down Expand Up @@ -436,13 +440,21 @@ function shop.TransferCredits(ply, targetPlyId64, credits)

if target:IsTerror() and target:Alive() then
target:AddCredits(credits)
---
-- @realm server
-- stylua: ignore
hook.Run("TTT2OnTransferCredits", ply, target, credits, false)
else
-- The would be recipient is dead, which the sender may not know.
-- Instead attempt to send the credits to the target's corpse, where they can be picked up.
local rag = target:FindCorpse()

if IsValid(rag) then
CORPSE.SetCredits(rag, CORPSE.GetCredits(rag, 0) + credits)
---
-- @realm server
-- stylua: ignore
hook.Run("TTT2OnTransferCredits", ply, target, credits, false)
end
end

Expand Down
14 changes: 14 additions & 0 deletions lua/ttt2/libraries/bodysearch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ if SERVER then

events.Trigger(EVENT_CREDITFOUND, ply, rag, credits)

---
-- @realm server
-- stylua: ignore
hook.Run("TTT2OnGiveFoundCredits", ply, rag, credits)

-- update clients so their UIs can be updated
net.Start("ttt2_credits_were_taken")
net.WriteUInt(searchUID or 0, 16)
Expand Down Expand Up @@ -376,6 +381,15 @@ if SERVER then
function bodysearch.StreamSceneData(sceneData, client)
net.SendStream("TTT2_BodySearchData", sceneData, client)
end

---
-- Called after a player has been given credits for searching a corpse.
-- @param Player ply The player that searched the corpse
-- @param Entity rag The ragdoll that was searched
-- @param number credits The amount of credits that were given
-- @hook
-- @realm server
function GM:TTT2OnGiveFoundCredits(ply, rag, credits) end
end

if CLIENT then
Expand Down
12 changes: 12 additions & 0 deletions lua/ttt2/libraries/credits.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ function credits.HandleKillCreditsAward(victim, attacker)
local creditsAmount = GetConVar("ttt_credits_award_kill"):GetInt()

attacker:AddCredits(creditsAmount)

---
-- @realm server
-- stylua: ignore
hook.Run("TTT2OnReceiveKillCredits", victim, attacker, creditsAmount)

LANG.Msg(
attacker,
"credit_kill",
Expand Down Expand Up @@ -143,6 +149,12 @@ function credits.HandleKillCreditsAward(victim, attacker)

-- now reward their player for their good game
plyToAward:AddCredits(creditsAmount)

---
-- @realm server
-- stylua: ignore
hook.Run("TTT2OnReceiveTeamAwardCredits", plyToAward, creditsAmount)

LANG.Msg(plyToAward, "credit_all", { num = creditsAmount }, MSG_MSTACK_ROLE)
end
end
Expand Down
Loading