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

Conversation

pkillboredom
Copy link
Contributor

This change adds some hooks for credit related events that are used by my addon ttt2stats. This addon records stats from my server's games to a database, which is used to populate a dashboard. I've been running these changes for a while and its about time I open a PR.

Added:

  • Added hook GM:TTT2OnGiveFoundCredits(), which is triggered serverside when a player has been given credits for searching a corpse.
  • Added hook GM:TTT2ReceivedKillCredits(), which is called when a player recieves credits for a kill.
  • Added hook GM:TTT2ReceivedTeamAwardCredits(), which is called when a player recieves credits as a team award.
  • Added hook GM:TTT2TransferedCredits(), which is called when a player has successfully transfered a credit to another player.

Changed:

  • TryRerollShop calls TTT2OrderedEquipment hook.

LMK if there are any suggestions. The thing I'm iffiest on is the TryRerollShop change, maybe a new hook would be better. Thanks!

 - TTT2ReceivedTeamAwardCredits
 - TTT2ReceivedKillCredits
 - TTT2OnGiveFoundCredits
 - TTT2TransferedCredits
 Conflicts:
	gamemodes/terrortown/gamemode/server/sv_corpse.lua
	gamemodes/terrortown/gamemode/server/sv_player_ext.lua
	gamemodes/terrortown/gamemode/server/sv_shop.lua
	lua/ttt2/libraries/credits.lua
…-merge

# Conflicts:
#	gamemodes/terrortown/gamemode/server/sv_corpse.lua
#	gamemodes/terrortown/gamemode/server/sv_player_ext.lua
#	gamemodes/terrortown/gamemode/server/sv_shop.lua
#	gamemodes/terrortown/gamemode/shared/sh_shop.lua
#	lua/ttt2/libraries/credits.lua
@pkillboredom
Copy link
Contributor Author

Sorry, one more commit. I couldn't understand what the remaining error was in CI so I had to go get stylua.

@EntranceJew
Copy link
Contributor

Yeah, it can be a little confusing what it wants, especially if TTT2 isn't the root of your project (for vscode at least)

@Histalek Histalek added the type/enhancement Enhancement or simple change to existing functionality label Mar 4, 2024
@TimGoll
Copy link
Member

TimGoll commented Mar 4, 2024

I will review this later, but just to ask, are you aware of TTT2's events? I think you should be able to get all of this data already from the events at the round end

@TimGoll
Copy link
Member

TimGoll commented Mar 4, 2024

  • Added hook GM:TTT2OnGiveFoundCredits(), which is triggered serverside when a player has been given credits for searching a corpse.
  • Added hook GM:TTT2ReceivedKillCredits(), which is called when a player recieves credits for a kill.
  • Added hook GM:TTT2ReceivedTeamAwardCredits(), which is called when a player recieves credits as a team award.
  • Added hook GM:TTT2TransferedCredits(), which is called when a player has successfully transfered a credit to another player.

IMHO these names are inconsistent. It should probably be more like GM:TTT2OnGiveFoundCredits(), GM:TTT2OnReceiveKillCredits(), GM:TTT2OnReceiveTeamAwardCredits() and GM:TTT2OnTransferCredits()

Copy link
Member

@TimGoll TimGoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the suggested name change I'd also like to suggest adding more functionality to those hooks. I'm thinking of "return false to cancel the action".

So this

hook.Add("TTT2OnGiveFoundCredits", "myhook", function(ply, rag, credits)
    return false
end

would cancel that action.

But this would probably break your statistics addon, wouldn't it?

gamemodes/terrortown/gamemode/server/sv_corpse.lua Outdated Show resolved Hide resolved
@pkillboredom pkillboredom marked this pull request as draft March 28, 2024 21:00
@pkillboredom
Copy link
Contributor Author

I will review this later, but just to ask, are you aware of TTT2's events? I think you should be able to get all of this data already from the events at the round end

In my case I did not want to wait until round end, I wanted to update the database as soon as something had occurred.

  • Added hook GM:TTT2OnGiveFoundCredits(), which is triggered serverside when a player has been given credits for searching a corpse.
  • Added hook GM:TTT2ReceivedKillCredits(), which is called when a player recieves credits for a kill.
  • Added hook GM:TTT2ReceivedTeamAwardCredits(), which is called when a player recieves credits as a team award.
  • Added hook GM:TTT2TransferedCredits(), which is called when a player has successfully transfered a credit to another player.

IMHO these names are inconsistent. It should probably be more like GM:TTT2OnGiveFoundCredits(), GM:TTT2OnReceiveKillCredits(), GM:TTT2OnReceiveTeamAwardCredits() and GM:TTT2OnTransferCredits()

I have changed the names.

pkillboredom added a commit to pkillboredom/ttt2stats that referenced this pull request Mar 28, 2024
@TimGoll
Copy link
Member

TimGoll commented Mar 29, 2024

Then this is fine with me now, as soon as you undraft it, you can rerequest a review from me. Thanks!

@TimGoll TimGoll marked this pull request as ready for review August 21, 2024 08:38
Copy link
Member

@TimGoll TimGoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This somehow got lost as you never updated the review state and I never checked the code state. LGTM, thanks for contributing!

@TimGoll TimGoll merged commit 1d02cea into TTT-2:master Aug 21, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Enhancement or simple change to existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants