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