Skip to content

Commit

Permalink
Map transitions plugin (#346)
Browse files Browse the repository at this point in the history
* Delete thesaccing_v2.vpk

* Delete TheCrashStand.vpk

* Update generalfixes.cfg

* Update shared_settings.cfg

* Update shared_settings.cfg

* Update shared_settings.cfg

* Update shared_settings.cfg

* Update pmelite.cfg

* Update shared_settings.cfg

* Update shared_settings.cfg

* Update shared_settings.cfg

* Add files via upload

* Update l4d2_map_transitions.sp

* Add files via upload

Co-authored-by: SirPlease
  • Loading branch information
Derpduck authored Aug 15, 2021
1 parent ca876ec commit 9787f32
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 0 deletions.
Binary file removed addons/TheCrashStand.vpk
Binary file not shown.
Binary file not shown.
154 changes: 154 additions & 0 deletions addons/sourcemod/scripting/l4d2_map_transitions.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <left4dhooks>
#include <colors>

#define MAP_NAME_MAX_LENGTH 64
#define LEFT4FRAMEWORK_GAMEDATA "left4dhooks.l4d2"

StringMap hMapTransitionPair = null

Handle hSetCampaignScores

int g_iPointsTeamA = 0
int g_iPointsTeamB = 0
bool g_bHasTransitioned = false

public Plugin:myinfo =
{
name = "Map Transitions",
author = "Derpduck",
description = "Define map transitions to combine campaigns",
version = "1",
url = "https://github.com/SirPlease/L4D2-Competitive-Rework"
}

public OnPluginStart()
{
CheckGame()
LoadSDK()

hMapTransitionPair = new StringMap()
RegServerCmd("sm_add_map_transition", AddMapTransition)

HookEvent("round_start", OnRoundStart_Event, EventHookMode_PostNoCopy)
}

void CheckGame()
{
if (GetEngineVersion() != Engine_Left4Dead2)
{
SetFailState("Plugin 'SetScores' supports Left 4 Dead 2 only!")
}
}

void LoadSDK()
{
Handle conf = LoadGameConfigFile(LEFT4FRAMEWORK_GAMEDATA)
if (conf == INVALID_HANDLE)
{
SetFailState("Could not load gamedata/%s.txt", LEFT4FRAMEWORK_GAMEDATA)
}

StartPrepSDKCall(SDKCall_GameRules)
if (!PrepSDKCall_SetFromConf(conf, SDKConf_Signature, "SetCampaignScores"))
{
SetFailState("Function 'SetCampaignScores' not found.")
}

PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain)
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain)
hSetCampaignScores = EndPrepSDKCall()
if (hSetCampaignScores == INVALID_HANDLE)
{
SetFailState("Function 'SetCampaignScores' found, but something went wrong.")
}

delete conf
}

public OnRoundEnd()
{
int isSecondHalf = InSecondHalfOfRound()

//If map is in last half, attempt a transition
if (isSecondHalf == 1)
{
CreateTimer(15.0, OnRoundEnd_Post)
}
}

static Action:OnRoundEnd_Post(Handle timer)
{
//Check if map has been registered for a map transition
char currentMapName[MAP_NAME_MAX_LENGTH]
char nextMapName[MAP_NAME_MAX_LENGTH]

GetCurrentMap(currentMapName, sizeof(currentMapName))

//We have a map to transition to
if (hMapTransitionPair.GetString(currentMapName, nextMapName, sizeof(nextMapName)))
{
//Preserve scores between transitions
g_iPointsTeamA = L4D2Direct_GetVSCampaignScore(0)
g_iPointsTeamB = L4D2Direct_GetVSCampaignScore(1)
g_bHasTransitioned = true

CPrintToChatAll("{olive}[MT]{default} Starting transition from: {blue}%s{default} to: {blue}%s", currentMapName, nextMapName)
LogMessage("Map transitioned from: %s to: %s", currentMapName, nextMapName)
ForceChangeLevel(nextMapName, "Map Transitions")
}
}

static void OnRoundStart_Event(Event hEvent, const char[] eName, bool dontBroadcast)
{
int isSecondHalf = InSecondHalfOfRound()

//Set scores after a modified transition
if (g_bHasTransitioned && isSecondHalf == 0)
{
CreateTimer(5.0, OnRoundStart_Post) //We need to do this before l4d_tank_control_eq checks scores (at 10 seconds)
g_bHasTransitioned = false
}
}

static Action:OnRoundStart_Post(Handle timer)
{
//Print scores, teams will not be flipped because the game thinks we have started a new match
CPrintToChatAll("{olive}[MT]{default} Set scores to: {blue}(Survivors) %i{default} vs {blue}(Infected) %i{default}", g_iPointsTeamA, g_iPointsTeamB)

//Set scores on scoreboard
SDKCall(hSetCampaignScores, g_iPointsTeamA, g_iPointsTeamB)

//Set actual scores
L4D2Direct_SetVSCampaignScore(0, g_iPointsTeamA)
L4D2Direct_SetVSCampaignScore(1, g_iPointsTeamB)
LogMessage("Set scores to: (Survivors) %i vs (Infected) %i", g_iPointsTeamA, g_iPointsTeamB)
}

static Action:AddMapTransition(int args)
{
if (args != 2)
{
PrintToServer("Usage: sm_add_map_transition <starting map name> <ending map name>")
LogError("Usage: sm_add_map_transition <starting map name> <ending map name>")
return Plugin_Handled;
}

//Read map pair names
char mapStart[MAP_NAME_MAX_LENGTH]
char mapEnd[MAP_NAME_MAX_LENGTH]
GetCmdArg(1, mapStart, sizeof(mapStart))
GetCmdArg(2, mapEnd, sizeof(mapEnd))

hMapTransitionPair.SetString(mapStart, mapEnd, true)

return Plugin_Handled;
}

//Return if round is first or second half
stock InSecondHalfOfRound()
{
return GameRules_GetProp("m_bInSecondHalfOfRound");
}
Binary file removed addons/thesaccing_v2.vpk
Binary file not shown.
4 changes: 4 additions & 0 deletions cfg/cfgogl/apex/shared_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ static_witch_map dkr_m3_tunneloflove
static_witch_map dkr_m4_ferris
static_witch_map dkr_m5_stadium
// Map transition rules
sm_add_map_transition c6m2_bedlam c7m1_docks
sm_add_map_transition c9m2_lots c14m1_junkyard
// Personalized settings
exec confogl_personalize.cfg
Expand Down
4 changes: 4 additions & 0 deletions cfg/cfgogl/eq/shared_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ tank_map_only_first_event c1m4_atrium
tank_map_only_first_event c4m5_milltown_escape
tank_map_only_first_event c5m5_bridge

// Map transition rules
sm_add_map_transition c6m2_bedlam c7m1_docks
sm_add_map_transition c9m2_lots c14m1_junkyard

// Personalized settings
exec confogl_personalize.cfg

Expand Down
4 changes: 4 additions & 0 deletions cfg/cfgogl/nextmod/shared_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ static_witch_map dkr_m3_tunneloflove
static_witch_map dkr_m4_ferris
static_witch_map dkr_m5_stadium
// Map transition rules
sm_add_map_transition c6m2_bedlam c7m1_docks
sm_add_map_transition c9m2_lots c14m1_junkyard
// Personalized settings
exec confogl_personalize.cfg
Expand Down
4 changes: 4 additions & 0 deletions cfg/cfgogl/pmelite/pmelite.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ confogl_addcvar sm_witch_bonus_print 0
confogl_addcvar sm_witch_bonus_always 1
confogl_addcvar sm_hbonus_configpath "../../cfg/cfgogl/pmelite/holdoutmapinfo.txt"

// Map transition rules
sm_add_map_transition c6m2_bedlam c7m1_docks
sm_add_map_transition c9m2_lots c14m1_junkyard

// Personalized settings
exec confogl_personalize.cfg

Expand Down
4 changes: 4 additions & 0 deletions cfg/cfgogl/zonehunters/shared_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ static_witch_map dkr_m3_tunneloflove
static_witch_map dkr_m4_ferris
static_witch_map dkr_m5_stadium
// Map transition rules
sm_add_map_transition c6m2_bedlam c7m1_docks
sm_add_map_transition c9m2_lots c14m1_junkyard
// Personalized settings
exec confogl_personalize.cfg
Expand Down
4 changes: 4 additions & 0 deletions cfg/cfgogl/zonemod/shared_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ static_witch_map dkr_m3_tunneloflove
static_witch_map dkr_m4_ferris
static_witch_map dkr_m5_stadium
// Map transition rules
sm_add_map_transition c6m2_bedlam c7m1_docks
sm_add_map_transition c9m2_lots c14m1_junkyard
// Personalized settings
exec confogl_personalize.cfg
Expand Down
4 changes: 4 additions & 0 deletions cfg/cfgogl/zonemodold/shared_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ static_witch_map dkr_m3_tunneloflove
static_witch_map dkr_m4_ferris
static_witch_map dkr_m5_stadium
// Map transition rules
sm_add_map_transition c6m2_bedlam c7m1_docks
sm_add_map_transition c9m2_lots c14m1_junkyard
// Personalized settings
exec confogl_personalize.cfg
Expand Down
4 changes: 4 additions & 0 deletions cfg/cfgogl/zoneretro/shared_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ static_witch_map dkr_m3_tunneloflove
static_witch_map dkr_m4_ferris
static_witch_map dkr_m5_stadium
// Map transition rules
sm_add_map_transition c6m2_bedlam c7m1_docks
sm_add_map_transition c9m2_lots c14m1_junkyard
// Personalized settings
exec confogl_personalize.cfg
Expand Down
1 change: 1 addition & 0 deletions cfg/generalfixes.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ sm plugins load l4d_pause_message.smx
sm plugins load fixes/l4d2_boomer_shenanigans.smx
sm plugins load fixes/sv_consistency_fix.smx
sm plugins load fixes/l4d2_hltv_crash_fix.smx
sm plugins load optional/l4d2_map_transitions.smx
sm plugins load fixes/l4d_checkpoint_rock_patch.smx

// Anti-Cheat.
Expand Down

0 comments on commit 9787f32

Please sign in to comment.