|
pred@2133
|
1 |
/** |
|
pred@2133
|
2 |
* vim: set ts=4 : |
|
pred@2133
|
3 |
* ============================================================================= |
|
pred@2133
|
4 |
* SourceMod Rock The Vote Plugin |
|
pred@2133
|
5 |
* Creates a map vote when the required number of players have requested one. |
|
pred@2133
|
6 |
* |
|
pred@2133
|
7 |
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. |
|
pred@2133
|
8 |
* ============================================================================= |
|
pred@2133
|
9 |
* |
|
pred@2133
|
10 |
* This program is free software; you can redistribute it and/or modify it under |
|
pred@2133
|
11 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
pred@2133
|
12 |
* Free Software Foundation. |
|
pred@2133
|
13 |
* |
|
pred@2133
|
14 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
pred@2133
|
15 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
pred@2133
|
16 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
pred@2133
|
17 |
* details. |
|
pred@2133
|
18 |
* |
|
pred@2133
|
19 |
* You should have received a copy of the GNU General Public License along with |
|
pred@2133
|
20 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
pred@2133
|
21 |
* |
|
pred@2133
|
22 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
pred@2133
|
23 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
pred@2133
|
24 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
pred@2133
|
25 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
pred@2133
|
26 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
pred@2133
|
27 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
pred@2133
|
28 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
pred@2133
|
29 |
* or <http://www.sourcemod.net/license.php>. |
|
pred@2133
|
30 |
* |
|
pred@2133
|
31 |
* Version: $Id$ |
|
pred@2133
|
32 |
*/ |
|
pred@2133
|
33 |
|
|
pred@2133
|
34 |
#include <sourcemod> |
|
pred@2133
|
35 |
#include <mapchooser> |
|
pred@2133
|
36 |
|
|
pred@2133
|
37 |
#pragma semicolon 1 |
|
pred@2133
|
38 |
|
|
pred@2133
|
39 |
public Plugin:myinfo = |
|
pred@2133
|
40 |
{ |
|
pred@2133
|
41 |
name = "Map Nominations", |
|
pred@2133
|
42 |
author = "AlliedModders LLC", |
|
pred@2133
|
43 |
description = "Provides Map Nominations", |
|
pred@2133
|
44 |
version = SOURCEMOD_VERSION, |
|
pred@2133
|
45 |
url = "http://www.sourcemod.net/" |
|
pred@2133
|
46 |
}; |
|
pred@2133
|
47 |
|
|
pred@2133
|
48 |
new Handle:g_Cvar_ExcludeOld = INVALID_HANDLE; |
|
pred@2133
|
49 |
new Handle:g_Cvar_ExcludeCurrent = INVALID_HANDLE; |
|
pred@2133
|
50 |
|
|
pred@2133
|
51 |
new Handle:g_MapList = INVALID_HANDLE; |
|
pred@2133
|
52 |
new Handle:g_MapMenu = INVALID_HANDLE; |
|
pred@2133
|
53 |
new g_mapFileSerial = -1; |
|
pred@2133
|
54 |
|
|
pred@2133
|
55 |
public OnPluginStart() |
|
pred@2133
|
56 |
{ |
|
pred@2133
|
57 |
LoadTranslations("common.phrases"); |
|
pred@2133
|
58 |
LoadTranslations("nominations.phrases"); |
|
pred@2133
|
59 |
|
|
pred@2133
|
60 |
new arraySize = ByteCountToCells(33); |
|
pred@2133
|
61 |
g_MapList = CreateArray(arraySize); |
|
pred@2133
|
62 |
|
|
pred@2133
|
63 |
g_Cvar_ExcludeOld = CreateConVar("sm_nominate_excludeold", "1", "Specifies if the current map should be excluded from the Nominations list", 0, true, 0.00, true, 1.0); |
|
pred@2133
|
64 |
g_Cvar_ExcludeCurrent = CreateConVar("sm_nominate_excludecurrent", "1", "Specifies if the MapChooser excluded maps should also be excluded from Nominations", 0, true, 0.00, true, 1.0); |
|
pred@2133
|
65 |
|
|
pred@2133
|
66 |
RegConsoleCmd("say", Command_Say); |
|
pred@2133
|
67 |
RegConsoleCmd("say_team", Command_Say); |
|
pred@2133
|
68 |
|
|
pred@2133
|
69 |
RegConsoleCmd("sm_nominate", Command_Nominate); |
|
pred@2133
|
70 |
|
|
pred@2133
|
71 |
RegAdminCmd("sm_nominate_addmap", Command_Addmap, ADMFLAG_CHANGEMAP, "sm_nominate_addmap <mapname> - Forces a map to be on the next mapvote."); |
|
pred@2133
|
72 |
} |
|
pred@2133
|
73 |
|
|
pred@2133
|
74 |
public OnConfigsExecuted() |
|
pred@2133
|
75 |
{ |
|
pred@2133
|
76 |
if (ReadMapList(g_MapList, |
|
pred@2133
|
77 |
g_mapFileSerial, |
|
pred@2133
|
78 |
"nominations", |
|
pred@2133
|
79 |
MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER) |
|
pred@2133
|
80 |
== INVALID_HANDLE) |
|
pred@2133
|
81 |
{ |
|
pred@2133
|
82 |
if (g_mapFileSerial == -1) |
|
pred@2133
|
83 |
{ |
|
pred@2133
|
84 |
SetFailState("Unable to create a valid map list."); |
|
pred@2133
|
85 |
} |
|
pred@2133
|
86 |
} |
|
pred@2133
|
87 |
|
|
pred@2133
|
88 |
BuildMapMenu(); |
|
pred@2133
|
89 |
} |
|
pred@2133
|
90 |
|
|
pred@2344
|
91 |
public OnNominationRemoved(String:map[], owner) |
|
pred@2133
|
92 |
{ |
|
pred@2344
|
93 |
AddMenuItem(g_MapMenu, map, map); |
|
pred@2133
|
94 |
} |
|
pred@2133
|
95 |
|
|
pred@2133
|
96 |
public Action:Command_Addmap(client, args) |
|
pred@2133
|
97 |
{ |
|
pred@2133
|
98 |
if (args < 1) |
|
pred@2133
|
99 |
{ |
|
pred@2133
|
100 |
ReplyToCommand(client, "[SM] Usage: sm_nominate_addmap <mapname>"); |
|
pred@2133
|
101 |
return Plugin_Handled; |
|
pred@2133
|
102 |
} |
|
pred@2133
|
103 |
|
|
pred@2133
|
104 |
decl String:mapname[64]; |
|
pred@2133
|
105 |
GetCmdArg(1, mapname, sizeof(mapname)); |
|
pred@2133
|
106 |
|
|
pred@2344
|
107 |
if (FindStringInArray(g_MapList, mapname) == -1) |
|
pred@2133
|
108 |
{ |
|
pred@2133
|
109 |
ReplyToCommand(client, "%t", "Map was not found", mapname); |
|
pred@2344
|
110 |
return Plugin_Handled; |
|
pred@2133
|
111 |
} |
|
pred@2133
|
112 |
|
|
pred@2133
|
113 |
new NominateResult:result = NominateMap(mapname, true, 0); |
|
pred@2133
|
114 |
|
|
pred@2133
|
115 |
if (result > Nominate_Replaced) |
|
pred@2133
|
116 |
{ |
|
pred@2133
|
117 |
/* We assume already in vote is the casue because the maplist does a Map Validity check and we forced, so it can't be full */ |
|
pred@2133
|
118 |
ReplyToCommand(client, "%t", "Map Already In Vote", mapname); |
|
pred@2133
|
119 |
|
|
pred@2133
|
120 |
return Plugin_Handled; |
|
pred@2133
|
121 |
} |
|
pred@2133
|
122 |
|
|
pred@2344
|
123 |
decl String:item[64]; |
|
pred@2344
|
124 |
for (new i = 0; i < GetMenuItemCount(g_MapMenu); i++) |
|
pred@2344
|
125 |
{ |
|
pred@2344
|
126 |
GetMenuItem(g_MapMenu, i, item, sizeof(item)); |
|
pred@2344
|
127 |
if (strcmp(item, mapname) == 0) |
|
pred@2344
|
128 |
{ |
|
pred@2344
|
129 |
RemoveMenuItem(g_MapMenu, i); |
|
pred@2344
|
130 |
break; |
|
pred@2344
|
131 |
} |
|
pred@2344
|
132 |
} |
|
pred@2133
|
133 |
|
|
pred@2133
|
134 |
ReplyToCommand(client, "%t", "Map Inserted", mapname); |
|
pred@2133
|
135 |
LogAction(client, -1, "\"%L\" inserted map \"%s\".", client, mapname); |
|
pred@2133
|
136 |
|
|
pred@2133
|
137 |
return Plugin_Handled; |
|
pred@2133
|
138 |
} |
|
pred@2133
|
139 |
|
|
pred@2133
|
140 |
public Action:Command_Say(client, args) |
|
pred@2133
|
141 |
{ |
|
pred@2133
|
142 |
if (!client) |
|
pred@2133
|
143 |
{ |
|
pred@2133
|
144 |
return Plugin_Continue; |
|
pred@2133
|
145 |
} |
|
pred@2133
|
146 |
|
|
pred@2133
|
147 |
decl String:text[192]; |
|
pred@2133
|
148 |
if (!GetCmdArgString(text, sizeof(text))) |
|
pred@2133
|
149 |
{ |
|
pred@2133
|
150 |
return Plugin_Continue; |
|
pred@2133
|
151 |
} |
|
pred@2133
|
152 |
|
|
pred@2133
|
153 |
new startidx = 0; |
|
pred@2133
|
154 |
if(text[strlen(text)-1] == '"') |
|
pred@2133
|
155 |
{ |
|
pred@2133
|
156 |
text[strlen(text)-1] = '\0'; |
|
pred@2133
|
157 |
startidx = 1; |
|
pred@2133
|
158 |
} |
|
pred@2133
|
159 |
|
|
pred@2133
|
160 |
new ReplySource:old = SetCmdReplySource(SM_REPLY_TO_CHAT); |
|
pred@2133
|
161 |
|
|
pred@2133
|
162 |
if (strcmp(text[startidx], "nominate", false) == 0) |
|
pred@2133
|
163 |
{ |
|
pred@2133
|
164 |
AttemptNominate(client); |
|
pred@2133
|
165 |
} |
|
pred@2133
|
166 |
|
|
pred@2133
|
167 |
SetCmdReplySource(old); |
|
pred@2133
|
168 |
|
|
pred@2133
|
169 |
return Plugin_Continue; |
|
pred@2133
|
170 |
} |
|
pred@2133
|
171 |
|
|
pred@2133
|
172 |
public Action:Command_Nominate(client, args) |
|
pred@2133
|
173 |
{ |
|
pred@2133
|
174 |
if (!client) |
|
pred@2133
|
175 |
{ |
|
pred@2133
|
176 |
return Plugin_Continue; |
|
pred@2133
|
177 |
} |
|
pred@2133
|
178 |
|
|
pred@2133
|
179 |
if (args == 0) |
|
pred@2133
|
180 |
{ |
|
pred@2133
|
181 |
AttemptNominate(client); |
|
pred@2133
|
182 |
return Plugin_Continue; |
|
pred@2133
|
183 |
} |
|
pred@2133
|
184 |
|
|
pred@2133
|
185 |
decl String:mapname[64]; |
|
pred@2133
|
186 |
GetCmdArg(1, mapname, sizeof(mapname)); |
|
pred@2133
|
187 |
|
|
pred@2344
|
188 |
decl String:item[64]; |
|
pred@2344
|
189 |
for (new i = 0; i < GetMenuItemCount(g_MapMenu); i++) |
|
pred@2133
|
190 |
{ |
|
pred@2344
|
191 |
GetMenuItem(g_MapMenu, i, item, sizeof(item)); |
|
pred@2344
|
192 |
if (strcmp(item, mapname) == 0) |
|
pred@2344
|
193 |
{ |
|
pred@2344
|
194 |
new NominateResult:result = NominateMap(mapname, false, client); |
|
pred@2344
|
195 |
|
|
pred@2344
|
196 |
if (result > Nominate_Replaced) |
|
pred@2344
|
197 |
{ |
|
pred@2344
|
198 |
if (result == Nominate_AlreadyInVote) |
|
pred@2344
|
199 |
{ |
|
pred@2344
|
200 |
ReplyToCommand(client, "%t", "Map Already In Vote", mapname); |
|
pred@2344
|
201 |
} |
|
pred@2344
|
202 |
else |
|
pred@2344
|
203 |
{ |
|
pred@2344
|
204 |
ReplyToCommand(client, "[SM] %t", "Map Already Nominated"); |
|
pred@2344
|
205 |
} |
|
pred@2344
|
206 |
|
|
pred@2344
|
207 |
return Plugin_Handled; |
|
pred@2344
|
208 |
} |
|
pred@2344
|
209 |
|
|
pred@2344
|
210 |
RemoveMenuItem(g_MapMenu, i); |
|
pred@2344
|
211 |
|
|
pred@2344
|
212 |
decl String:name[64]; |
|
pred@2344
|
213 |
GetClientName(client, name, sizeof(name)); |
|
pred@2344
|
214 |
|
|
pred@2344
|
215 |
PrintToChatAll("[SM] %t", "Map Nominated", name, mapname); |
|
pred@2344
|
216 |
|
|
pred@2344
|
217 |
return Plugin_Continue; |
|
pred@2344
|
218 |
} |
|
pred@2133
|
219 |
} |
|
pred@2133
|
220 |
|
|
pred@2344
|
221 |
ReplyToCommand(client, "%t", "Map was not found", mapname); |
|
pred@2344
|
222 |
return Plugin_Handled; |
|
pred@2133
|
223 |
} |
|
pred@2133
|
224 |
|
|
pred@2133
|
225 |
AttemptNominate(client) |
|
pred@2133
|
226 |
{ |
|
pred@2133
|
227 |
SetMenuTitle(g_MapMenu, "%t", "Nominate Title", client); |
|
pred@2133
|
228 |
DisplayMenu(g_MapMenu, client, MENU_TIME_FOREVER); |
|
pred@2133
|
229 |
|
|
pred@2133
|
230 |
return; |
|
pred@2133
|
231 |
} |
|
pred@2133
|
232 |
|
|
pred@2133
|
233 |
BuildMapMenu() |
|
pred@2133
|
234 |
{ |
|
pred@2133
|
235 |
if (g_MapMenu != INVALID_HANDLE) |
|
pred@2133
|
236 |
{ |
|
pred@2133
|
237 |
CloseHandle(g_MapMenu); |
|
pred@2133
|
238 |
g_MapMenu = INVALID_HANDLE; |
|
pred@2133
|
239 |
} |
|
pred@2133
|
240 |
|
|
pred@2344
|
241 |
g_MapMenu = CreateMenu(Handler_MapSelectMenu); |
|
pred@2133
|
242 |
|
|
pred@2133
|
243 |
decl String:map[64]; |
|
pred@2133
|
244 |
|
|
pred@2133
|
245 |
new Handle:excludeMaps; |
|
pred@2133
|
246 |
decl String:currentMap[32]; |
|
pred@2133
|
247 |
|
|
pred@2133
|
248 |
if (GetConVarBool(g_Cvar_ExcludeOld)) |
|
pred@2133
|
249 |
{ |
|
pred@2133
|
250 |
excludeMaps = CreateArray(ByteCountToCells(33)); |
|
pred@2133
|
251 |
GetExcludeMapList(excludeMaps); |
|
pred@2133
|
252 |
} |
|
pred@2133
|
253 |
|
|
pred@2133
|
254 |
if (GetConVarBool(g_Cvar_ExcludeCurrent)) |
|
pred@2133
|
255 |
{ |
|
pred@2133
|
256 |
GetCurrentMap(currentMap, sizeof(currentMap)); |
|
pred@2133
|
257 |
} |
|
pred@2133
|
258 |
|
|
pred@2133
|
259 |
for (new i = 0; i < GetArraySize(g_MapList); i++) |
|
pred@2133
|
260 |
{ |
|
pred@2344
|
261 |
GetArrayString(g_MapList, i, map, sizeof(map)); |
|
pred@2133
|
262 |
|
|
pred@2344
|
263 |
if (GetConVarBool(g_Cvar_ExcludeOld)) |
|
pred@2344
|
264 |
{ |
|
pred@2344
|
265 |
if (FindStringInArray(excludeMaps, map) != -1) |
|
pred@2344
|
266 |
{ |
|
pred@2344
|
267 |
continue; |
|
pred@2344
|
268 |
} |
|
pred@2344
|
269 |
} |
|
pred@2133
|
270 |
|
|
pred@2133
|
271 |
if (GetConVarBool(g_Cvar_ExcludeCurrent)) |
|
pred@2133
|
272 |
{ |
|
pred@2133
|
273 |
if (StrEqual(map, currentMap)) |
|
pred@2133
|
274 |
{ |
|
pred@2344
|
275 |
continue; |
|
pred@2133
|
276 |
} |
|
pred@2133
|
277 |
} |
|
pred@2133
|
278 |
|
|
pred@2133
|
279 |
AddMenuItem(g_MapMenu, map, map); |
|
pred@2133
|
280 |
} |
|
pred@2133
|
281 |
|
|
pred@2133
|
282 |
SetMenuExitButton(g_MapMenu, true); |
|
pred@2133
|
283 |
} |
|
pred@2133
|
284 |
|
|
pred@2133
|
285 |
public Handler_MapSelectMenu(Handle:menu, MenuAction:action, param1, param2) |
|
pred@2133
|
286 |
{ |
|
pred@2133
|
287 |
switch (action) |
|
pred@2133
|
288 |
{ |
|
pred@2133
|
289 |
case MenuAction_Select: |
|
pred@2133
|
290 |
{ |
|
pred@2133
|
291 |
decl String:map[64], String:name[64]; |
|
pred@2344
|
292 |
GetMenuItem(menu, param2, map, sizeof(map)); |
|
pred@2344
|
293 |
|
|
pred@2133
|
294 |
|
|
pred@2133
|
295 |
GetClientName(param1, name, 64); |
|
pred@2133
|
296 |
|
|
pred@2344
|
297 |
|
|
pred@2133
|
298 |
new NominateResult:result = NominateMap(map, false, param1); |
|
pred@2133
|
299 |
|
|
pred@2133
|
300 |
/* Don't need to check for InvalidMap because the menu did that already */ |
|
pred@2133
|
301 |
if (result == Nominate_AlreadyInVote) |
|
pred@2133
|
302 |
{ |
|
pred@2133
|
303 |
PrintToChat(param1, "[SM] %t", "Map Already Nominated"); |
|
pred@2344
|
304 |
return; |
|
pred@2133
|
305 |
} |
|
pred@2133
|
306 |
else if (result == Nominate_VoteFull) |
|
pred@2133
|
307 |
{ |
|
pred@2133
|
308 |
PrintToChat(param1, "[SM] %t", "Max Nominations"); |
|
pred@2344
|
309 |
return; |
|
pred@2133
|
310 |
} |
|
pred@2344
|
311 |
|
|
pred@2344
|
312 |
RemoveMenuItem(menu, param2); |
|
pred@2343
|
313 |
|
|
pred@2133
|
314 |
if (result == Nominate_Replaced) |
|
pred@2133
|
315 |
{ |
|
pred@2133
|
316 |
PrintToChatAll("[SM] %t", "Map Nomination Changed", name, map); |
|
pred@2344
|
317 |
return; |
|
pred@2133
|
318 |
} |
|
pred@2133
|
319 |
|
|
pred@2133
|
320 |
PrintToChatAll("[SM] %t", "Map Nominated", name, map); |
|
pred@2133
|
321 |
} |
|
pred@2133
|
322 |
} |
|
pred@2133
|
323 |
} |