plugins/rockthevote.sp
author Matt Woodrow <pred@alliedmods.net>
Sun May 25 20:50:11 2008 +0000 (2008-05-25)
changeset 2082 89c0bd044fbe
parent 1952 b7aa2b626807
child 2133 cad0a5ea6742
permissions -rw-r--r--
Fixed amb1713 - The tiniest of tiny mixups in description orders.
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod Rock The Vote Plugin
ds@1952
     5
 * Creates a map vote when the required number of players have requested one.
ds@1952
     6
 *
ds@1952
     7
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     8
 * =============================================================================
ds@1952
     9
 *
ds@1952
    10
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    11
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    12
 * Free Software Foundation.
ds@1952
    13
 * 
ds@1952
    14
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    16
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    17
 * details.
ds@1952
    18
 *
ds@1952
    19
 * You should have received a copy of the GNU General Public License along with
ds@1952
    20
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    21
 *
ds@1952
    22
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    23
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    24
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    25
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    26
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    27
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    28
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    29
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    30
 *
ds@1952
    31
 * Version: $Id$
ds@1952
    32
 */
ds@1952
    33
ds@1952
    34
#include <sourcemod>
ds@1952
    35
ds@1952
    36
#pragma semicolon 1
ds@1952
    37
ds@1952
    38
