plugins/mapmanager/commands.sp
author David Anderson <dvander@alliedmods.net>
Sat May 17 05:12:52 2008 +0000 (2008-05-17)
changeset 2056 f1fcde46ac7c
parent 1952 b7aa2b626807
permissions -rw-r--r--
added amb1119 - sm_revote command
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod Map Manager Plugin
ds@1952
     5
 * Contains callbacks for commands
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
 public Action:Command_Say(client, args)
ds@1952
    35
 {
ds@1952
    36
	decl String:text[192];
ds@1952
    37
	if (GetCmdArgString(text, sizeof(text)) < 1)
ds@1952
    38
	{
ds@1952
    39
		return Plugin_Continue;
ds@1952
    40
	}
ds@1952
    41
	
ds@1952
    42
	new startidx;
ds@1952
    43
	if (text[strlen(text)-1] == '"')
ds@1952
    44
	{
ds@1952
    45
		text[strlen(text)-1] = '\0';
ds@1952
    46
		startidx = 1;
ds@1952
    47
	}
ds@1952
    48
	
ds@1952
    49
	decl String:message[8];
ds@1952
    50
	BreakString(text[startidx], message, sizeof(message));
ds@1952
    51
	
ds@1952
    52
	if (strcmp(message, "nextmap", false) == 0)
ds@1952
    53
	{
ds@1952
    54
		decl String:map[32];
ds@1952
    55
		GetConVarString(g_Cvar_Nextmap, map, sizeof(map));
ds@1952
    56
		
ds@1952
    57
		PrintToChat(client, "%t", "Next Map", map);
ds@1952
    58
	}
ds@1952
    59
	else
ds@1952
    60
	{
ds@1952
    61
		if (GetConVarBool(g_Cvar_RockTheVote) && (strcmp(text[startidx], "rtv", false) == 0 || strcmp(text[startidx], "rockthevote", false) == 0))
ds@1952
    62
		{
ds@1952
    63
			if (g_MapChanged)
ds@1952
    64
			{
ds@1952
    65
				ReplyToCommand(client, "[SM] %t", "Map change in progress");
ds@1952
    66
				return Plugin_Continue;
ds@1952
    67
			}			
ds@1952
    68
			
ds@1952
    69
			if (!g_RTV_Allowed)
ds@1952
    70
			{
ds@1952
    71
				PrintToChat(client, "[SM] %t", "RTV Not Allowed");
ds@1952
    72
				return Plugin_Continue;
ds@1952
    73
			}
ds@1952
    74
			
ds@1952
    75
			if (g_RTV_Ended)
ds@1952
    76
			{
ds@1952
    77
				PrintToChat(client, "[SM] %t", "RTV Ended");
ds@1952
    78
				return Plugin_Continue;
ds@1952
    79
			}
ds@1952
    80
			
ds@1952
    81
			if (g_RTV_Started)
ds@1952
    82
			{
ds@1952
    83
				PrintToChat(client, "[SM] %t", "RTV Started");
ds@1952
    84
				return Plugin_Continue;
ds@1952
    85
			}
ds@1952
    86
			
ds@1952
    87
			if (GetClientCount(true) < GetConVarInt(g_Cvar_MinPlayers) && g_RTV_Votes == 0) // Should we keep checking g_Votes here?
ds@1952
    88
			{
ds@1952
    89
				PrintToChat(client, "[SM] %t", "Minimal Players Not Met");
ds@1952
    90
				return Plugin_Continue;			
ds@1952
    91
			}
ds@1952
    92
			
ds@1952
    93
			if (g_RTV_Voted[client])
ds@1952
    94
			{
ds@1952
    95
				PrintToChat(client, "[SM] %t", "Already Voted");
ds@1952
    96
				return Plugin_Continue;
ds@1952
    97
			}	
ds@1952
    98
			
ds@1952
    99
			new String:name[64];
ds@1952
   100
			GetClientName(client, name, sizeof(name));
ds@1952
   101
			
ds@1952
   102
			g_RTV_Votes++;
ds@1952
   103
			g_RTV_Voted[client] = true;
ds@1952
   104
			
ds@1952
   105
			PrintToChatAll("[SM] %t", "RTV Requested", name, g_RTV_Votes, g_RTV_VotesNeeded);
ds@1952
   106
			
ds@1952
   107
			if (g_RTV_Votes >= g_RTV_VotesNeeded)
ds@1952
   108
			{
ds@1952
   109
				g_RTV_Started = true;
ds@1952
   110
				CreateTimer(2.0, Timer_StartRTV, TIMER_FLAG_NO_MAPCHANGE);
ds@1952
   111
			}
ds@1952
   112
		}
ds@1952
   113
		else if (GetConVarBool(g_Cvar_Nominate) && strcmp(text[startidx], "nominate", false) == 0)
ds@1952
   114
		{
ds@1952
   115
			if (g_MapChanged)
ds@1952
   116
			{
ds@1952
   117
				ReplyToCommand(client, "[SM] %t", "Map change in progress");
ds@1952
   118
				return Plugin_Continue;
ds@1952
   119
			}
ds@1952
   120
			
ds@1952
   121
			if (g_RTV_Started || g_HasVoteStarted)
ds@1952
   122
			{
ds@1952
   123
				ReplyToCommand(client, "[SM] %t", "Map vote in progress");
ds@1952
   124
				return Plugin_Continue;				
ds@1952
   125
			}
ds@1952
   126
			
ds@1952
   127
			if (g_Nominated[client])
ds@1952
   128
			{
ds@1952
   129
				PrintToChat(client, "[SM] %t", "Already Nominated");
ds@1952
   130
				return Plugin_Continue;
ds@1952
   131
			}
ds@1952
   132
			
ds@1952
   133
			if (GetArraySize(g_Nominate) >= GetConVarInt(g_Cvar_Maps))
ds@1952
   134
			{
ds@1952
   135
				PrintToChat(client, "[SM] %t", "Max Nominations");
ds@1952
   136
				return Plugin_Continue;			
ds@1952
   137
			}
ds@1952
   138
			
ds@1952
   139
			DisplayMenu(g_Menu_Nominate, client, MENU_TIME_FOREVER);		
ds@1952
   140
		}		
ds@1952
   141
	}
ds@1952
   142
	
ds@1952
   143
	return Plugin_Continue;	
ds@1952
   144
}
ds@1952
   145
