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

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

pkillboredom
Copy link

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
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?

-- @param number credits The amount of credits that were given
-- @hook
-- @realm server
function GM:TTT2OnGiveFoundCredits(ply, rag, credits) end
Copy link
Member

Choose a reason for hiding this comment

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

This hook seems to be called no where?

Copy link
Author

Choose a reason for hiding this comment

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

I missed in merging from upstream that the place where this was called moved from sv_corpse to bodysearch. I've added the call back and will test sometime in the next few days.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure that adding the additional functionality you've suggested would work for my stats addon, like you said.

The event system currently doesn't have events for the GM:TTT2OnReceiveKillCredits(), GM:TTT2OnReceiveTeamAwardCredits() or GM:TTT2OnTransferCredits() cases. If you would prefer that I pivot toward using the event system, I think that would work for me over making the hooks cancel-able. I suppose I would just need to add events for those cases and listen to GM:TTT2AddedEvent to record the events in real time, right?

Copy link
Member

Choose a reason for hiding this comment

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

Nah, I don't want to pivot you in that direction, I only wanted to make sure that you are aware of it. If you say that it doesn't work for you, then it is fine

@pkillboredom pkillboredom marked this pull request as draft March 28, 2024 21:00
@pkillboredom
Copy link
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!

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.

None yet

4 participants