public Plugin:myinfo =
ds@1952
    39
{
ds@1952
    40
	name = "Rock The Vote",
ds@1952
    41
	author = "AlliedModders LLC",
ds@1952
    42
	description = "Provides RTV 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_Needed = INVALID_HANDLE;
ds@1952
    48
new Handle:g_Cvar_Maps = INVALID_HANDLE;
ds@1952
    49
new Handle:g_Cvar_Nominate = INVALID_HANDLE;
ds@1952
    50
new Handle:g_Cvar_MinPlayers = INVALID_HANDLE;
ds@1952
    51
ds@1952
    52
new Handle:g_MapList = INVALID_HANDLE;
ds@1952
    53
new Handle:g_RTVMapList = INVALID_HANDLE;
ds@1952
    54
new Handle:g_MapMenu = INVALID_HANDLE;
ds@1952
    55
new Handle:g_RetryTimer = INVALID_HANDLE;
ds@1952
    56
new g_mapFileSerial = -1;
ds@1952
    57
ds@1952
    58
new bool:g_CanRTV = false;		// True if RTV loaded maps and is active.
ds@1952
    59
new bool:g_RTVAllowed = false;	// True if RTV is available to players. Used to delay rtv votes.
ds@1952
    60
new bool:g_RTVStarted = false;	// Indicates that the actual map vote has started
ds@1952
    61
new bool:g_RTVEnded = false;	// Indicates that the actual map vote has concluded
ds@1952
    62
new g_Voters = 0;				// Total voters connected. Doesn't include fake clients.
ds@1952
    63
new g_Votes = 0;				// Total number of "say rtv" votes
ds@1952
    64
new g_VotesNeeded = 0;			// Necessary votes before map vote begins. (voters * percent_needed)
ds@1952
    65
new bool:g_Voted[MAXPLAYERS+1] = {false, ...};
ds@1952
    66
new bool:g_Nominated[MAXPLAYERS+1] = {false, ...};
ds@1952
    67
ds@1952
    68
public OnPluginStart()
ds@1952
    69
{
ds@1952
    70
	LoadTranslations("common.phrases");
ds@1952
    71
	LoadTranslations("rockthevote.phrases");
ds@1952
    72
	
ds@1952
    73
	new arraySize = ByteCountToCells(33);	
ds@1952
    74
	g_MapList = CreateArray(arraySize);
ds@1952
    75
	g_RTVMapList = CreateArray(arraySize);
ds@1952
    76
	
ds@1952
    77
	g_Cvar_Needed = CreateConVar("sm_rtv_needed", "0.60", "Percentage of players needed to rockthevote (Def 60%)", 0, true, 0.05, true, 1.0);
ds@1952
    78
	g_Cvar_Maps = CreateConVar("sm_rtv_maps", "4", "Number of maps to be voted on. 2 to 6. (Def 4)", 0, true, 2.0, true, 6.0);
ds@1952
    79
	g_Cvar_Nominate = CreateConVar("sm_rtv_nominate", "1", "Enables nomination system.", 0, true, 0.0, true, 1.0);
ds@1952
    80
	g_Cvar_MinPlayers = CreateConVar("sm_rtv_minplayers", "0", "Number of players required before RTV will be enabled.", 0, true, 0.0, true, float(MAXPLAYERS));
ds@1952
    81
	
ds@1952
    82
	RegConsoleCmd("say", Command_Say);
ds@1952
    83
	RegConsoleCmd("say_team", Command_Say);
ds@1952
    84
	
ds@1952
    85
	RegAdminCmd("sm_rtv_addmap", Command_Addmap, ADMFLAG_CHANGEMAP, "sm_rtv_addmap <mapname> - Forces a map to be on the RTV, and lowers the allowed nominations.");
ds@1952
    86
	
ds@1952
    87
	AutoExecConfig(true, "rtv");
ds@1952
    88
}
ds@1952
    89
ds@1952
    90
public OnMapStart()
ds@1952
    91
{
ds@1952
    92
	g_Voters = 0;
ds@1952
    93
	g_Votes = 0;
ds@1952
    94
	g_VotesNeeded = 0;
ds@1952
    95
	g_RTVStarted = false;
ds@1952
    96
	g_RTVEnded = false;
ds@1952
    97
}
ds@1952
    98
ds@1952
    99
public OnMapEnd()
ds@1952
   100
{
ds@1952
   101
	g_CanRTV = false;	
ds@1952
   102
	g_RTVAllowed = false;
ds@1952
   103
}
ds@1952
   104
ds@1952
   105
public OnConfigsExecuted()
ds@1952
   106
{
ds@1952
   107
	if (g_RTVMapList != INVALID_HANDLE)
ds@1952
   108
	{
ds@1952
   109
		ClearArray(g_RTVMapList);
ds@1952
   110
	}
ds@1952
   111
	
ds@1952
   112
	if (ReadMapList(g_MapList,
ds@1952
   113
					g_mapFileSerial,
ds@1952
   114
					"rockthevote",
ds@1952
   115
					MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER)
ds@1952
   116
		== INVALID_HANDLE)
ds@1952
   117
	{
ds@1952
   118
		if (g_mapFileSerial == -1)
ds@1952
   119
		{
ds@1952
   120
			LogError("Unable to create a valid map list.");
ds@1952
   121
		}
ds@1952
   122
	}
ds@1952
   123
	
ds@1952
   124
	BuildMapMenu();
ds@1952
   125
	g_CanRTV = true;
ds@1952
   126
	CreateTimer(30.0, Timer_DelayRTV);
ds@1952
   127
}
ds@1952
   128
ds@1952
   129
public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
ds@1952
   130
{
ds@1952
   131
	if(!g_CanRTV || IsFakeClient(client))
ds@1952
   132
		return true;
ds@1952
   133
	
ds@1952
   134
	g_Voted[client] = false;
ds@1952
   135
	g_Nominated[client] = false;
ds@1952
   136
ds@1952
   137
	g_Voters++;
ds@1952
   138
	g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed));
ds@1952
   139
	
ds@1952
   140
	return true;
ds@1952
   141
}
ds@1952
   142
ds@1952
   143
public OnClientDisconnect(client)
ds@1952
   144
{
ds@1952
   145
	if(!g_CanRTV || IsFakeClient(client))
ds@1952
   146
		return;
ds@1952
   147
	
ds@1952
   148
	if(g_Voted[client])
ds@1952
   149
	{
ds@1952
   150
		g_Votes--;
ds@1952
   151
	}
ds@1952
   152
	
ds@1952
   153
	g_Voters--;
ds@1952
   154
	
ds@1952
   155
	g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed));
ds@1952
   156
	
ds@1952
   157
	if (g_Votes && g_Voters && g_Votes >= g_VotesNeeded && g_RTVAllowed && !g_RTVStarted) 
