View Single Post
Proaxel
Member
Join Date: Oct 2014
Old 03-21-2021 , 19:55   Re: [L4D2] How to scale the gas can goal in scavenge finales to number of survivors?
Reply With Quote #10

I got it figured out and working, thanks to both of you! I changed my mind and went with having the VScript read a convar as suggested by Zynda, and went with having ScavengeRemixDS being responsible for setting up the extra can spawns.


PHP Code:
public Action OnVScriptExecuted(const char[] sScriptchar sOverride[PLATFORM_MAX_PATH], bool bOverride)
{
    if( 
strcmp(sScript"c1m4_atrium_finale") == || (bOverride && strcmp(sOverride"c1m4_atrium_finale") == 0) )
    {
        
//PrintToServer("[ScavengeBalancerDebug] Determining Can amount now.", g_numAtRoundStart);
        //PrintToChatAll("\x05[ScavengeBalancerDebug] \x01Determining Can amount now");
        
g_numAtRoundStart GetTotalSurvivorCount();
        
//PrintToServer("Survivors: %d", g_numAtRoundStart);
        
FindConVar("cans_goal_c1m4").IntValue CalculateGasCanGoal(13g_numAtRoundStart);
        
FindConVar("l4d2_scramble_can_count").IntValue FindConVar("cans_goal_c1m4").IntValue
        
g_overridenGoal true;
        
g_newGasCanGoal FindConVar("cans_goal_c1m4").IntValue;
        
Ent_Fire("game_scavenge_progress_display""SetTotalItems"g_newGasCanGoal);
        
//PrintToChatAll("\x05[ScavengeBalancerDebug] \x01Calculated new scavenge goal.", g_numAtRoundStart, FindConVar("l4d2_scramble_can_count").IntValue);
        //PrintToChatAll("13 + ((%d - 4) * 2) = %d", g_numAtRoundStart, FindConVar("l4d2_scramble_can_count").IntValue);
        //PrintToChatAll("\x05[ScavengeBalancerDebug] \x01%d gas cans SHOULD now be on the map. Ping Proaxel on Discord if this is not the case", FindConVar("l4d2_scramble_can_count").IntValue);
    
}
    return 
Plugin_Continue;

It is safe to run this right as the elevator opens, ScavengeRemixDS does see the convar change right away and spawns the right number of gas cans.

The only problem I ran into was that I found ScavengeRemixDS only scrambles the gas cans on the first finale attempt since map load. I found that if more players join between the time the finale starts the first time and the second time (due to survivors losing and restarting the round), my plugin sets the new goal to the number of players accordingly, but ScavengeRemixDS still spawns the number of cans determined from the first time, which can result in a softlocked finale due to not enough cans. Also, unlike vanilla it doesn't despawn the cans if survivors lose and retry again, so you can see all the gas cans as you're walking into the atrium for the second time again.

Thankfully the fix for these problems was simple, the code for said plugin is well organized enough that it was simply a matter of hooking the mission_lost event, and using it to call a couple of already made functions and changing a boolean to false to allow it to calculate and scramble gas cans again the next time the finale is triggered.

PHP Code:
public Action Event_MissionLost(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(!
IsScavenge() && !IsSurvival() && ScrambleConfirmed)
    {
        
RemoveAllGasCanSpawns(); //Remove all current gas cans
        
RemoveAllGasCans(); //Remove all current gas can spawners
        
ScrambleConfirmed false;
        
PrintToChatAll("\x05[ScavengeRemixDS] \x01Gas Can Spawns Reset");
    }

Edit: I've since merged my plugin into the ScavengeRemixDS plugin itself. I thought it made more sense, so I just did it.

Last edited by Proaxel; 04-05-2021 at 04:40.
Proaxel is offline