Update CS:GO team score gamedata.
3 * =============================================================================
4 * SourceMod Rock The Vote Plugin
5 * Creates a map vote when the required number of players have requested one.
7 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
8 * =============================================================================
10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License, version 3.0, as published by the
12 * Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
22 * As a special exception, AlliedModders LLC gives you permission to link the
23 * code of this program (as well as its derivative works) to "Half-Life 2," the
24 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
25 * by the Valve Corporation. You must obey the GNU General Public License in
26 * all respects for all other code used. Additionally, AlliedModders LLC grants
27 * this exception to all derivative works. AlliedModders LLC defines further
28 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
29 * or <http://www.sourcemod.net/license.php>.
39 public Plugin:myinfo =
41 name = "Map Nominations",
42 author = "AlliedModders LLC",
43 description = "Provides Map Nominations",
44 version = SOURCEMOD_VERSION,
45 url = "http://www.sourcemod.net/"
48 new Handle:g_Cvar_ExcludeOld = INVALID_HANDLE;
49 new Handle:g_Cvar_ExcludeCurrent = INVALID_HANDLE;
51 new Handle:g_MapList = INVALID_HANDLE;
52 new Handle:g_MapMenu = INVALID_HANDLE;
53 new g_mapFileSerial = -1;
55 #define MAPSTATUS_ENABLED (1<<0)
56 #define MAPSTATUS_DISABLED (1<<1)
57 #define MAPSTATUS_EXCLUDE_CURRENT (1<<2)
58 #define MAPSTATUS_EXCLUDE_PREVIOUS (1<<3)
59 #define MAPSTATUS_EXCLUDE_NOMINATED (1<<4)
63 public OnPluginStart()
65 LoadTranslations("common.phrases");
66 LoadTranslations("nominations.phrases");
68 new arraySize = ByteCountToCells(33);
69 g_MapList = CreateArray(arraySize);
71 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);
72 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);
74 RegConsoleCmd("sm_nominate", Command_Nominate);
76 RegAdminCmd("sm_nominate_addmap", Command_Addmap, ADMFLAG_CHANGEMAP, "sm_nominate_addmap <mapname> - Forces a map to be on the next mapvote.");
78 g_mapTrie = CreateTrie();
81 public OnConfigsExecuted()
83 if (ReadMapList(g_MapList,
86 MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER)
89 if (g_mapFileSerial == -1)
91 SetFailState("Unable to create a valid map list.");
98 public OnNominationRemoved(const String:map[], owner)
102 /* Is the map in our list? */
103 if (!GetTrieValue(g_mapTrie, map, status))
108 /* Was the map disabled due to being nominated */
109 if ((status & MAPSTATUS_EXCLUDE_NOMINATED) != MAPSTATUS_EXCLUDE_NOMINATED)
114 SetTrieValue(g_mapTrie, map, MAPSTATUS_ENABLED);
117 public Action:Command_Addmap(client, args)
121 ReplyToCommand(client, "[SM] Usage: sm_nominate_addmap <mapname>");
122 return Plugin_Handled;
125 decl String:mapname[64];
126 GetCmdArg(1, mapname, sizeof(mapname));
130 if (!GetTrieValue(g_mapTrie, mapname, status))
132 ReplyToCommand(client, "%t", "Map was not found", mapname);
133 return Plugin_Handled;
136 new NominateResult:result = NominateMap(mapname, true, 0);
138 if (result > Nominate_Replaced)
140 /* 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 */
141 ReplyToCommand(client, "%t", "Map Already In Vote", mapname);
143 return Plugin_Handled;
147 SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
150 ReplyToCommand(client, "%t", "Map Inserted", mapname);
151 LogAction(client, -1, "\"%L\" inserted map \"%s\".", client, mapname);
153 return Plugin_Handled;
156 public OnClientSayCommand_Post(client, const String:command[], const String:sArgs[])
163 if (strcmp(sArgs, "nominate", false) == 0)
165 new ReplySource:old = SetCmdReplySource(SM_REPLY_TO_CHAT);
167 AttemptNominate(client);
169 SetCmdReplySource(old);
173 public Action:Command_Nominate(client, args)
177 return Plugin_Handled;
182 AttemptNominate(client);
183 return Plugin_Handled;
186 decl String:mapname[64];
187 GetCmdArg(1, mapname, sizeof(mapname));
190 if (!GetTrieValue(g_mapTrie, mapname, status))
192 ReplyToCommand(client, "%t", "Map was not found", mapname);
193 return Plugin_Handled;
196 if ((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
198 if ((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
200 ReplyToCommand(client, "[SM] %t", "Can't Nominate Current Map");
203 if ((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
205 ReplyToCommand(client, "[SM] %t", "Map in Exclude List");
208 if ((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
210 ReplyToCommand(client, "[SM] %t", "Map Already Nominated");
213 return Plugin_Handled;
216 new NominateResult:result = NominateMap(mapname, false, client);
218 if (result > Nominate_Replaced)
220 if (result == Nominate_AlreadyInVote)
222 ReplyToCommand(client, "%t", "Map Already In Vote", mapname);
226 ReplyToCommand(client, "[SM] %t", "Map Already Nominated");
229 return Plugin_Handled;
232 /* Map was nominated! - Disable the menu item and update the trie */
234 SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
236 decl String:name[64];
237 GetClientName(client, name, sizeof(name));
238 PrintToChatAll("[SM] %t", "Map Nominated", name, mapname);
240 return Plugin_Continue;
243 AttemptNominate(client)
245 SetMenuTitle(g_MapMenu, "%T", "Nominate Title", client);
246 DisplayMenu(g_MapMenu, client, MENU_TIME_FOREVER);
253 if (g_MapMenu != INVALID_HANDLE)
255 CloseHandle(g_MapMenu);
256 g_MapMenu = INVALID_HANDLE;
259 ClearTrie(g_mapTrie);
261 g_MapMenu = CreateMenu(Handler_MapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem);
265 new Handle:excludeMaps = INVALID_HANDLE;
266 decl String:currentMap[32];
268 if (GetConVarBool(g_Cvar_ExcludeOld))
270 excludeMaps = CreateArray(ByteCountToCells(33));
271 GetExcludeMapList(excludeMaps);
274 if (GetConVarBool(g_Cvar_ExcludeCurrent))
276 GetCurrentMap(currentMap, sizeof(currentMap));
280 for (new i = 0; i < GetArraySize(g_MapList); i++)
282 new status = MAPSTATUS_ENABLED;
284 GetArrayString(g_MapList, i, map, sizeof(map));
286 if (GetConVarBool(g_Cvar_ExcludeCurrent))
288 if (StrEqual(map, currentMap))
290 status = MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_CURRENT;
294 /* Dont bother with this check if the current map check passed */
295 if (GetConVarBool(g_Cvar_ExcludeOld) && status == MAPSTATUS_ENABLED)
297 if (FindStringInArray(excludeMaps, map) != -1)
299 status = MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_PREVIOUS;
303 AddMenuItem(g_MapMenu, map, map);
304 SetTrieValue(g_mapTrie, map, status);
307 SetMenuExitButton(g_MapMenu, true);
309 if (excludeMaps != INVALID_HANDLE)
311 CloseHandle(excludeMaps);
315 public Handler_MapSelectMenu(Handle:menu, MenuAction:action, param1, param2)
319 case MenuAction_Select:
321 decl String:map[64], String:name[64];
322 GetMenuItem(menu, param2, map, sizeof(map));
324 GetClientName(param1, name, 64);
326 new NominateResult:result = NominateMap(map, false, param1);
328 /* Don't need to check for InvalidMap because the menu did that already */
329 if (result == Nominate_AlreadyInVote)
331 PrintToChat(param1, "[SM] %t", "Map Already Nominated");
334 else if (result == Nominate_VoteFull)
336 PrintToChat(param1, "[SM] %t", "Max Nominations");
340 SetTrieValue(g_mapTrie, map, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
342 if (result == Nominate_Replaced)
344 PrintToChatAll("[SM] %t", "Map Nomination Changed", name, map);
348 PrintToChatAll("[SM] %t", "Map Nominated", name, map);
351 case MenuAction_DrawItem:
354 GetMenuItem(menu, param2, map, sizeof(map));
358 if (!GetTrieValue(g_mapTrie, map, status))
360 LogError("Menu selection of item not in trie. Major logic problem somewhere.");
361 return ITEMDRAW_DEFAULT;
364 if ((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
366 return ITEMDRAW_DISABLED;
369 return ITEMDRAW_DEFAULT;
373 case MenuAction_DisplayItem:
376 GetMenuItem(menu, param2, map, sizeof(map));
380 if (!GetTrieValue(g_mapTrie, map, status))
382 LogError("Menu selection of item not in trie. Major logic problem somewhere.");
386 decl String:display[100];
388 if ((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
390 if ((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
392 Format(display, sizeof(display), "%s (%T)", map, "Current Map", param1);
393 return RedrawMenuItem(display);
396 if ((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
398 Format(display, sizeof(display), "%s (%T)", map, "Recently Played", param1);
399 return RedrawMenuItem(display);
402 if ((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
404 Format(display, sizeof(display), "%s (%T)", map, "Nominated", param1);
405 return RedrawMenuItem(display);