ds@1952
   158
	{
ds@1952
   159
		g_RTVStarted = true;
ds@1952
   160
		CreateTimer(2.0, Timer_StartRTV, TIMER_FLAG_NO_MAPCHANGE);
ds@1952
   161
	}	
ds@1952
   162
}
ds@1952
   163
ds@1952
   164
public Action:Command_Addmap(client, args)
ds@1952
   165
{
ds@1952
   166
	if (args < 1)
ds@1952
   167
	{
ds@1952
   168
		ReplyToCommand(client, "[SM] Usage: sm_rtv_addmap <mapname>");
ds@1952
   169
		return Plugin_Handled;
ds@1952
   170
	}
ds@1952
   171
	
ds@1952
   172
	if (!g_CanRTV)
ds@1952
   173
	{
ds@1952
   174
		ReplyToCommand(client, "[SM] RockTheVote is not available.");
ds@1952
   175
		return Plugin_Handled;
ds@1952
   176
	}
ds@1952
   177
	
ds@1952
   178
	decl String:mapname[64];
ds@1952
   179
	GetCmdArg(1, mapname, sizeof(mapname));
ds@1952
   180
ds@1952
   181
	if (FindStringInArray(g_MapList, mapname) == -1)
ds@1952
   182
	{
ds@1952
   183
		ReplyToCommand(client, "%t", "Map was not found", mapname);
ds@1952
   184
		return Plugin_Handled;
ds@1952
   185
	}
ds@1952
   186
	
ds@1952
   187
	if (GetArraySize(g_RTVMapList) > 0)
ds@1952
   188
	{
ds@1952
   189
		if (FindStringInArray(g_RTVMapList, mapname) != -1)
ds@1952
   190
		{
ds@1952
   191
			ReplyToCommand(client, "%t", "Map Already In Vote", mapname);
ds@1952
   192
			return Plugin_Handled;				
ds@1952
   193
		}
ds@1952
   194
		
ds@1952
   195
		ShiftArrayUp(g_RTVMapList, 0);
ds@1952
   196
		SetArrayString(g_RTVMapList, 0, mapname);
ds@1952
   197
		
ds@1952
   198
		while (GetArraySize(g_RTVMapList) > GetConVarInt(g_Cvar_Maps))
ds@1952
   199
		{
ds@1952
   200
			RemoveFromArray(g_RTVMapList, GetConVarInt(g_Cvar_Maps));
ds@1952
   201
		}
ds@1952
   202
	}
ds@1952
   203
	else
ds@1952
   204
	{
ds@1952
   205
		PushArrayString(g_RTVMapList, mapname);
ds@1952
   206
	}
ds@1952
   207
		
ds@1952
   208
	decl String:item[64];
ds@1952
   209
	for (new i = 0; i < GetMenuItemCount(g_MapMenu); i++)
ds@1952
   210
	{
ds@1952
   211
		GetMenuItem(g_MapMenu, i, item, sizeof(item));
ds@1952
   212
		if (strcmp(item, mapname) == 0)
ds@1952
   213
		{
ds@1952
   214
			RemoveMenuItem(g_MapMenu, i);
ds@1952
   215
			break;
ds@1952
   216
		}			
ds@1952
   217
	}	
ds@1952
   218
	
ds@1952
   219
	ReplyToCommand(client, "%t", "Map Inserted", mapname);
ds@1952
   220
	LogAction(client, -1, "\"%L\" inserted map \"%s\".", client, mapname);
ds@1952
   221
ds@1952
   222
	return Plugin_Handled;		
ds@1952
   223
}
ds@1952
   224
ds@1952
   225