ds@1952
   146
public Action:Command_Mapvote(client, args)
ds@1952
   147
{
ds@1952
   148
	InitiateVote();
ds@1952
   149
ds@1952
   150
	return Plugin_Handled;	
ds@1952
   151
}
ds@1952
   152
 
ds@1952
   153
public Action:Command_Nextmap(args)
ds@1952
   154
{
ds@1952
   155
	decl String:map[64];
ds@1952
   156
	
ds@1952
   157
	GetConVarString(g_Cvar_Nextmap, map, sizeof(map));
ds@1952
   158
	
ds@1952
   159
	ReplyToCommand(0, "%t", "Next Map", map);
ds@1952
   160
	
ds@1952
   161
	return Plugin_Handled;
ds@1952
   162
} 
ds@1952
   163
 
ds@1952
   164
public Action:Command_List(client, args) 
ds@1952
   165
{
ds@1952
   166
	PrintToConsole(client, "Map Cycle:");
ds@1952
   167
	
ds@1952
   168
	decl String:currentMap[64];
ds@1952
   169
	GetCurrentMap(currentMap, 64);	
ds@1952
   170
	
ds@1952
   171
	decl String:mapName[64];
ds@1952
   172
	for (new i = 0; i < GetArraySize(g_MapCycle); i++)
ds@1952
   173
	{
ds@1952
   174
		GetArrayString(g_MapCycle, i, mapName, sizeof(mapName));
ds@1952
   175
		if (strcmp(mapName, currentMap) == 0)
ds@1952
   176
		{
ds@1952
   177
			PrintToConsole(client, "%s <========= Current map", mapName);
ds@1952
   178
		}
ds@1952
   179
		else if (strcmp(mapName, g_NextMap) == 0)
ds@1952
   180
		{
ds@1952
   181
			PrintToConsole(client, "%s <========= Next map", mapName);
ds@1952
   182
		}
ds@1952
   183
		else
ds@1952
   184
		{
ds@1952
   185
			PrintToConsole(client, "%s", mapName);
ds@1952
   186
		}
ds@1952
   187
	}
ds@1952
   188
 
ds@1952
   189
	return Plugin_Handled;
ds@1952
   190
} 
ds@1952
   191
ds@1952
   192
public Action:Command_SetNextmap(client, args)
ds@1952
   193
{
ds@1952
   194
	if (args < 1)
ds@1952
   195
	{
ds@1952
   196
		ReplyToCommand(client, "[SM] Usage: sm_setnextmap <map>");
ds@1952
   197
		return Plugin_Handled;
ds@1952
   198
	}
ds@1952
   199
	
ds@1952
   200
	if (g_MapChanged)
ds@1952
   201
	{
ds@1952
   202
		ReplyToCommand(client, "[SM] %t", "Map change in progress");
ds@1952
   203
		return Plugin_Handled;
ds@1952
   204
	}	
ds@1952
   205
ds@1952
   206
	decl String:map[64];
ds@1952
   207
	GetCmdArg(1, map, sizeof(map));
ds@1952
   208
ds@1952
   209
	if (!IsMapValid(map))
ds@1952
   210
	{
ds@1952
   211
		ReplyToCommand(client, "[SM] %t", "Map was not found", map);
ds@1952
   212
		return Plugin_Handled;
ds@1952
   213
	}
ds@1952
   214
ds@1952
   215
	ShowActivity(client, "%t", "Cvar changed", "sm_nextmap", map);
ds@1952
   216
	LogMessage("\"%L\" changed sm_nextmap to \"%s\"", client, map);
ds@1952
   217
ds@1952
   218
	SetNextMap(map);
ds@1952
   219
ds@1952
   220
	return Plugin_Handled;
ds@1952
   221
}
ds@1952
   222
 
ds@1952
   223
 public Action:Command_Map(client, args)
ds@1952
   224
 {
ds@1952
   225
	if (args < 1)
ds@1952
   226
	{
ds@1952
   227
		ReplyToCommand(client, "[SM] Usage: sm_map <map> [r/e]");
ds@1952
   228
		return Plugin_Handled;
ds@1952
   229
	}
ds@1952
   230
	
ds@1952
   231
	if (g_MapChanged)
ds@1952
   232
	{
ds@1952
   233
		ReplyToCommand(client, "[SM] %t", "Map change in progress");
ds@1952
   234
		return Plugin_Handled;
ds@1952
   235
	}
ds@1952
   236
 
ds@1952
   237
	decl String:map[64];
ds@1952
   238
	GetCmdArg(1, map, sizeof(map));
ds@1952
   239
 
ds@1952
   240
	if (!IsMapValid(map))
ds@1952
   241
	{
ds@1952
   242
		ReplyToCommand(client, "[SM] %t", "Map was not found", map);
ds@1952
   243
		return Plugin_Handled;
ds@1952
   244
	}
ds@1952
   245
	
ds@1952
   246
	decl String:when[2];
ds@1952
   247
	if (args > 1)
ds@1952
   248
	{
ds@1952
   249
		GetCmdArg(2, when, sizeof(when));
ds@1952
   250
		
ds@1952
   251
		when[0] = CharToLower(when[0]);
ds@1952
   252
		if (when[0] != 'r' && when[0] != 'e')
ds@1952
   253
		{
ds@1952
   254
			when[0] = 'i';
ds@1952
   255
		}	
ds@1952
   256
	}
ds@1952
   257
	
ds@1952
   258
	SetMapChange(client, map, when);
ds@1952
   259
 
ds@1952
   260
	return Plugin_Handled;
ds@1952
   261
}
ds@1952
   262
ds@1952
   263
public Action:Command_Votemap(client, args)
ds@1952
   264
{
ds@1952
   265
	if (args < 1)
ds@1952
   266
	{
ds@1952
   267
		ReplyToCommand(client, "[SM] Usage: sm_votemap [r/e] <mapname> [mapname2] ... [mapname5]");
ds@1952
   268
		return Plugin_Handled;	
ds@1952
   269
	}
ds@1952
   270
	
ds@1952
   271
	if (g_MapChanged)
ds@1952
   272
	{
ds@1952
   273
		ReplyToCommand(client, "[SM] %t", "Map change in progress");
ds@1952
   274
		return Plugin_Handled;
ds@1952
   275
	}	
ds@1952
   276
	
ds@1952
   277
	if (IsVoteInProgress())
ds@1952
   278
	{
ds@1952
   279
		ReplyToCommand(client, "[SM] %t", "Vote in Progress");
ds@1952
   280
		return Plugin_Handled;
ds@1952
   281
	}
ds@1952
   282
		
ds@1952
   283
	if (!TestVoteDelay(client))
ds@1952
   284
	{
ds@1952
   285
		return Plugin_Handled;
ds@1952
   286
	}
ds@1952
   287
	
ds@1952
   288
	decl String:text[256];
ds@1952
   289
	GetCmdArgString(text, sizeof(text));
ds@1952
   290
ds@1952
   291
	decl String:maps[5][64];
ds@1952
   292
	new mapCount;	
ds@1952
   293
	new len, pos;
ds@1952
   294
ds@1952
   295
	// Find out if the user specified "when"
ds@1952
   296
	decl String:when[64];
ds@1952
   297
	pos = BreakString(text[len], when, sizeof(when));
ds@1952
   298
	if (!IsMapValid(when))
ds@1952
   299
	{
ds@1952
   300
		when[0] = CharToLower(when[0]);
ds@1952
   301
		if (when[0] != 'r' && when[0] != 'e')
ds@1952
   302
		{
ds@1952
   303
			ReplyToCommand(client, "[SM] %t", "Map was not found", maps[mapCount]);
ds@1952
   304
			return Plugin_Handled;
ds@1952
   305
		}
ds@1952
   306
	}
ds@1952
   307
	else
ds@1952
   308
	{
ds@1952
   309
		strcpy(maps[mapCount], sizeof(maps[]), when);
ds@1952
   310
		mapCount++;
ds@1952
   311
		when[0] = 'i';
ds@1952
   312
	}
ds@1952
   313
	
ds@1952
   314
	len += pos;
ds@1952
   315
	
ds@1952
   316
	while (pos != -1 && mapCount < 5)
ds@1952
   317
	{	
ds@1952
   318
		pos = BreakString(text[len], maps[mapCount], sizeof(maps[]));
ds@1952
   319
		
ds@1952
   320
		if (!IsMapValid(maps[mapCount]))
ds@1952
   321
		{
ds@1952
   322
			ReplyToCommand(client, "[SM] %t", "Map was not found", maps[mapCount]);
ds@1952
   323
			return Plugin_Handled;
ds@1952
   324
		}		
ds@1952
   325
ds@1952
   326
		mapCount++;
ds@1952
   327
		
ds@1952
   328
		len += pos;
ds@1952
   329
	}
ds@1952
   330
ds@1952
   331
	g_VoteMapInUse = client;
ds@1952
   332
	g_Client_Data[client][0] = when[0];
ds@1952
   333
ds@1952
   334
	DisplayVoteMapMenu(client, mapCount, maps);
ds@1952
   335
	
ds@1952
   336
	return Plugin_Handled;	
ds@1952
   337
}
ds@1952
   338
ds@1952
   339
public Action:Command_Nominate(client, args)
ds@1952
   340
{
ds@1952
   341
	if (args < 1)
ds@1952
   342
	{
ds@1952
   343
		ReplyToCommand(client, "[SM] Usage: sm_nominate <mapname>");
ds@1952
   344
		return Plugin_Handled;
ds@1952
   345
	}
ds@1952
   346
	
ds@1952
   347
	if (!GetConVarBool(g_Cvar_Nominate))
ds@1952
   348
	{
ds@1952
   349
		ReplyToCommand(client, "[SM] Nominations are currently disabled.");
ds@1952
   350
		return Plugin_Handled;
ds@1952
   351
	}
ds@1952
   352
	
ds@1952
   353
	decl String:mapname[64];
ds@1952
   354
	GetCmdArg(1, mapname, sizeof(mapname));
ds@1952
   355
ds@1952
   356
	if (FindStringInArray(g_MapList, mapname) == -1)
ds@1952
   357
	{
ds@1952
   358
		ReplyToCommand(client, "%t", "Map was not found", mapname);
ds@1952
   359
		return Plugin_Handled;
ds@1952
   360
	}
ds@1952
   361
	
ds@1952
   362
	if (GetArraySize(g_Nominated) > 0)
ds@1952
   363
	{
ds@1952
   364
		if (FindStringInArray(g_Nominated, mapname) != -1)
ds@1952
   365
		{
ds@1952
   366
			ReplyToCommand(client, "%t", "Map Already In Vote", mapname);
ds@1952
   367
			return Plugin_Handled;				
ds@1952
   368
		}
ds@1952
   369
		
ds@1952
   370
		ShiftArrayUp(g_Nominated, 0);
ds@1952
   371
		SetArrayString(g_Nominated, 0, mapname);
ds@1952
   372
		
ds@1952
   373
		while (GetArraySize(g_Nominated) > GetConVarInt(g_Cvar_Maps))
ds@1952
   374
		{
ds@1952
   375
			RemoveFromArray(g_Nominated, GetConVarInt(g_Cvar_Maps));
ds@1952
   376
		}
ds@1952
   377
	}
ds@1952
   378
	else
ds@1952
   379
	{
ds@1952
   380
		PushArrayString(g_Nominated, mapname);
ds@1952
   381
	}
ds@1952
   382
		
ds@1952
   383
	decl String:item[64];
ds@1952
   384
	for (new i = 0; i < GetMenuItemCount(g_Menu_Nominate); i++)
ds@1952
   385
	{
ds@1952
   386
		GetMenuItem(g_Menu_Nominate, i, item, sizeof(item));
ds@1952
   387
		if (strcmp(item, mapname) == 0)
ds@1952
   388
		{
ds@1952
   389
			RemoveMenuItem(g_Menu_Nominate, i);
ds@1952
   390
			break;
ds@1952
   391
		}			
ds@1952
   392
	}	
ds@1952
   393
	
ds@1952
   394
	ReplyToCommand(client, "%t", "Map Inserted", mapname);
ds@1952
   395
	LogAction(client, -1, "\"%L\" inserted map \"%s\".", client, mapname);
ds@1952
   396
ds@1952
   397
	return Plugin_Handled;		
ds@1952
   398
}