forked from SirPlease/L4D2-Competitive-Rework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl4d2_map_transitions.sp
More file actions
160 lines (128 loc) · 3.93 KB
/
Copy pathl4d2_map_transitions.sp
File metadata and controls
160 lines (128 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <left4dhooks>
#define L4D2UTIL_STOCKS_ONLY 1
#include <l4d2util>
#define DEBUG 0
#define MAP_NAME_MAX_LENGTH 64
StringMap
g_hMapTransitionPair = null;
int
g_iPointsTeamA = 0,
g_iPointsTeamB = 0;
bool
g_bHasTransitioned = false;
Handle
g_hTransitionTimer;
public Plugin myinfo =
{
name = "Map Transitions",
author = "Derpduck, Forgetest",
description = "Define map transitions to combine campaigns",
version = "3.3",
url = "https://github.com/SirPlease/L4D2-Competitive-Rework"
};
public void OnPluginStart()
{
CheckGame();
g_hMapTransitionPair = new StringMap();
RegServerCmd("sm_add_map_transition", AddMapTransition);
}
void CheckGame()
{
if (GetEngineVersion() != Engine_Left4Dead2) {
SetFailState("Plugin 'Map Transitions' supports Left 4 Dead 2 only!");
}
}
public void L4D2_OnEndVersusModeRound_Post() //left4dhooks
{
//If map is in last half, attempt a transition
if (InSecondHalfOfRound()) {
g_hTransitionTimer = CreateTimer(15.0, OnRoundEnd_Post);
#if DEBUG
PrintToChatAll("L4D2_OnEndVersusModeRound_Post");
#endif
}
}
Action OnRoundEnd_Post(Handle hTimer)
{
g_hTransitionTimer = null;
//Check if map has been registered for a map transition
char sCurrentMapName[MAP_NAME_MAX_LENGTH], sNextMapName[MAP_NAME_MAX_LENGTH];
GetCurrentMapLower(sCurrentMapName, sizeof(sCurrentMapName));
//We have a map to transition to
if (g_hMapTransitionPair.GetString(sCurrentMapName, sNextMapName, sizeof(sNextMapName))) {
//Preserve scores between transitions
g_iPointsTeamA = L4D2Direct_GetVSCampaignScore(0);
g_iPointsTeamB = L4D2Direct_GetVSCampaignScore(1);
g_bHasTransitioned = true;
#if DEBUG
LogMessage("Map transitioned from: %s to: %s", sCurrentMapName, sNextMapName);
#endif
PrintToServer("[MT] Starting transition from: %s to: %s", sCurrentMapName, sNextMapName); // none of player can see PrintToChat text when changing map
L4D_RestartScenarioFromVote(sNextMapName); // Use this instead and c6m1 will spawn witch correctly
}
return Plugin_Stop;
}
public void OnMapEnd()
{
//In case map is force-chenged before custom transition takes place
if (g_hTransitionTimer != null) {
g_bHasTransitioned = false;
delete g_hTransitionTimer;
}
}
public void OnMapStart()
{
//Set scores after a modified transition
if (g_bHasTransitioned) {
CreateTimer(1.0, Timer_OnMapStartDelay, _, TIMER_FLAG_NO_MAPCHANGE); //Clients have issues connecting if team swap happens exactly on map start, so we delay it
g_bHasTransitioned = false;
}
}
Action Timer_OnMapStartDelay(Handle hTimer)
{
SetScores();
return Plugin_Stop;
}
void SetScores()
{
//If team B is winning, swap teams. Does not change how scores are set
if (g_iPointsTeamA < g_iPointsTeamB) {
L4D2_SwapTeams();
#if DEBUG
LogMessage("Teams swapped");
#endif
}
//Set actual scores
L4D2Direct_SetVSCampaignScore(0, g_iPointsTeamA);
L4D2Direct_SetVSCampaignScore(1, g_iPointsTeamB);
GameRules_SetProp("m_iCampaignScore", g_iPointsTeamA, _, 0);
GameRules_SetProp("m_iCampaignScore", g_iPointsTeamB, _, 1);
#if DEBUG
LogMessage("Set scores to: (Survivors) %i vs (Infected) %i", g_iPointsTeamA, g_iPointsTeamB);
#endif
}
Action AddMapTransition(int iArgs)
{
if (iArgs != 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 sMapStart[MAP_NAME_MAX_LENGTH], sMapEnd[MAP_NAME_MAX_LENGTH];
GetCmdArg(1, sMapStart, sizeof(sMapStart));
GetCmdArg(2, sMapEnd, sizeof(sMapEnd));
String_ToLower(sMapStart, sizeof(sMapStart));
String_ToLower(sMapEnd, sizeof(sMapEnd));
g_hMapTransitionPair.SetString(sMapStart, sMapEnd, true);
return Plugin_Handled;
}
int GetCurrentMapLower(char[] buffer, int maxlength)
{
int bytes = GetCurrentMap(buffer, maxlength);
if (bytes) String_ToLower(buffer, maxlength);
return bytes;
}