public Action:Command_Say(client, args)
ds@1952
   226
{
ds@1952
   227
	if (!g_CanRTV || !client)
ds@1952
   228
	{
ds@1952
   229
		return Plugin_Continue;
ds@1952
   230
	}
ds@1952
   231
ds@1952
   232
	decl String:text[192];
ds@1952
   233
	if (!GetCmdArgString(text, sizeof(text)))
ds@1952
   234
	{
ds@1952
   235
		return Plugin_Continue;
ds@1952
   236
	}
ds@1952
   237
	
ds@1952
   238
	new startidx = 0;
ds@1952
   239
	if(text[strlen(text)-1] == '"')
ds@1952
   240
	{
ds@1952
   241
		text[strlen(text)-1] = '\0';
ds@1952
   242
		startidx = 1;
ds@1952
   243
	}
ds@1952
   244
	
ds@1952
   245
	if (strcmp(text[startidx], "rtv", false) == 0 || strcmp(text[startidx], "rockthevote", false) == 0)
ds@1952
   246
	{
ds@1952
   247
		if (!g_RTVAllowed)
ds@1952
   248
		{
ds@1952
   249
			PrintToChat(client, "[SM] %t", "RTV Not Allowed");
ds@1952
   250
			return Plugin_Continue;
ds@1952
   251
		}
ds@1952
   252
		
ds@1952
   253
		if (g_RTVEnded)
ds@1952
   254
		{
ds@1952
   255
			PrintToChat(client, "[SM] %t", "RTV Ended");
ds@1952
   256
			return Plugin_Continue;
ds@1952
   257
		}
ds@1952
   258
		
ds@1952
   259
		if (g_RTVStarted)
ds@1952
   260
		{
ds@1952
   261
			PrintToChat(client, "[SM] %t", "RTV Started");
ds@1952
   262
			return Plugin_Continue;
ds@1952
   263
		}
ds@1952
   264
		
ds@1952
   265
		if (GetClientCount(true) < GetConVarInt(g_Cvar_MinPlayers) && g_Votes == 0) // Should we keep checking g_Votes here?
ds@1952
   266
		{
ds@1952
   267
			PrintToChat(client, "[SM] %t", "Minimal Players Not Met");
ds@1952
   268
			return Plugin_Continue;			
ds@1952
   269
		}
ds@1952
   270
		
ds@1952
   271
		if (g_Voted[client])
ds@1952
   272
		{
ds@1952
   273
			PrintToChat(client, "[SM] %t", "Already Voted");
ds@1952
   274
			return Plugin_Continue;
ds@1952
   275
		}	
ds@1952
   276
		
ds@1952
   277
		new String:name[64];
ds@1952
   278
		GetClientName(client, name, sizeof(name));
ds@1952
   279
		
ds@1952
   280
		g_Votes++;
ds@1952
   281
		g_Voted[client] = true;
ds@1952
   282
		
ds@1952
   283
		PrintToChatAll("[SM] %t", "RTV Requested", name, g_Votes, g_VotesNeeded);
ds@1952
   284
		
ds@1952
   285
		if (g_Votes >= g_VotesNeeded)
ds@1952
   286
		{
ds@1952
   287
			g_RTVStarted = true;
ds@1952
   288
			CreateTimer(2.0, Timer_StartRTV, TIMER_FLAG_NO_MAPCHANGE);
ds@1952
   289
		}
ds@1952
   290
	}
ds@1952
   291
	else if (GetConVarBool(g_Cvar_Nominate) && strcmp(text[startidx], "nominate", false) == 0)
ds@1952
   292
	{
ds@1952
   293
		if (g_RTVEnded)
ds@1952
   294
		{
ds@1952
   295
			PrintToChat(client, "[SM] %t", "RTV Ended");
ds@1952
   296
			return Plugin_Continue;
ds@1952
   297
		}		
ds@1952
   298
		
ds@1952
   299
		if (g_RTVStarted)
ds@1952
   300
		{
ds@1952
   301
			PrintToChat(client, "[SM] %t", "RTV Started");
ds@1952
   302
			return Plugin_Continue;
ds@1952
   303
		}
ds@1952
   304
		
ds@1952
   305
		if (g_Nominated[client])
ds@1952
   306
		{
ds@1952
   307
			PrintToChat(client, "[SM] %t", "Already Nominated");
ds@1952
   308
			return Plugin_Continue;
ds@1952
   309
		}
ds@1952
   310
		
ds@1952
   311
		if (GetArraySize(g_RTVMapList) >= GetConVarInt(g_Cvar_Maps))
ds@1952
   312
		{
ds@1952
   313
			PrintToChat(client, "[SM] %t", "Max Nominations");
ds@1952
   314
			return Plugin_Continue;			
ds@1952
   315
		}
ds@1952
   316
		
ds@1952
   317
		DisplayMenu(g_MapMenu, client, MENU_TIME_FOREVER);		
ds@1952
   318
	}
ds@1952
   319
	
ds@1952
   320
	return Plugin_Continue;	
ds@1952
   321
}
ds@1952
   322
