|
ds@1952
|
1 |
/** |
|
ds@1952
|
2 |
* vim: set ts=4 : |
|
ds@1952
|
3 |
* ============================================================================= |
|
ds@1952
|
4 |
* SourceMod Mapchooser Plugin |
|
ds@1952
|
5 |
* Creates a map vote at appropriate times, setting sm_nextmap to the winning |
|
ds@1952
|
6 |
* vote |
|
ds@1952
|
7 |
* |
|
pred@2032
|
8 |
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. |
|
ds@1952
|
9 |
* ============================================================================= |
|
ds@1952
|
10 |
* |
|
ds@1952
|
11 |
* This program is free software; you can redistribute it and/or modify it under |
|
ds@1952
|
12 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
ds@1952
|
13 |
* Free Software Foundation. |
|
ds@1952
|
14 |
* |
|
ds@1952
|
15 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
ds@1952
|
16 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
ds@1952
|
17 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
ds@1952
|
18 |
* details. |
|
ds@1952
|
19 |
* |
|
ds@1952
|
20 |
* You should have received a copy of the GNU General Public License along with |
|
ds@1952
|
21 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
ds@1952
|
22 |
* |
|
ds@1952
|
23 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
ds@1952
|
24 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
ds@1952
|
25 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
ds@1952
|
26 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
ds@1952
|
27 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
ds@1952
|
28 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
ds@1952
|
29 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
ds@1952
|
30 |
* or <http://www.sourcemod.net/license.php>. |
|
ds@1952
|
31 |
* |
|
ds@1952
|
32 |
* Version: $Id$ |
|
ds@1952
|
33 |
*/ |
|
ds@1952
|
34 |
|
|
ds@1952
|
35 |
#pragma semicolon 1 |
|
ds@1952
|
36 |
#include <sourcemod> |
|
ds@1952
|
37 |
|
|
ds@1952
|
38 |
public Plugin:myinfo = |
|
ds@1952
|
39 |
{ |
|
ds@1952
|
40 |
name = "MapChooser", |
|
ds@1952
|
41 |
author = "AlliedModders LLC", |
|
ds@1952
|
42 |
description = "Automated Map Voting", |
|
ds@1952
|
43 |
version = SOURCEMOD_VERSION, |
|
ds@1952
|
44 |
url = "http://www.sourcemod.net/" |
|
ds@1952
|
45 |
}; |
|
ds@1952
|
46 |
|
|
ds@1952
|
47 |
new Handle:g_Cvar_Winlimit = INVALID_HANDLE; |
|
ds@1952
|
48 |
new Handle:g_Cvar_Maxrounds = INVALID_HANDLE; |
|
ds@1952
|
49 |
new Handle:g_Cvar_Fraglimit = INVALID_HANDLE; |
|
ds@1952
|
50 |
|
|
ds@1952
|
51 |
new Handle:g_Cvar_Nextmap = INVALID_HANDLE; |
|
ds@1952
|
52 |
|
|
ds@1952
|
53 |
new Handle:g_Cvar_StartTime = INVALID_HANDLE; |
|
ds@1952
|
54 |
new Handle:g_Cvar_StartRounds = INVALID_HANDLE; |
|
ds@1952
|
55 |
new Handle:g_Cvar_StartFrags = INVALID_HANDLE; |
|
ds@1952
|
56 |
new Handle:g_Cvar_ExtendTimeStep = INVALID_HANDLE; |
|
ds@1952
|
57 |
new Handle:g_Cvar_ExtendRoundStep = INVALID_HANDLE; |
|
ds@1952
|
58 |
new Handle:g_Cvar_ExtendFragStep = INVALID_HANDLE; |
|
ds@1952
|
59 |
new Handle:g_Cvar_ExcludeMaps = INVALID_HANDLE; |
|
ds@1952
|
60 |
new Handle:g_Cvar_IncludeMaps = INVALID_HANDLE; |
|
ds@1952
|
61 |
new Handle:g_Cvar_NoVoteMode = INVALID_HANDLE; |
|
ds@1952
|
62 |
new Handle:g_Cvar_Extend = INVALID_HANDLE; |
|
ds@1952
|
63 |
|
|
ds@1952
|
64 |
new Handle:g_VoteTimer = INVALID_HANDLE; |
|
ds@1952
|
65 |
new Handle:g_RetryTimer = INVALID_HANDLE; |
|
ds@1952
|
66 |
|
|
ds@1952
|
67 |
new Handle:g_MapList = INVALID_HANDLE; |
|
ds@1952
|
68 |
new Handle:g_OldMapList = INVALID_HANDLE; |
|
ds@1952
|
69 |
new Handle:g_NextMapList = INVALID_HANDLE; |
|
ds@1952
|
70 |
new Handle:g_TeamScores = INVALID_HANDLE; |
|
ds@1952
|
71 |
new Handle:g_VoteMenu = INVALID_HANDLE; |
|
ds@1952
|
72 |
|
|
ds@1952
|
73 |
new g_Extends; |
|
ds@1952
|
74 |
new g_TotalRounds; |
|
ds@1952
|
75 |
new bool:g_HasVoteStarted; |
|
ds@1952
|
76 |
new g_mapFileSerial = -1; |
|
ds@1952
|
77 |
|
|
ds@1952
|
78 |
#define VOTE_EXTEND "##extend##" |
|
ds@1952
|
79 |
|
|
ds@1952
|
80 |
public OnPluginStart() |
|
ds@1952
|
81 |
{ |
|
ds@1952
|
82 |
LoadTranslations("mapchooser.phrases"); |
|
ds@1952
|
83 |
|
|
ds@1952
|
84 |
new arraySize = ByteCountToCells(33); |
|
ds@1952
|
85 |
g_MapList = CreateArray(arraySize); |
|
ds@1952
|
86 |
g_OldMapList = CreateArray(arraySize); |
|
ds@1952
|
87 |
g_NextMapList = CreateArray(arraySize); |
|
ds@1952
|
88 |
|
|
ds@1952
|
89 |
g_Cvar_StartTime = CreateConVar("sm_mapvote_start", "3.0", "Specifies when to start the vote based on time remaining.", _, true, 1.0); |
|
ds@1952
|
90 |
g_Cvar_StartRounds = CreateConVar("sm_mapvote_startround", "2.0", "Specifies when to start the vote based on rounds remaining.", _, true, 1.0); |
|
ds@1952
|
91 |
g_Cvar_StartFrags = CreateConVar("sm_mapvote_startfrags", "5.0", "Specifies when to start the vote base on frags remaining.", _, true, 1.0); |
|
ds@1952
|
92 |
g_Cvar_ExtendTimeStep = CreateConVar("sm_extendmap_timestep", "15", "Specifies how much many more minutes each extension makes", _, true, 5.0); |
|
ds@1952
|
93 |
g_Cvar_ExtendRoundStep = CreateConVar("sm_extendmap_roundstep", "5", "Specifies how many more rounds each extension makes", _, true, 5.0); |
|
ds@1952
|
94 |
g_Cvar_ExtendFragStep = CreateConVar("sm_extendmap_fragstep", "10", "Specifies how many more frags are allowed when map is extended.", _, true, 5.0); |
|
ds@1952
|
95 |
g_Cvar_ExcludeMaps = CreateConVar("sm_mapvote_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0); |
|
ds@1952
|
96 |
g_Cvar_IncludeMaps = CreateConVar("sm_mapvote_include", "5", "Specifies how many maps to include in the vote.", _, true, 2.0, true, 6.0); |
|
ds@1952
|
97 |
g_Cvar_NoVoteMode = CreateConVar("sm_mapvote_novote", "1", "Specifies whether or not MapChooser should pick a map if no votes are received.", _, true, 0.0, true, 1.0); |
|
ds@1952
|
98 |
g_Cvar_Extend = CreateConVar("sm_mapvote_extend", "0", "Number of extensions allowed each map.", _, true, 0.0); |
|
ds@1952
|
99 |
|
|
ds@1952
|
100 |
RegAdminCmd("sm_mapvote", Command_Mapvote, ADMFLAG_CHANGEMAP, "sm_mapvote - Forces MapChooser to attempt to run a map vote now."); |
|
ds@1952
|
101 |
|
|
ds@1952
|
102 |
g_Cvar_Winlimit = FindConVar("mp_winlimit"); |
|
ds@1952
|
103 |
g_Cvar_Maxrounds = FindConVar("mp_maxrounds"); |
|
ds@1952
|
104 |
g_Cvar_Fraglimit = FindConVar("mp_fraglimit"); |
|
ds@1952
|
105 |
|
|
ds@1952
|
106 |
if (g_Cvar_Winlimit != INVALID_HANDLE || g_Cvar_Maxrounds != INVALID_HANDLE) |
|
ds@1952
|
107 |
{ |
|
ds@1952
|
108 |
HookEvent("round_end", Event_RoundEnd); |
|
pred@2032
|
109 |
HookEventEx("teamplay_round_win", Event_TeamPlayRoundWin); |
|
ds@1952
|
110 |
} |
|
ds@1952
|
111 |
|
|
ds@1952
|
112 |
if (g_Cvar_Fraglimit != INVALID_HANDLE) |
|
ds@1952
|
113 |
{ |
|
ds@1952
|
114 |
HookEvent("player_death", Event_PlayerDeath); |
|
ds@1952
|
115 |
} |
|
ds@1952
|
116 |
|
|
ds@1952
|
117 |
AutoExecConfig(true, "mapchooser"); |
|
ds@1952
|
118 |
} |
|
ds@1952
|
119 |
|
|
ds@1952
|
120 |
public OnConfigsExecuted() |
|
ds@1952
|
121 |
{ |
|
ds@1952
|
122 |
g_Cvar_Nextmap = FindConVar("sm_nextmap"); |
|
ds@1952
|
123 |
|
|
ds@1952
|
124 |
if (g_Cvar_Nextmap == INVALID_HANDLE) |
|
ds@1952
|
125 |
{ |
|
ds@1952
|
126 |
LogError("FATAL: Cannot find sm_nextmap cvar. Mapchooser not loaded."); |
|
ds@1952
|
127 |
SetFailState("sm_nextmap not found"); |
|
ds@1952
|
128 |
} |
|
ds@1952
|
129 |
|
|
ds@1952
|
130 |
if (ReadMapList(g_MapList, |
|
ds@1952
|
131 |
g_mapFileSerial, |
|
ds@1952
|
132 |
"mapchooser", |
|
ds@1952
|
133 |
MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER) |
|
ds@1952
|
134 |
!= INVALID_HANDLE) |
|
ds@1952
|
135 |
|
|
ds@1952
|
136 |
{ |
|
ds@1952
|
137 |
if (g_mapFileSerial == -1) |
|
ds@1952
|
138 |
{ |
|
ds@1952
|
139 |
LogError("Unable to create a valid map list."); |
|
ds@1952
|
140 |
} |
|
ds@1952
|
141 |
} |
|
ds@1952
|
142 |
|
|
ds@1952
|
143 |
CreateNextVote(); |
|
ds@1952
|
144 |
SetupTimeleftTimer(); |
|
ds@1952
|
145 |
SetConVarString(g_Cvar_Nextmap, "Pending Vote"); |
|
ds@1952
|
146 |
|
|
ds@1952
|
147 |
if (g_TeamScores != INVALID_HANDLE) |
|
ds@1952
|
148 |
{ |
|
ds@1952
|
149 |
CloseHandle(g_TeamScores); |
|
ds@1952
|
150 |
} |
|
ds@1952
|
151 |
|
|
ds@1952
|
152 |
g_TeamScores = CreateArray(2); |
|
ds@1952
|
153 |
g_TotalRounds = 0; |
|
ds@1952
|
154 |
|
|
ds@1952
|
155 |
g_Extends = 0; |
|
ds@1952
|
156 |
} |
|
ds@1952
|
157 |
|
|
ds@1952
|
158 |
public OnMapEnd() |
|
ds@1952
|
159 |
{ |
|
ds@1952
|
160 |
g_HasVoteStarted = false; |
|
ds@1952
|
161 |
|
|
ds@1952
|
162 |
if (g_VoteTimer != INVALID_HANDLE) |
|
ds@1952
|
163 |
{ |
|
ds@1952
|
164 |
KillTimer(g_VoteTimer); |
|
ds@1952
|
165 |
g_VoteTimer = INVALID_HANDLE; |
|
ds@1952
|
166 |
} |
|
ds@1952
|
167 |
|
|
ds@1952
|
168 |
if (g_RetryTimer != INVALID_HANDLE) |
|
ds@1952
|
169 |
{ |
|
ds@1952
|
170 |
KillTimer(g_RetryTimer); |
|
ds@1952
|
171 |
g_RetryTimer = INVALID_HANDLE; |
|
ds@1952
|
172 |
} |
|
ds@1952
|
173 |
} |
|
ds@1952
|
174 |
|
|
ds@1952
|
175 |
public OnMapTimeLeftChanged() |
|
ds@1952
|
176 |
{ |
|
ds@1952
|
177 |
if (GetArraySize(g_MapList)) |
|
ds@1952
|
178 |
{ |
|
ds@1952
|
179 |
SetupTimeleftTimer(); |
|
ds@1952
|
180 |
} |
|
ds@1952
|
181 |
} |
|
ds@1952
|
182 |
|
|
ds@1952
|
183 |
SetupTimeleftTimer() |
|
ds@1952
|
184 |
{ |
|
ds@1952
|
185 |
new time; |
|
ds@1952
|
186 |
if (GetMapTimeLeft(time) && time > 0) |
|
ds@1952
|
187 |
{ |
|
ds@1952
|
188 |
new startTime = GetConVarInt(g_Cvar_StartTime) * 60; |
|
ds@1952
|
189 |
if (time - startTime < 0) |
|
ds@1952
|
190 |
{ |
|
ds@1952
|
191 |
InitiateVote(); |
|
ds@1952
|
192 |
} |
|
ds@1952
|
193 |
else |
|
ds@1952
|
194 |
{ |
|
ds@1952
|
195 |
if (g_VoteTimer != INVALID_HANDLE) |
|
ds@1952
|
196 |
{ |
|
ds@1952
|
197 |
KillTimer(g_VoteTimer); |
|
ds@1952
|
198 |
g_VoteTimer = INVALID_HANDLE; |
|
ds@1952
|
199 |
} |
|
ds@1952
|
200 |
|
|
ds@1952
|
201 |
g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVote); |
|
ds@1952
|
202 |
} |
|
ds@1952
|
203 |
} |
|
ds@1952
|
204 |
} |
|
ds@1952
|
205 |
|
|
ds@1952
|
206 |
public Action:Timer_StartMapVote(Handle:timer) |
|
ds@1952
|
207 |
{ |
|
ds@1952
|
208 |
if (!GetArraySize(g_MapList)) |
|
ds@1952
|
209 |
{ |
|
ds@1952
|
210 |
return Plugin_Stop; |
|
ds@1952
|
211 |
} |
|
ds@1952
|
212 |
|
|
ds@1952
|
213 |
if (timer == g_RetryTimer) |
|
ds@1952
|
214 |
{ |
|
ds@1952
|
215 |
g_RetryTimer = INVALID_HANDLE; |
|
ds@1952
|
216 |
} |
|
ds@1952
|
217 |
else |
|
ds@1952
|
218 |
{ |
|
ds@1952
|
219 |
g_VoteTimer = INVALID_HANDLE; |
|
ds@1952
|
220 |
} |
|
ds@1952
|
221 |
|
|
ds@1952
|
222 |
InitiateVote(); |
|
ds@1952
|
223 |
|
|
ds@1952
|
224 |
return Plugin_Stop; |
|
ds@1952
|
225 |
} |
|
ds@1952
|
226 |
|
|
pred@2032
|
227 |
public Event_TeamPlayRoundWin(Handle:event, const String:name[], bool:dontBroadcast) |
|
pred@2032
|
228 |
{ |
|
pred@2032
|
229 |
new isFull = GetEventInt(event, "full_round"); |
|
pred@2032
|
230 |
new winningTeam = GetEventInt(event, "team"); |
|
pred@2032
|
231 |
|
|
pred@2032
|
232 |
if (isFull == 1) |
|
pred@2032
|
233 |
{ |
|
pred@2032
|
234 |
RoundCompleted(winningTeam); |
|
pred@2032
|
235 |
} |
|
pred@2032
|
236 |
} |
|
ds@1952
|
237 |
/* You ask, why don't you just use team_score event? And I answer... Because CSS doesn't. */ |
|
ds@1952
|
238 |
public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast) |
|
ds@1952
|
239 |
{ |
|
ds@1952
|
240 |
if (!GetArraySize(g_MapList) || g_HasVoteStarted) |
|
ds@1952
|
241 |
{ |
|
ds@1952
|
242 |
return; |
|
ds@1952
|
243 |
} |
|
ds@1952
|
244 |
|
|
ds@1952
|
245 |
new winner = GetEventInt(event, "winner"); |
|
ds@1952
|
246 |
|
|
pred@2032
|
247 |
RoundCompleted(winner); |
|
pred@2032
|
248 |
} |
|
pred@2032
|
249 |
|
|
pred@2032
|
250 |
public RoundCompleted(winner) |
|
pred@2032
|
251 |
{ |
|
ds@1952
|
252 |
if (winner == 0 || winner == 1) |
|
ds@1952
|
253 |
{ |
|
ds@1952
|
254 |
return; |
|
ds@1952
|
255 |
} |
|
ds@1952
|
256 |
|
|
ds@1952
|
257 |
g_TotalRounds++; |
|
ds@1952
|
258 |
|
|
ds@1952
|
259 |
new team[2], teamPos = -1; |
|
ds@1952
|
260 |
for (new i; i < GetArraySize(g_TeamScores); i++) |
|
ds@1952
|
261 |
{ |
|
ds@1952
|
262 |
GetArrayArray(g_TeamScores, i, team); |
|
ds@1952
|
263 |
if (team[0] == winner) |
|
ds@1952
|
264 |
{ |
|
ds@1952
|
265 |
teamPos = i; |
|
ds@1952
|
266 |
break; |
|
ds@1952
|
267 |
} |
|
ds@1952
|
268 |
} |
|
ds@1952
|
269 |
|
|
ds@1952
|
270 |
if (teamPos == -1) |
|
ds@1952
|
271 |
{ |
|
ds@1952
|
272 |
team[0] = winner; |
|
ds@1952
|
273 |
team[1] = 1; |
|
ds@1952
|
274 |
PushArrayArray(g_TeamScores, team); |
|
ds@1952
|
275 |
} |
|
ds@1952
|
276 |
else |
|
ds@1952
|
277 |
{ |
|
ds@1952
|
278 |
team[1]++; |
|
ds@1952
|
279 |
SetArrayArray(g_TeamScores, teamPos, team); |
|
ds@1952
|
280 |
} |
|
ds@1952
|
281 |
|
|
ds@1952
|
282 |
if (g_Cvar_Winlimit != INVALID_HANDLE) |
|
ds@1952
|
283 |
{ |
|
ds@1952
|
284 |
new winlimit = GetConVarInt(g_Cvar_Winlimit); |
|
ds@1952
|
285 |
if (winlimit) |
|
ds@1952
|
286 |
{ |
|
ds@1952
|
287 |
if (team[1] >= (winlimit - GetConVarInt(g_Cvar_StartRounds))) |
|
ds@1952
|
288 |
{ |
|
ds@1952
|
289 |
InitiateVote(); |
|
ds@1952
|
290 |
} |
|
ds@1952
|
291 |
} |
|
ds@1952
|
292 |
} |
|
ds@1952
|
293 |
|
|
ds@1952
|
294 |
if (g_Cvar_Maxrounds != INVALID_HANDLE) |
|
ds@1952
|
295 |
{ |
|
ds@1952
|
296 |
new maxrounds = GetConVarInt(g_Cvar_Maxrounds); |
|
ds@1952
|
297 |
if (maxrounds) |
|
ds@1952
|
298 |
{ |
|
ds@1952
|
299 |
if (g_TotalRounds >= (maxrounds - GetConVarInt(g_Cvar_StartRounds))) |
|
ds@1952
|
300 |
{ |
|
ds@1952
|
301 |
InitiateVote(); |
|
ds@1952
|
302 |
} |
|
ds@1952
|
303 |
} |
|
ds@1952
|
304 |
} |
|
ds@1952
|
305 |
} |
|
ds@1952
|
306 |
|
|
ds@1952
|
307 |
public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast) |
|
ds@1952
|
308 |
{ |
|
ds@1952
|
309 |
if (!GetArraySize(g_MapList) || g_Cvar_Fraglimit == INVALID_HANDLE || g_HasVoteStarted) |
|
ds@1952
|
310 |
{ |
|
ds@1952
|
311 |
return; |
|
ds@1952
|
312 |
} |
|
ds@1952
|
313 |
|
|
ds@1952
|
314 |
if (!GetConVarInt(g_Cvar_Fraglimit)) |
|
ds@1952
|
315 |
{ |
|
ds@1952
|
316 |
return; |
|
ds@1952
|
317 |
} |
|
ds@1952
|
318 |
|
|
ds@1952
|
319 |
new fragger = GetClientOfUserId(GetEventInt(event, "attacker")); |
|
ds@1952
|
320 |
if (fragger && GetClientFrags(fragger) >= (GetConVarInt(g_Cvar_Fraglimit) - GetConVarInt(g_Cvar_StartFrags))) |
|
ds@1952
|
321 |
{ |
|
ds@1952
|
322 |
InitiateVote(); |
|
ds@1952
|
323 |
} |
|
ds@1952
|
324 |
} |
|
ds@1952
|
325 |
|
|
ds@1952
|
326 |
public Action:Command_Mapvote(client, args) |
|
ds@1952
|
327 |
{ |
|
ds@1952
|
328 |
InitiateVote(); |
|
ds@1952
|
329 |
|
|
ds@1952
|
330 |
return Plugin_Handled; |
|
ds@1952
|
331 |
} |
|
ds@1952
|
332 |
|
|
ds@1952
|
333 |
InitiateVote() |
|
ds@1952
|
334 |
{ |
|
ds@1952
|
335 |
if (g_HasVoteStarted || g_RetryTimer != INVALID_HANDLE) |
|
ds@1952
|
336 |
{ |
|
ds@1952
|
337 |
return; |
|
ds@1952
|
338 |
} |
|
ds@1952
|
339 |
|
|
ds@1952
|
340 |
if (IsVoteInProgress()) |
|
ds@1952
|
341 |
{ |
|
ds@1952
|
342 |
// Can't start a vote, try again in 5 seconds. |
|
ds@1952
|
343 |
g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote); |
|
ds@1952
|
344 |
return; |
|
ds@1952
|
345 |
} |
|
ds@1952
|
346 |
|
|
ds@1952
|
347 |
g_HasVoteStarted = true; |
|
ds@1952
|
348 |
g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MenuAction:MENU_ACTIONS_ALL); |
|
ds@1952
|
349 |
SetMenuTitle(g_VoteMenu, "Vote Nextmap"); |
|
ds@1952
|
350 |
|
|
ds@1952
|
351 |
decl String:map[32]; |
|
ds@1952
|
352 |
for (new i = 0; i < GetArraySize(g_NextMapList); i++) |
|
ds@1952
|
353 |
{ |
|
ds@1952
|
354 |
GetArrayString(g_NextMapList, i, map, sizeof(map)); |
|
ds@1952
|
355 |
AddMenuItem(g_VoteMenu, map, map); |
|
ds@1952
|
356 |
} |
|
ds@1952
|
357 |
|
|
ds@1952
|
358 |
if (GetConVarBool(g_Cvar_Extend) && g_Extends < GetConVarInt(g_Cvar_Extend)) |
|
ds@1952
|
359 |
{ |
|
ds@1952
|
360 |
AddMenuItem(g_VoteMenu, VOTE_EXTEND, "Extend Map"); |
|
ds@1952
|
361 |
} |
|
ds@1952
|
362 |
|
|
ds@1952
|
363 |
SetMenuExitButton(g_VoteMenu, false); |
|
ds@1952
|
364 |
VoteMenuToAll(g_VoteMenu, 20); |
|
ds@1952
|
365 |
|
|
ds@1952
|
366 |
LogMessage("Voting for next map has started."); |
|
ds@1952
|
367 |
PrintToChatAll("[SM] %t", "Nextmap Voting Started"); |
|
ds@1952
|
368 |
} |
|
ds@1952
|
369 |
|
|
ds@1952
|
370 |
public Handler_MapVoteMenu(Handle:menu, MenuAction:action, param1, param2) |
|
ds@1952
|
371 |
{ |
|
ds@1952
|
372 |
switch (action) |
|
ds@1952
|
373 |
{ |
|
ds@1952
|
374 |
case MenuAction_End: |
|
ds@1952
|
375 |
{ |
|
ds@1952
|
376 |
g_VoteMenu = INVALID_HANDLE; |
|
ds@1952
|
377 |
CloseHandle(menu); |
|
ds@1952
|
378 |
} |
|
ds@1952
|
379 |
|
|
ds@1952
|
380 |
case MenuAction_Display: |
|
ds@1952
|
381 |
{ |
|
ds@1952
|
382 |
decl String:buffer[255]; |
|
ds@1952
|
383 |
Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1); |
|
ds@1952
|
384 |
|
|
ds@1952
|
385 |
new Handle:panel = Handle:param2; |
|
ds@1952
|
386 |
SetPanelTitle(panel, buffer); |
|
ds@1952
|
387 |
} |
|
ds@1952
|
388 |
|
|
ds@1952
|
389 |
case MenuAction_DisplayItem: |
|
ds@1952
|
390 |
{ |
|
ds@1952
|
391 |
if (GetMenuItemCount(menu) - 1 == param2) |
|
ds@1952
|
392 |
{ |
|
ds@1952
|
393 |
decl String:map[64], String:buffer[255]; |
|
ds@1952
|
394 |
GetMenuItem(menu, param2, map, sizeof(map)); |
|
ds@1952
|
395 |
if (strcmp(map, VOTE_EXTEND, false) == 0) |
|
ds@1952
|
396 |
{ |
|
ds@1952
|
397 |
Format(buffer, sizeof(buffer), "%T", "Extend Map", param1); |
|
ds@1952
|
398 |
return RedrawMenuItem(buffer); |
|
ds@1952
|
399 |
} |
|
ds@1952
|
400 |
} |
|
ds@1952
|
401 |
} |
|
ds@1952
|
402 |
|
|
ds@1952
|
403 |
// Why am I commented out? Because BAIL hasn't decided yet if |
|
ds@1952
|
404 |
// vote notification will be built into the Vote API. |
|
ds@1952
|
405 |
/*case MenuAction_Select: |
|
ds@1952
|
406 |
{ |
|
ds@1952
|
407 |
decl String:Name[32], String:Map[32]; |
|
ds@1952
|
408 |
GetClientName(param1, Name, sizeof(Name)); |
|
ds@1952
|
409 |
GetMenuItem(menu, param2, Map, sizeof(Map)); |
|
ds@1952
|
410 |
|
|
ds@1952
|
411 |
PrintToChatAll("[SM] %s has voted for map '%s'", Name, Map); |
|
ds@1952
|
412 |
}*/ |
|
ds@1952
|
413 |
|
|
ds@1952
|
414 |
case MenuAction_VoteCancel: |
|
ds@1952
|
415 |
{ |
|
ds@1952
|
416 |
// If we receive 0 votes, pick at random. |
|
ds@1952
|
417 |
if (param1 == VoteCancel_NoVotes && GetConVarBool(g_Cvar_NoVoteMode)) |
|
ds@1952
|
418 |
{ |
|
ds@1952
|
419 |
new count = GetMenuItemCount(menu); |
|
ds@1952
|
420 |
new item = GetRandomInt(0, count - 1); |
|
ds@1952
|
421 |
decl String:map[32]; |
|
ds@1952
|
422 |
GetMenuItem(menu, item, map, sizeof(map)); |
|
ds@1952
|
423 |
|
|
ds@1952
|
424 |
while (strcmp(map, VOTE_EXTEND, false) == 0) |
|
ds@1952
|
425 |
{ |
|
ds@1952
|
426 |
item = GetRandomInt(0, count - 1); |
|
ds@1952
|
427 |
GetMenuItem(menu, item, map, sizeof(map)); |
|
ds@1952
|
428 |
} |
|
ds@1952
|
429 |
|
|
ds@1952
|
430 |
SetNextMap(map); |
|
ds@1952
|
431 |
} |
|
ds@1952
|
432 |
else |
|
ds@1952
|
433 |
{ |
|
ds@1952
|
434 |
// We were actually cancelled. What should we do? |
|
ds@1952
|
435 |
} |
|
ds@1952
|
436 |
} |
|
ds@1952
|
437 |
|
|
ds@1952
|
438 |
case MenuAction_VoteEnd: |
|
ds@1952
|
439 |
{ |
|
ds@1952
|
440 |
decl String:map[32]; |
|
ds@1952
|
441 |
GetMenuItem(menu, param1, map, sizeof(map)); |
|
ds@1952
|
442 |
|
|
ds@1952
|
443 |
if (strcmp(map, VOTE_EXTEND, false) == 0) |
|
ds@1952
|
444 |
{ |
|
ds@1952
|
445 |
g_Extends++; |
|
ds@1952
|
446 |
|
|
ds@1952
|
447 |
new time; |
|
ds@1952
|
448 |
if (GetMapTimeLimit(time)) |
|
ds@1952
|
449 |
{ |
|
ds@1952
|
450 |
if (time > 0) |
|
ds@1952
|
451 |
{ |
|
ds@1952
|
452 |
ExtendMapTimeLimit(GetConVarInt(g_Cvar_ExtendTimeStep)*60); |
|
ds@1952
|
453 |
} |
|
ds@1952
|
454 |
} |
|
ds@1952
|
455 |
|
|
ds@1952
|
456 |
if (g_Cvar_Winlimit != INVALID_HANDLE) |
|
ds@1952
|
457 |
{ |
|
ds@1952
|
458 |
new winlimit = GetConVarInt(g_Cvar_Winlimit); |
|
ds@1952
|
459 |
if (winlimit) |
|
ds@1952
|
460 |
{ |
|
ds@1952
|
461 |
SetConVarInt(g_Cvar_Winlimit, winlimit + GetConVarInt(g_Cvar_ExtendRoundStep)); |
|
ds@1952
|
462 |
} |
|
ds@1952
|
463 |
} |
|
ds@1952
|
464 |
|
|
ds@1952
|
465 |
if (g_Cvar_Maxrounds != INVALID_HANDLE) |
|
ds@1952
|
466 |
{ |
|
ds@1952
|
467 |
new maxrounds = GetConVarInt(g_Cvar_Maxrounds); |
|
ds@1952
|
468 |
if (maxrounds) |
|
ds@1952
|
469 |
{ |
|
ds@1952
|
470 |
SetConVarInt(g_Cvar_Maxrounds, maxrounds + GetConVarInt(g_Cvar_ExtendRoundStep)); |
|
ds@1952
|
471 |
} |
|
ds@1952
|
472 |
} |
|
ds@1952
|
473 |
|
|
ds@1952
|
474 |
if (g_Cvar_Fraglimit != INVALID_HANDLE) |
|
ds@1952
|
475 |
{ |
|
ds@1952
|
476 |
new fraglimit = GetConVarInt(g_Cvar_Fraglimit); |
|
ds@1952
|
477 |
if (fraglimit) |
|
ds@1952
|
478 |
{ |
|
ds@1952
|
479 |
SetConVarInt(g_Cvar_Fraglimit, fraglimit + GetConVarInt(g_Cvar_ExtendFragStep)); |
|
ds@1952
|
480 |
} |
|
ds@1952
|
481 |
} |
|
ds@1952
|
482 |
|
|
ds@1952
|
483 |
PrintToChatAll("[SM] %t", "Current Map Extended"); |
|
ds@1952
|
484 |
LogMessage("Voting for next map has finished. The current map has been extended."); |
|
ds@1952
|
485 |
|
|
ds@1952
|
486 |
// We extended, so we'll have to vote again. |
|
ds@1952
|
487 |
g_HasVoteStarted = false; |
|
ds@1952
|
488 |
CreateNextVote(); |
|
ds@1952
|
489 |
SetupTimeleftTimer(); |
|
ds@1952
|
490 |
} |
|
ds@1952
|
491 |
else |
|
ds@1952
|
492 |
{ |
|
ds@1952
|
493 |
SetNextMap(map); |
|
ds@1952
|
494 |
} |
|
ds@1952
|
495 |
} |
|
ds@1952
|
496 |
} |
|
ds@1952
|
497 |
|
|
ds@1952
|
498 |
return 0; |
|
ds@1952
|
499 |
} |
|
ds@1952
|
500 |
|
|
ds@1952
|
501 |
SetNextMap(const String:map[]) |
|
ds@1952
|
502 |
{ |
|
ds@1952
|
503 |
SetConVarString(g_Cvar_Nextmap, map); |
|
ds@1952
|
504 |
PushArrayString(g_OldMapList, map); |
|
ds@1952
|
505 |
|
|
ds@1952
|
506 |
if (GetArraySize(g_OldMapList) > GetConVarInt(g_Cvar_ExcludeMaps)) |
|
ds@1952
|
507 |
{ |
|
ds@1952
|
508 |
RemoveFromArray(g_OldMapList, 0); |
|
ds@1952
|
509 |
} |
|
ds@1952
|
510 |
|
|
ds@1952
|
511 |
PrintToChatAll("[SM] %t", "Nextmap Voting Finished", map); |
|
ds@1952
|
512 |
LogMessage("Voting for next map has finished. Nextmap: %s.", map); |
|
ds@1952
|
513 |
} |
|
ds@1952
|
514 |
|
|
ds@1952
|
515 |
CreateNextVote() |
|
ds@1952
|
516 |
{ |
|
ds@1952
|
517 |
if(g_NextMapList != INVALID_HANDLE) |
|
ds@1952
|
518 |
{ |
|
ds@1952
|
519 |
ClearArray(g_NextMapList); |
|
ds@1952
|
520 |
} |
|
ds@1952
|
521 |
|
|
ds@1952
|
522 |
decl String:map[32]; |
|
ds@1952
|
523 |
new index, Handle:tempMaps = CloneArray(g_MapList); |
|
ds@1952
|
524 |
|
|
ds@1952
|
525 |
GetCurrentMap(map, sizeof(map)); |
|
ds@1952
|
526 |
index = FindStringInArray(tempMaps, map); |
|
ds@1952
|
527 |
if (index != -1) |
|
ds@1952
|
528 |
{ |
|
ds@1952
|
529 |
RemoveFromArray(tempMaps, index); |
|
ds@1952
|
530 |
} |
|
ds@1952
|
531 |
|
|
ds@1952
|
532 |
if (GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps)) |
|
ds@1952
|
533 |
{ |
|
ds@1952
|
534 |
for (new i = 0; i < GetArraySize(g_OldMapList); i++) |
|
ds@1952
|
535 |
{ |
|
ds@1952
|
536 |
GetArrayString(g_OldMapList, i, map, sizeof(map)); |
|
ds@1952
|
537 |
index = FindStringInArray(tempMaps, map); |
|
ds@1952
|
538 |
if (index != -1) |
|
ds@1952
|
539 |
{ |
|
ds@1952
|
540 |
RemoveFromArray(tempMaps, index); |
|
ds@1952
|
541 |
} |
|
ds@1952
|
542 |
} |
|
ds@1952
|
543 |
} |
|
ds@1952
|
544 |
|
|
ds@1952
|
545 |
new limit = (GetConVarInt(g_Cvar_IncludeMaps) < GetArraySize(tempMaps) ? GetConVarInt(g_Cvar_IncludeMaps) : GetArraySize(tempMaps)); |
|
ds@1952
|
546 |
for (new i = 0; i < limit; i++) |
|
ds@1952
|
547 |
{ |
|
ds@1952
|
548 |
new b = GetRandomInt(0, GetArraySize(tempMaps) - 1); |
|
ds@1952
|
549 |
GetArrayString(tempMaps, b, map, sizeof(map)); |
|
ds@1952
|
550 |
PushArrayString(g_NextMapList, map); |
|
ds@1952
|
551 |
RemoveFromArray(tempMaps, b); |
|
ds@1952
|
552 |
} |
|
ds@1952
|
553 |
|
|
ds@1952
|
554 |
CloseHandle(tempMaps); |
|
ds@1952
|
555 |
} |