diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b9580f9c..d19daea3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/gamemodes/terrortown/gamemode/server/sv_player_ext.lua b/gamemodes/terrortown/gamemode/server/sv_player_ext.lua index 764b20f09..3a884b5dd 100644 --- a/gamemodes/terrortown/gamemode/server/sv_player_ext.lua +++ b/gamemodes/terrortown/gamemode/server/sv_player_ext.lua @@ -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 diff --git a/gamemodes/terrortown/gamemode/server/sv_shop.lua b/gamemodes/terrortown/gamemode/server/sv_shop.lua index ef57a6fa6..0e02959b4 100644 --- a/gamemodes/terrortown/gamemode/server/sv_shop.lua +++ b/gamemodes/terrortown/gamemode/server/sv_shop.lua @@ -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 diff --git a/gamemodes/terrortown/gamemode/shared/sh_shop.lua b/gamemodes/terrortown/gamemode/shared/sh_shop.lua index 1a444d56a..2ea86cec4 100644 --- a/gamemodes/terrortown/gamemode/shared/sh_shop.lua +++ b/gamemodes/terrortown/gamemode/shared/sh_shop.lua @@ -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 @@ -436,6 +440,10 @@ 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. @@ -443,6 +451,10 @@ function shop.TransferCredits(ply, targetPlyId64, credits) 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 diff --git a/lua/ttt2/libraries/bodysearch.lua b/lua/ttt2/libraries/bodysearch.lua index 05274acd8..50499c2e0 100644 --- a/lua/ttt2/libraries/bodysearch.lua +++ b/lua/ttt2/libraries/bodysearch.lua @@ -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) @@ -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 diff --git a/lua/ttt2/libraries/credits.lua b/lua/ttt2/libraries/credits.lua index a89b4caed..df0dca67a 100644 --- a/lua/ttt2/libraries/credits.lua +++ b/lua/ttt2/libraries/credits.lua @@ -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", @@ -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