ds@1952
   323
public Action:Timer_DelayRTV(Handle:timer)
ds@1952
   324
{
ds@1952
   325
	g_RTVAllowed = true;
ds@1952
   326
	g_RTVStarted = false;
ds@1952
   327
	g_RTVEnded = false;	
ds@1952
   328
}
ds@1952
   329
ds@1952
   330
public Action:Timer_StartRTV(Handle:timer)
ds@1952
   331
{
ds@1952
   332
	if (timer == g_RetryTimer)
ds@1952
   333
	{
ds@1952
   334
		g_RetryTimer = INVALID_HANDLE;
ds@1952
   335
	}
ds@1952
   336
	
ds@1952
   337
	if (g_RetryTimer != INVALID_HANDLE)
ds@1952
   338
	{
ds@1952
   339
		return;
ds@1952
   340
	}
ds@1952
   341
ds@1952
   342
	if (IsVoteInProgress())
ds@1952
   343
	{
ds@1952
   344
		// Can't start a vote, try again in 5 seconds.
ds@1952
   345
		g_RetryTimer = CreateTimer(5.0, Timer_StartRTV, TIMER_FLAG_NO_MAPCHANGE);
ds@1952
   346
		return;
ds@1952
   347
	}			
ds@1952
   348
	
ds@1952
   349
	PrintToChatAll("[SM] %t", "RTV Vote Ready");
ds@1952
   350
		
ds@1952
   351
	new Handle:MapVoteMenu = CreateMenu(Handler_MapMapVoteMenu, MenuAction:MENU_ACTIONS_ALL);
ds@1952
   352
	SetMenuTitle(MapVoteMenu, "Rock The Vote");
ds@1952
   353
	
ds@1952
   354
	new Handle:tempMaps  = CloneArray(g_MapList);
ds@1952
   355
	decl String:map[32];
ds@1952
   356
ds@1952
   357
	GetCurrentMap(map, sizeof(map));
ds@1952
   358
	new index = FindStringInArray(tempMaps, map);
ds@1952
   359
	if (index != -1)
ds@1952
   360
	{
ds@1952
   361
		RemoveFromArray(tempMaps, index);
ds@1952
   362
	}	
ds@1952
   363
	
ds@1952
   364
	// We assume that g_RTVMapList is within the correct limits, based on the logic for nominations
ds@1952
   365
	for (new i = 0; i < GetArraySize(g_RTVMapList); i++)
ds@1952
   366
	{
ds@1952
   367
		GetArrayString(g_RTVMapList, i, map, sizeof(map));
ds@1952
   368
		AddMenuItem(MapVoteMenu, map, map);
ds@1952
   369
		
ds@1952
   370
		index = FindStringInArray(tempMaps, map);
ds@1952
   371
		if (index != -1)
ds@1952
   372
		{
ds@1952
   373
			RemoveFromArray(tempMaps, index);
ds@1952
   374
		}
ds@1952
   375
	}
ds@1952
   376
	
ds@1952
   377
	new limit = GetConVarInt(g_Cvar_Maps) - GetArraySize(g_RTVMapList);
ds@1952
   378
	if (limit > GetArraySize(tempMaps))
ds@1952
   379
	{
ds@1952
   380
		limit = GetArraySize(tempMaps);
ds@1952
   381
	}
ds@1952
   382
ds@1952
   383
	for (new i = 0; i < limit; i++)
ds@1952
   384
	{
ds@1952
   385
		new b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
ds@1952
   386
		GetArrayString(tempMaps, b, map, sizeof(map));		
ds@1952
   387
		PushArrayString(g_RTVMapList, map);
ds@1952
   388
		AddMenuItem(MapVoteMenu, map, map);			
ds@1952
   389
		RemoveFromArray(tempMaps, b);
ds@1952
   390
	}	
ds@1952
   391
	
ds@1952
   392
	CloseHandle(tempMaps);
ds@1952
   393
	
ds@1952
   394
	AddMenuItem(MapVoteMenu, "Don't Change", "Don't Change");
ds@1952
   395
		
ds@1952
   396
	SetMenuExitButton(MapVoteMenu, false);
ds@1952
   397
	VoteMenuToAll(MapVoteMenu, 20);
ds@1952
   398
		
ds@1952
   399
	LogMessage("[SM] Rockthevote was successfully started.");
ds@1952
   400
}
ds@1952
   401
ds@1952
   402
public Action:Timer_ChangeMap(Handle:hTimer, Handle:dp)
ds@1952
   403
{
ds@1952
   404
	new String:map[65];
ds@1952
   405
	
ds@1952
   406
	ResetPack(dp);
ds@1952
   407
	ReadPackString(dp, map, sizeof(map));
ds@1952
   408
	
ds@1952
   409
	ServerCommand("changelevel \"%s\"", map);
ds@1952
   410
	
ds@1952
   411
	return Plugin_Stop;
ds@1952
   412
}
ds@1952
   413
ds@1952
   414
public Handler_MapMapVoteMenu(Handle:menu, MenuAction:action, param1, param2)
ds@1952
   415
{
ds@1952
   416
	switch (action)
ds@1952
   417
	{
ds@1952
   418
		case MenuAction_End:
ds@1952
   419
		{
ds@1952
   420
			CloseHandle(menu);
ds@1952
   421
		}
ds@1952
   422
		
ds@1952
   423
		case MenuAction_Display:
ds@1952
   424
		{
ds@1952
   425
	 		decl String:oldTitle[255], String:buffer[255];
ds@1952
   426
			GetMenuTitle(menu, oldTitle, sizeof(oldTitle));
ds@1952
   427
			Format(buffer, sizeof(buffer), "%T", oldTitle, param1);
ds@1952
   428
ds@1952
   429
			new Handle:panel = Handle:param2;
ds@1952
   430
			SetPanelTitle(panel, buffer);
ds@1952
   431
		}
ds@1952
   432
		
ds@1952
   433
		case MenuAction_DisplayItem:
ds@1952
   434
		{
ds@1952
   435
			if (GetMenuItemCount(menu) - 1 == param2)
ds@1952
   436
			{
ds@1952
   437
				decl String:buffer[255];
ds@1952
   438
				Format(buffer, sizeof(buffer), "%T", "Don't Change", param1);
ds@1952
   439
				return RedrawMenuItem(buffer);
ds@1952
   440
			}
ds@1952
   441
		}		
ds@1952
   442
ds@1952
   443
		// Why am I commented out? Because BAIL hasn't decided yet if
ds@1952
   444
		// vote notification will be built into the Vote API.
ds@1952
   445
		/*case MenuAction_Select:
ds@1952
   446
		{
ds@1952
   447
			decl String:Name[32], String:Map[32];
ds@1952
   448
			GetClientName(param1, Name, sizeof(Name));
ds@1952
   449
			GetMenuItem(menu, param2, Map, sizeof(Map));
ds@1952
   450
ds@1952
   451
			PrintToChatAll("[SM] %s has voted for map '%s'", Name, Map);
ds@1952
   452
		}*/
ds@1952
   453
		
ds@1952
   454
		case MenuAction_VoteCancel:
ds@1952
   455
		{
ds@1952
   456
			if (param1 == VoteCancel_NoVotes)
ds@1952
   457
			{
ds@1952
   458
				PrintToChatAll("[SM] %t", "No Votes");
ds@1952
   459
				g_RTVEnded = true;
ds@1952
   460
			}
ds@1952
   461
		}
ds@1952
   462
ds@1952
   463
		case MenuAction_VoteEnd:
ds@1952
   464
		{
ds@1952
   465
			new String:map[64];
ds@1952
   466
			
ds@1952
   467
			GetMenuItem(menu, param1, map, sizeof(map));
ds@1952
   468
			
ds@1952
   469
			if (GetMenuItemCount(menu) - 1 == param1) // This should always match the "Keep Current" option
ds@1952
   470
			{
ds@1952
   471
				PrintToChatAll("[SM] %t", "Current Map Stays");
ds@1952
   472
				LogMessage("[SM] Rockthevote has ended, current map kept.");
ds@1952
   473
			}
ds@1952
   474
			else
ds@1952
   475
			{
ds@1952
   476
				PrintToChatAll("[SM] %t", "Changing Maps", map);
ds@1952
   477
				LogMessage("[SM] Rockthevote has ended, changing to map %s.", map);
ds@1952
   478
				new Handle:dp;
ds@1952
   479
				CreateDataTimer(5.0, Timer_ChangeMap, dp);
ds@1952
   480
				WritePackString(dp, map);
ds@1952
   481
			}
ds@1952
   482
			
ds@1952
   483
			g_RTVEnded = true;
ds@1952
   484
		}
ds@1952
   485
	}
ds@1952
   486
	
ds@1952
   487
	return 0;
ds@1952
   488
}
ds@1952
   489
ds@1952
   490
public Handler_MapSelectMenu(Handle:menu, MenuAction:action, param1, param2)
ds@1952
   491
{
ds@1952
   492
	switch (action)
ds@1952
   493
	{
ds@1952
   494
		case MenuAction_Select:
ds@1952
   495
		{
ds@1952
   496
			if (GetArraySize(g_RTVMapList) >= GetConVarInt(g_Cvar_Maps)) 
ds@1952
   497
			{
ds@1952
   498
				PrintToChat(param1, "[SM] %t", "Max Nominations");
ds@1952
   499
				return;	
ds@1952
   500
			}
ds@1952
   501
			
ds@1952
   502
			decl String:map[64], String:name[64];
ds@1952
   503
			GetMenuItem(menu, param2, map, sizeof(map));
ds@1952
   504
			
ds@1952
   505
			if (FindStringInArray(g_RTVMapList, map) != -1)
ds@1952
   506
			{
ds@1952
   507
				PrintToChat(param1, "[SM] %t", "Map Already Nominated");
ds@1952
   508
				return;
ds@1952
   509
			}
ds@1952
   510
			
ds@1952
   511
			GetClientName(param1, name, 64);
ds@1952
   512
ds@1952
   513
			PushArrayString(g_RTVMapList, map);
ds@1952
   514
			RemoveMenuItem(menu, param2);
ds@1952
   515
			
ds@1952
   516
			g_Nominated[param1] = true;
ds@1952
   517
			
ds@1952
   518
			PrintToChatAll("[SM] %t", "Map Nominated", name, map);
ds@1952
   519
		}
ds@1952
   520
	}
ds@1952
   521
}
ds@1952
   522
ds@1952
   523
BuildMapMenu()
ds@1952
   524
{
ds@1952
   525
	if (g_MapMenu != INVALID_HANDLE)
ds@1952
   526
	{
ds@1952
   527
		CloseHandle(g_MapMenu);
ds@1952
   528
		g_MapMenu = INVALID_HANDLE;
ds@1952
   529
	}
ds@1952
   530
	
ds@1952
   531
	g_MapMenu = CreateMenu(Handler_MapSelectMenu);
ds@1952
   532
	SetMenuTitle(g_MapMenu, "%t", "Nominate Title");
ds@1952
   533
ds@1952
   534
	decl String:map[64];		
ds@1952
   535
	for (new i = 0; i < GetArraySize(g_MapList); i++)
ds@1952
   536
	{
ds@1952
   537
		GetArrayString(g_MapList, i, map, sizeof(map));
ds@1952
   538
		AddMenuItem(g_MapMenu, map, map);
ds@1952
   539
	}
ds@1952
   540
	
ds@1952
   541
	SetMenuExitButton(g_MapMenu, false);
ds@1952
   542
}