Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <sdktools>
- #pragma semicolon 1
- ConVar g_hFinaleEscapeBonus;
- int g_FinalEscapeBonus = 0;
- int g_SurvivorTeamIndex = -1;
- public Plugin myinfo =
- {
- name = "L4D/2 Finale Escape Bonus",
- author = "Nicholas Solin a.k.a. PatPeter",
- description = "Awards configurable bonus points to the correct Survivor team in Versus Mode.",
- version = "1.5",
- url = ""
- };
- public void OnPluginStart()
- {
- // Create a ConVar for bonus points
- 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);
- RegConsoleCmd("debug_score", Cmd_DebugScore, "Prints various game rule scores for debugging.");
- HookEvent("finale_vehicle_leaving", Event_FinaleVehicleLeaving, EventHookMode_Post);
- // https://wiki.alliedmods.net/Left_4_dead_2_events#round_end
- HookEvent("round_end", Event_RoundEnd);
- }
- // Event triggered when the finale vehicle leaves
- public void Event_FinaleVehicleLeaving(Event event, const char[] name, bool dontBroadcast)
- {
- int survivorCount = event.GetInt("survivorcount");
- if (survivorCount <= 0)
- {
- PrintToServer("[L4D2 Debug] No survivors escaped.");
- return;
- }
- // Get the active survivor team index dynamically
- g_SurvivorTeamIndex = GetCurrentSurvivorTeamIndex();
- if (g_SurvivorTeamIndex == -1)
- {
- PrintToServer("[L4D2 Debug] Could not determine the active Survivor team!");
- return;
- }
- int bonusPerSurvivor = g_hFinaleEscapeBonus.IntValue; // GetConVarInt(FindConVar("versus_finale_escape_bonus"));
- g_FinalEscapeBonus = survivorCount * bonusPerSurvivor;
- PrintToServer("[L4D2 Debug] Survivors escaped: %d", survivorCount);
- PrintToServer("[L4D2 Debug] Storing bonus points: %d ( %d x %d )", g_FinalEscapeBonus, survivorCount, bonusPerSurvivor);
- }
- public void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
- {
- if (g_FinalEscapeBonus <= 0 || g_SurvivorTeamIndex == -1)
- {
- PrintToServer("[L4D2 Debug] Skipping bonus: already applied or no bonus to apply.");
- return;
- }
- // Delay the score application to make sure it's the *second* round_end
- CreateTimer(5.0, ApplyFinaleBonusScore, _, TIMER_FLAG_NO_MAPCHANGE);
- }
- public Action ApplyFinaleBonusScore(Handle timer)
- {
- if (g_FinalEscapeBonus <= 0 || g_SurvivorTeamIndex == -1)
- {
- return Plugin_Stop;
- }
- int currentScore = GameRules_GetProp("m_iCampaignScore", 4, g_SurvivorTeamIndex);
- int newScore = currentScore + g_FinalEscapeBonus;
- GameRules_SetProp("m_iCampaignScore", newScore, 4, g_SurvivorTeamIndex, true);
- PrintToServer("[L4D2 Debug] Applied +%d finale escape bonus to Team %d", g_FinalEscapeBonus, g_SurvivorTeamIndex);
- PrintToServer("[L4D2 Debug] Updated Campaign Score: %d", newScore);
- g_FinalEscapeBonus = 0;
- g_SurvivorTeamIndex = -1;
- return Plugin_Stop;
- }
- /* Event triggered at the end of the round
- public void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
- {
- if (g_SurvivorTeamIndex == -1)
- {
- PrintToServer("[L4D2 Debug] Survivor team index is invalid. Cannot apply score.");
- return;
- }
- // Retrieve the current score for the survivor team
- int currentScore = GameRules_GetProp("m_iCampaignScore", 4, g_SurvivorTeamIndex);
- PrintToServer("[L4D2 Debug] Previous Campaign Score: %d", currentScore);
- PrintToServer("[L4D2 Debug] Applying Finale Escape Bonus: +%d", g_FinalEscapeBonus);
- int newScore = currentScore + g_FinalEscapeBonus;
- GameRules_SetProp("m_iCampaignScore", newScore, 4, g_SurvivorTeamIndex, true);
- PrintToServer("[L4D2] Updated Campaign Score: %d", newScore);
- // Reset bonus for the next round
- g_FinalEscapeBonus = 0;
- g_SurvivorTeamIndex = -1;
- }*/
- // Returns the active Survivor team's index in m_iSurvivorScore
- int GetCurrentSurvivorTeamIndex()
- {
- //int roundTeam = GameRules_GetProp("m_iRoundTeam"); // 2 = Survivors, 3 = Infected
- //if (roundTeam != 2) return -1; // Only proceed if Survivors are playing
- int isSecondHalf = GameRules_GetProp("m_bInSecondHalfOfRound"); // 0 = First team, 1 = Second team
- return isSecondHalf; // 0 = First team (index 0), 1 = Second team (index 1)
- }
- public Action Cmd_DebugScore(int client, int args)
- {
- if (args < 1)
- {
- ReplyToCommand(client, "[L4D2 Debug] Usage: sm_debug_score <GameRules property>");
- return Plugin_Handled;
- }
- char propName[64];
- GetCmdArg(1, propName, sizeof(propName));
- PrintToServer("[L4D2 Debug] Fetching GameRules property: %s", propName);
- if (StrEqual(propName, "m_flTeamRoundTime") || StrEqual(propName, "m_flRoundStartTime") ||
- StrEqual(propName, "m_flRoundEndTime") || StrEqual(propName, "m_flAccumulatedTime") ||
- StrEqual(propName, "m_flTeamBestRoundTime") || StrEqual(propName, "m_flRoundDuration"))
- {
- DebugPrintPropFloat(propName, 2);
- }
- else
- {
- // Default to 2 elements for most props unless overridden explicitly
- int count = 2;
- if (StrEqual(propName, "m_iScavengeTeamScore")) count = 10;
- else if (StrEqual(propName, "m_iVersusDistancePerSurvivor")) count = 8;
- else if (StrEqual(propName, "m_iVersusSurvivorDeathDistance")) count = 8;
- else if (StrEqual(propName, "m_bInIntro") || StrEqual(propName, "m_nRoundNumber") ||
- StrEqual(propName, "m_nRoundLimit") || StrEqual(propName, "m_nScavengeItemsRemaining") ||
- StrEqual(propName, "m_nScavengeItemsGoal") || StrEqual(propName, "m_bAreTeamsFlipped") ||
- StrEqual(propName, "m_bInSecondHalfOfRound") || StrEqual(propName, "m_bIsTransitioningToNextMap") ||
- StrEqual(propName, "m_bIsVersusVoteRestarting") || StrEqual(propName, "m_iSacrificeEscapees")) count = 1;
- else if (StrEqual(propName, "m_iWinningTeamNumber")) count = 5;
- DebugPrintProp(propName, count);
- }
- PrintToServer("[L4D2 Debug] Debugging of %s complete.", propName);
- return Plugin_Handled;
- }
- void DebugPrintProp(const char[] propName, int count)
- {
- for (int i = 0; i < count; i++)
- {
- int value = GameRules_GetProp(propName, 4, i);
- PrintToServer("[L4D2 Debug] %s[%d] = %d", propName, i, value);
- }
- }
- void DebugPrintPropFloat(const char[] propName, int count)
- {
- for (int i = 0; i < count; i++)
- {
- float value = GameRules_GetPropFloat(propName, i); // Corrected function call
- PrintToServer("[L4D2 Debug] %s[%d] = %f", propName, i, value);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment