PatPeter

Untitled

Apr 9th, 2025
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.66 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3.  
  4. #pragma semicolon 1
  5.  
  6. ConVar g_hFinaleEscapeBonus;
  7.  
  8. int g_FinalEscapeBonus = 0;
  9. int g_SurvivorTeamIndex = -1;
  10.  
  11. public Plugin myinfo =
  12. {
  13. name = "L4D/2 Finale Escape Bonus",
  14. author = "Nicholas Solin a.k.a. PatPeter",
  15. description = "Awards configurable bonus points to the correct Survivor team in Versus Mode.",
  16. version = "1.5",
  17. url = ""
  18. };
  19.  
  20. public void OnPluginStart()
  21. {
  22. // Create a ConVar for bonus points
  23. g_hFinaleEscapeBonus = CreateConVar("versus_finale_escape_bonus", "200", "Bonus points for each survivor that escapes in Versus Mode.", FCVAR_NOTIFY, true, 0.0, true, 1000.0);
  24. RegConsoleCmd("debug_score", Cmd_DebugScore, "Prints various game rule scores for debugging.");
  25. HookEvent("finale_vehicle_leaving", Event_FinaleVehicleLeaving, EventHookMode_Post);
  26. // https://wiki.alliedmods.net/Left_4_dead_2_events#round_end
  27. HookEvent("round_end", Event_RoundEnd);
  28. }
  29.  
  30. // Event triggered when the finale vehicle leaves
  31. public void Event_FinaleVehicleLeaving(Event event, const char[] name, bool dontBroadcast)
  32. {
  33. int survivorCount = event.GetInt("survivorcount");
  34.  
  35. if (survivorCount <= 0)
  36. {
  37. PrintToServer("[L4D2 Debug] No survivors escaped.");
  38. return;
  39. }
  40.  
  41. // Get the active survivor team index dynamically
  42. g_SurvivorTeamIndex = GetCurrentSurvivorTeamIndex();
  43. if (g_SurvivorTeamIndex == -1)
  44. {
  45. PrintToServer("[L4D2 Debug] Could not determine the active Survivor team!");
  46. return;
  47. }
  48.  
  49. int bonusPerSurvivor = g_hFinaleEscapeBonus.IntValue; // GetConVarInt(FindConVar("versus_finale_escape_bonus"));
  50. g_FinalEscapeBonus = survivorCount * bonusPerSurvivor;
  51.  
  52. PrintToServer("[L4D2 Debug] Survivors escaped: %d", survivorCount);
  53. PrintToServer("[L4D2 Debug] Storing bonus points: %d ( %d x %d )", g_FinalEscapeBonus, survivorCount, bonusPerSurvivor);
  54. }
  55.  
  56. public void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
  57. {
  58. if (g_FinalEscapeBonus <= 0 || g_SurvivorTeamIndex == -1)
  59. {
  60. PrintToServer("[L4D2 Debug] Skipping bonus: already applied or no bonus to apply.");
  61. return;
  62. }
  63.  
  64. // Delay the score application to make sure it's the *second* round_end
  65. CreateTimer(5.0, ApplyFinaleBonusScore, _, TIMER_FLAG_NO_MAPCHANGE);
  66. }
  67.  
  68. public Action ApplyFinaleBonusScore(Handle timer)
  69. {
  70. if (g_FinalEscapeBonus <= 0 || g_SurvivorTeamIndex == -1)
  71. {
  72. return Plugin_Stop;
  73. }
  74.  
  75. int currentScore = GameRules_GetProp("m_iCampaignScore", 4, g_SurvivorTeamIndex);
  76. int newScore = currentScore + g_FinalEscapeBonus;
  77.  
  78. GameRules_SetProp("m_iCampaignScore", newScore, 4, g_SurvivorTeamIndex, true);
  79. PrintToServer("[L4D2 Debug] Applied +%d finale escape bonus to Team %d", g_FinalEscapeBonus, g_SurvivorTeamIndex);
  80. PrintToServer("[L4D2 Debug] Updated Campaign Score: %d", newScore);
  81.  
  82. g_FinalEscapeBonus = 0;
  83. g_SurvivorTeamIndex = -1;
  84.  
  85. return Plugin_Stop;
  86. }
  87.  
  88. /* Event triggered at the end of the round
  89. public void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
  90. {
  91. if (g_SurvivorTeamIndex == -1)
  92. {
  93. PrintToServer("[L4D2 Debug] Survivor team index is invalid. Cannot apply score.");
  94. return;
  95. }
  96.  
  97. // Retrieve the current score for the survivor team
  98. int currentScore = GameRules_GetProp("m_iCampaignScore", 4, g_SurvivorTeamIndex);
  99.  
  100. PrintToServer("[L4D2 Debug] Previous Campaign Score: %d", currentScore);
  101. PrintToServer("[L4D2 Debug] Applying Finale Escape Bonus: +%d", g_FinalEscapeBonus);
  102.  
  103. int newScore = currentScore + g_FinalEscapeBonus;
  104. GameRules_SetProp("m_iCampaignScore", newScore, 4, g_SurvivorTeamIndex, true);
  105.  
  106. PrintToServer("[L4D2] Updated Campaign Score: %d", newScore);
  107.  
  108. // Reset bonus for the next round
  109. g_FinalEscapeBonus = 0;
  110. g_SurvivorTeamIndex = -1;
  111. }*/
  112.  
  113. // Returns the active Survivor team's index in m_iSurvivorScore
  114. int GetCurrentSurvivorTeamIndex()
  115. {
  116. //int roundTeam = GameRules_GetProp("m_iRoundTeam"); // 2 = Survivors, 3 = Infected
  117. //if (roundTeam != 2) return -1; // Only proceed if Survivors are playing
  118.  
  119. int isSecondHalf = GameRules_GetProp("m_bInSecondHalfOfRound"); // 0 = First team, 1 = Second team
  120. return isSecondHalf; // 0 = First team (index 0), 1 = Second team (index 1)
  121. }
  122.  
  123. public Action Cmd_DebugScore(int client, int args)
  124. {
  125. if (args < 1)
  126. {
  127. ReplyToCommand(client, "[L4D2 Debug] Usage: sm_debug_score <GameRules property>");
  128. return Plugin_Handled;
  129. }
  130.  
  131. char propName[64];
  132. GetCmdArg(1, propName, sizeof(propName));
  133.  
  134. PrintToServer("[L4D2 Debug] Fetching GameRules property: %s", propName);
  135.  
  136. if (StrEqual(propName, "m_flTeamRoundTime") || StrEqual(propName, "m_flRoundStartTime") ||
  137. StrEqual(propName, "m_flRoundEndTime") || StrEqual(propName, "m_flAccumulatedTime") ||
  138. StrEqual(propName, "m_flTeamBestRoundTime") || StrEqual(propName, "m_flRoundDuration"))
  139. {
  140. DebugPrintPropFloat(propName, 2);
  141. }
  142. else
  143. {
  144. // Default to 2 elements for most props unless overridden explicitly
  145. int count = 2;
  146.  
  147. if (StrEqual(propName, "m_iScavengeTeamScore")) count = 10;
  148. else if (StrEqual(propName, "m_iVersusDistancePerSurvivor")) count = 8;
  149. else if (StrEqual(propName, "m_iVersusSurvivorDeathDistance")) count = 8;
  150. else if (StrEqual(propName, "m_bInIntro") || StrEqual(propName, "m_nRoundNumber") ||
  151. StrEqual(propName, "m_nRoundLimit") || StrEqual(propName, "m_nScavengeItemsRemaining") ||
  152. StrEqual(propName, "m_nScavengeItemsGoal") || StrEqual(propName, "m_bAreTeamsFlipped") ||
  153. StrEqual(propName, "m_bInSecondHalfOfRound") || StrEqual(propName, "m_bIsTransitioningToNextMap") ||
  154. StrEqual(propName, "m_bIsVersusVoteRestarting") || StrEqual(propName, "m_iSacrificeEscapees")) count = 1;
  155. else if (StrEqual(propName, "m_iWinningTeamNumber")) count = 5;
  156.  
  157. DebugPrintProp(propName, count);
  158. }
  159.  
  160. PrintToServer("[L4D2 Debug] Debugging of %s complete.", propName);
  161. return Plugin_Handled;
  162. }
  163.  
  164. void DebugPrintProp(const char[] propName, int count)
  165. {
  166. for (int i = 0; i < count; i++)
  167. {
  168. int value = GameRules_GetProp(propName, 4, i);
  169. PrintToServer("[L4D2 Debug] %s[%d] = %d", propName, i, value);
  170. }
  171. }
  172.  
  173. void DebugPrintPropFloat(const char[] propName, int count)
  174. {
  175. for (int i = 0; i < count; i++)
  176. {
  177. float value = GameRules_GetPropFloat(propName, i); // Corrected function call
  178. PrintToServer("[L4D2 Debug] %s[%d] = %f", propName, i, value);
  179. }
  180. }
  181.  
Advertisement
Add Comment
Please, Sign In to add comment