csrd_extended_humiliation.sp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * [CSRD] Extended Humiliation Round Fixes
  3. *
  4. * Minor quality-of-life improvements in extended humiliation rounds.
  5. *
  6. * 1. Hides the round win panel 5 seconds after the round is over. Pairs well with an
  7. * end-round Prop Hunt system as it prevents the win panel from covering up a good amount of the
  8. * screen for the rest of the humiliation period.
  9. * 2. Hides losing player health. "The losers are all too concerned with trying to escape the
  10. * victors that they don't notice how much health they have left" is what I'd like to think.
  11. */
  12. #pragma semicolon 1
  13. #include <sourcemod>
  14. #include <tf2_stocks>
  15. #pragma newdecls required
  16. #define PLUGIN_VERSION "1.0.0"
  17. public Plugin myinfo = {
  18. name = "[CSRD] Extended Humiliation Round Fixes",
  19. author = "nosoop",
  20. description = "Improvements to deal with extended humiliation rounds.",
  21. version = PLUGIN_VERSION,
  22. url = "https://git.csrd.science/"
  23. }
  24. #define HIDEHUD_HEALTH ( 1 << 3 )
  25. public void OnPluginStart() {
  26. HookEvent("teamplay_round_win", OnRoundWin, EventHookMode_PostNoCopy);
  27. }
  28. public void OnRoundWin(Event event, const char[] name, bool dontBroadcast) {
  29. // we could pass it so only winners have their win panel closed...
  30. if ((FindConVar("mp_bonusroundtime").IntValue > 5)) {
  31. CreateTimer(5.0, HideWinPanelAll);
  32. }
  33. }
  34. public Action HideWinPanelAll(Handle timer, any discard) {
  35. int clients[MAXPLAYERS], numClients;
  36. for (int i = 1; i <= MaxClients; i++) {
  37. if (!IsClientInGame(i) || IsFakeClient(i)) {
  38. continue;
  39. }
  40. TFTeam team = TF2_GetClientTeam(i);
  41. if (team == TFTeam_Red || team == TFTeam_Blue) {
  42. clients[numClients++] = i;
  43. // just set and forget; no need to reset this at round start
  44. SetEntProp(i, Prop_Data, "m_iHideHUD", HIDEHUD_HEALTH);
  45. }
  46. }
  47. TF2_HideWinPanel(clients, numClients);
  48. }
  49. /**
  50. * Based off of CTFWinPanel:FireGameEvent():
  51. * https://github.com/LestaD/SourceEngine2007/blob/master/se2007/game/client/tf/tf_hud_winpanel.cpp#L103
  52. *
  53. * When a client receives the `teamplay_round_start` event, it hides the win panel.
  54. * `teamplay_game_over` and `tf_game_over` may also possibly work, though I didn't bother
  55. * checking since it's likely they do other stuff on the client (like showing other panels or
  56. * something).
  57. */
  58. stock void TF2_HideWinPanel(const int[] clients, int numClients) {
  59. if (numClients) {
  60. Event event = CreateEvent("teamplay_round_start", true);
  61. #if SOURCEMOD_V_MAJOR >= 1 && SOURCEMOD_V_MINOR > 8
  62. // avoid broadcasting event; disabling broadcasts on 1.8 throws an error
  63. event.BroadcastDisabled = true;
  64. #endif
  65. for (int i = 0; i < numClients; i++) {
  66. event.FireToClient(clients[i]);
  67. }
  68. delete event;
  69. }
  70. }