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
base: master
Are you sure you want to change the base?
Conversation
- TTT2ReceivedTeamAwardCredits - TTT2ReceivedKillCredits - TTT2OnGiveFoundCredits - TTT2TransferedCredits
Fixed some errors.
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
Sorry, one more commit. I couldn't understand what the remaining error was in CI so I had to go get stylua. |
Yeah, it can be a little confusing what it wants, especially if TTT2 isn't the root of your project (for vscode at least) |
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 |
IMHO these names are inconsistent. It should probably be more like |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
In my case I did not want to wait until round end, I wanted to update the database as soon as something had occurred.
I have changed the names. |
…he call location moved to bodysearch)
…-merge # Conflicts: # CHANGELOG.md
Then this is fine with me now, as soon as you undraft it, you can rerequest a review from me. Thanks! |
…-merge # Conflicts: # CHANGELOG.md
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:
GM:TTT2OnGiveFoundCredits()
, which is triggered serverside when a player has been given credits for searching a corpse.GM:TTT2ReceivedKillCredits()
, which is called when a player recieves credits for a kill.GM:TTT2ReceivedTeamAwardCredits()
, which is called when a player recieves credits as a team award.GM:TTT2TransferedCredits()
, which is called when a player has successfully transfered a credit to another player.Changed:
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!