plugins/mapmanager/commands.sp
branchsourcemod-1.1.0
changeset 1807 a0de5251fb1a
child 1947 e73a1e51833b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/mapmanager/commands.sp	Wed Dec 19 22:19:34 2007 +0000
     1.3 @@ -0,0 +1,398 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod Map Manager Plugin
     1.8 + * Contains callbacks for commands
     1.9 + *
    1.10 + * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
    1.11 + * =============================================================================
    1.12 + *
    1.13 + * This program is free software; you can redistribute it and/or modify it under
    1.14 + * the terms of the GNU General Public License, version 3.0, as published by the
    1.15 + * Free Software Foundation.
    1.16 + * 
    1.17 + * This program is distributed in the hope that it will be useful, but WITHOUT
    1.18 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.19 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.20 + * details.
    1.21 + *
    1.22 + * You should have received a copy of the GNU General Public License along with
    1.23 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.24 + *
    1.25 + * As a special exception, AlliedModders LLC gives you permission to link the
    1.26 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.27 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.28 + * by the Valve Corporation.  You must obey the GNU General Public License in
    1.29 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.30 + * this exception to all derivative works.  AlliedModders LLC defines further
    1.31 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.32 + * or <http://www.sourcemod.net/license.php>.
    1.33 + *
    1.34 + * Version: $Id$
    1.35 + */
    1.36 + 
    1.37 + public Action:Command_Say(client, args)
    1.38 + {
    1.39 +	decl String:text[192];
    1.40 +	if (GetCmdArgString(text, sizeof(text)) < 1)
    1.41 +	{
    1.42 +		return Plugin_Continue;
    1.43 +	}
    1.44 +	
    1.45 +	new startidx;
    1.46 +	if (text[strlen(text)-1] == '"')
    1.47 +	{
    1.48 +		text[strlen(text)-1] = '\0';
    1.49 +		startidx = 1;
    1.50 +	}
    1.51 +	
    1.52 +	decl String:message[8];
    1.53 +	BreakString(text[startidx], message, sizeof(message));
    1.54 +	
    1.55 +	if (strcmp(message, "nextmap", false) == 0)
    1.56 +	{
    1.57 +		decl String:map[32];
    1.58 +		GetConVarString(g_Cvar_Nextmap, map, sizeof(map));
    1.59 +		
    1.60 +		PrintToChat(client, "%t", "Next Map", map);
    1.61 +	}
    1.62 +	else
    1.63 +	{
    1.64 +		if (GetConVarBool(g_Cvar_RockTheVote) && (strcmp(text[startidx], "rtv", false) == 0 || strcmp(text[startidx], "rockthevote", false) == 0))
    1.65 +		{
    1.66 +			if (g_MapChanged)
    1.67 +			{
    1.68 +				ReplyToCommand(client, "[SM] %t", "Map change in progress");
    1.69 +				return Plugin_Continue;
    1.70 +			}			
    1.71 +			
    1.72 +			if (!g_RTV_Allowed)
    1.73 +			{
    1.74 +				PrintToChat(client, "[SM] %t", "RTV Not Allowed");
    1.75 +				return Plugin_Continue;
    1.76 +			}
    1.77 +			
    1.78 +			if (g_RTV_Ended)
    1.79 +			{
    1.80 +				PrintToChat(client, "[SM] %t", "RTV Ended");
    1.81 +				return Plugin_Continue;
    1.82 +			}
    1.83 +			
    1.84 +			if (g_RTV_Started)
    1.85 +			{
    1.86 +				PrintToChat(client, "[SM] %t", "RTV Started");
    1.87 +				return Plugin_Continue;
    1.88 +			}
    1.89 +			
    1.90 +			if (GetClientCount(true) < GetConVarInt(g_Cvar_MinPlayers) && g_RTV_Votes == 0) // Should we keep checking g_Votes here?
    1.91 +			{
    1.92 +				PrintToChat(client, "[SM] %t", "Minimal Players Not Met");
    1.93 +				return Plugin_Continue;			
    1.94 +			}
    1.95 +			
    1.96 +			if (g_RTV_Voted[client])
    1.97 +			{
    1.98 +				PrintToChat(client, "[SM] %t", "Already Voted");
    1.99 +				return Plugin_Continue;
   1.100 +			}	
   1.101 +			
   1.102 +			new String:name[64];
   1.103 +			GetClientName(client, name, sizeof(name));
   1.104 +			
   1.105 +			g_RTV_Votes++;
   1.106 +			g_RTV_Voted[client] = true;
   1.107 +			
   1.108 +			PrintToChatAll("[SM] %t", "RTV Requested", name, g_RTV_Votes, g_RTV_VotesNeeded);
   1.109 +			
   1.110 +			if (g_RTV_Votes >= g_RTV_VotesNeeded)
   1.111 +			{
   1.112 +				g_RTV_Started = true;
   1.113 +				CreateTimer(2.0, Timer_StartRTV, TIMER_FLAG_NO_MAPCHANGE);
   1.114 +			}
   1.115 +		}
   1.116 +		else if (GetConVarBool(g_Cvar_Nominate) && strcmp(text[startidx], "nominate", false) == 0)
   1.117 +		{
   1.118 +			if (g_MapChanged)
   1.119 +			{
   1.120 +				ReplyToCommand(client, "[SM] %t", "Map change in progress");
   1.121 +				return Plugin_Continue;
   1.122 +			}
   1.123 +			
   1.124 +			if (g_RTV_Started || g_HasVoteStarted)
   1.125 +			{
   1.126 +				ReplyToCommand(client, "[SM] %t", "Map vote in progress");
   1.127 +				return Plugin_Continue;				
   1.128 +			}
   1.129 +			
   1.130 +			if (g_Nominated[client])
   1.131 +			{
   1.132 +				PrintToChat(client, "[SM] %t", "Already Nominated");
   1.133 +				return Plugin_Continue;
   1.134 +			}
   1.135 +			
   1.136 +			if (GetArraySize(g_Nominate) >= GetConVarInt(g_Cvar_Maps))
   1.137 +			{
   1.138 +				PrintToChat(client, "[SM] %t", "Max Nominations");
   1.139 +				return Plugin_Continue;			
   1.140 +			}
   1.141 +			
   1.142 +			DisplayMenu(g_Menu_Nominate, client, MENU_TIME_FOREVER);		
   1.143 +		}		
   1.144 +	}
   1.145 +	
   1.146 +	return Plugin_Continue;	
   1.147 +}
   1.148 +
   1.149 +public Action:Command_Mapvote(client, args)
   1.150 +{
   1.151 +	InitiateVote();
   1.152 +
   1.153 +	return Plugin_Handled;	
   1.154 +}
   1.155 + 
   1.156 +public Action:Command_Nextmap(args)
   1.157 +{
   1.158 +	decl String:map[64];
   1.159 +	
   1.160 +	GetConVarString(g_Cvar_Nextmap, map, sizeof(map));
   1.161 +	
   1.162 +	ReplyToCommand(0, "%t", "Next Map", map);
   1.163 +	
   1.164 +	return Plugin_Handled;
   1.165 +} 
   1.166 + 
   1.167 +public Action:Command_List(client, args) 
   1.168 +{
   1.169 +	PrintToConsole(client, "Map Cycle:");
   1.170 +	
   1.171 +	decl String:currentMap[64];
   1.172 +	GetCurrentMap(currentMap, 64);	
   1.173 +	
   1.174 +	decl String:mapName[64];
   1.175 +	for (new i = 0; i < GetArraySize(g_MapCycle); i++)
   1.176 +	{
   1.177 +		GetArrayString(g_MapCycle, i, mapName, sizeof(mapName));
   1.178 +		if (strcmp(mapName, currentMap) == 0)
   1.179 +		{
   1.180 +			PrintToConsole(client, "%s <========= Current map", mapName);
   1.181 +		}
   1.182 +		else if (strcmp(mapName, g_NextMap) == 0)
   1.183 +		{
   1.184 +			PrintToConsole(client, "%s <========= Next map", mapName);
   1.185 +		}
   1.186 +		else
   1.187 +		{
   1.188 +			PrintToConsole(client, "%s", mapName);
   1.189 +		}
   1.190 +	}
   1.191 + 
   1.192 +	return Plugin_Handled;
   1.193 +} 
   1.194 +
   1.195 +public Action:Command_SetNextmap(client, args)
   1.196 +{
   1.197 +	if (args < 1)
   1.198 +	{
   1.199 +		ReplyToCommand(client, "[SM] Usage: sm_setnextmap <map>");
   1.200 +		return Plugin_Handled;
   1.201 +	}
   1.202 +	
   1.203 +	if (g_MapChanged)
   1.204 +	{
   1.205 +		ReplyToCommand(client, "[SM] %t", "Map change in progress");
   1.206 +		return Plugin_Handled;
   1.207 +	}	
   1.208 +
   1.209 +	decl String:map[64];
   1.210 +	GetCmdArg(1, map, sizeof(map));
   1.211 +
   1.212 +	if (!IsMapValid(map))
   1.213 +	{
   1.214 +		ReplyToCommand(client, "[SM] %t", "Map was not found", map);
   1.215 +		return Plugin_Handled;
   1.216 +	}
   1.217 +
   1.218 +	ShowActivity(client, "%t", "Cvar changed", "sm_nextmap", map);
   1.219 +	LogMessage("\"%L\" changed sm_nextmap to \"%s\"", client, map);
   1.220 +
   1.221 +	SetNextMap(map);
   1.222 +
   1.223 +	return Plugin_Handled;
   1.224 +}
   1.225 + 
   1.226 + public Action:Command_Map(client, args)
   1.227 + {
   1.228 +	if (args < 1)
   1.229 +	{
   1.230 +		ReplyToCommand(client, "[SM] Usage: sm_map <map> [r/e]");
   1.231 +		return Plugin_Handled;
   1.232 +	}
   1.233 +	
   1.234 +	if (g_MapChanged)
   1.235 +	{
   1.236 +		ReplyToCommand(client, "[SM] %t", "Map change in progress");
   1.237 +		return Plugin_Handled;
   1.238 +	}
   1.239 + 
   1.240 +	decl String:map[64];
   1.241 +	GetCmdArg(1, map, sizeof(map));
   1.242 + 
   1.243 +	if (!IsMapValid(map))
   1.244 +	{
   1.245 +		ReplyToCommand(client, "[SM] %t", "Map was not found", map);
   1.246 +		return Plugin_Handled;
   1.247 +	}
   1.248 +	
   1.249 +	decl String:when[2];
   1.250 +	if (args > 1)
   1.251 +	{
   1.252 +		GetCmdArg(2, when, sizeof(when));
   1.253 +		
   1.254 +		when[0] = CharToLower(when[0]);
   1.255 +		if (when[0] != 'r' && when[0] != 'e')
   1.256 +		{
   1.257 +			when[0] = 'i';
   1.258 +		}	
   1.259 +	}
   1.260 +	
   1.261 +	SetMapChange(client, map, when);
   1.262 + 
   1.263 +	return Plugin_Handled;
   1.264 +}
   1.265 +
   1.266 +public Action:Command_Votemap(client, args)
   1.267 +{
   1.268 +	if (args < 1)
   1.269 +	{
   1.270 +		ReplyToCommand(client, "[SM] Usage: sm_votemap [r/e] <mapname> [mapname2] ... [mapname5]");
   1.271 +		return Plugin_Handled;	
   1.272 +	}
   1.273 +	
   1.274 +	if (g_MapChanged)
   1.275 +	{
   1.276 +		ReplyToCommand(client, "[SM] %t", "Map change in progress");
   1.277 +		return Plugin_Handled;
   1.278 +	}	
   1.279 +	
   1.280 +	if (IsVoteInProgress())
   1.281 +	{
   1.282 +		ReplyToCommand(client, "[SM] %t", "Vote in Progress");
   1.283 +		return Plugin_Handled;
   1.284 +	}
   1.285 +		
   1.286 +	if (!TestVoteDelay(client))
   1.287 +	{
   1.288 +		return Plugin_Handled;
   1.289 +	}
   1.290 +	
   1.291 +	decl String:text[256];
   1.292 +	GetCmdArgString(text, sizeof(text));
   1.293 +
   1.294 +	decl String:maps[5][64];
   1.295 +	new mapCount;	
   1.296 +	new len, pos;
   1.297 +
   1.298 +	// Find out if the user specified "when"
   1.299 +	decl String:when[64];
   1.300 +	pos = BreakString(text[len], when, sizeof(when));
   1.301 +	if (!IsMapValid(when))
   1.302 +	{
   1.303 +		when[0] = CharToLower(when[0]);
   1.304 +		if (when[0] != 'r' && when[0] != 'e')
   1.305 +		{
   1.306 +			ReplyToCommand(client, "[SM] %t", "Map was not found", maps[mapCount]);
   1.307 +			return Plugin_Handled;
   1.308 +		}
   1.309 +	}
   1.310 +	else
   1.311 +	{
   1.312 +		strcpy(maps[mapCount], sizeof(maps[]), when);
   1.313 +		mapCount++;
   1.314 +		when[0] = 'i';
   1.315 +	}
   1.316 +	
   1.317 +	len += pos;
   1.318 +	
   1.319 +	while (pos != -1 && mapCount < 5)
   1.320 +	{	
   1.321 +		pos = BreakString(text[len], maps[mapCount], sizeof(maps[]));
   1.322 +		
   1.323 +		if (!IsMapValid(maps[mapCount]))
   1.324 +		{
   1.325 +			ReplyToCommand(client, "[SM] %t", "Map was not found", maps[mapCount]);
   1.326 +			return Plugin_Handled;
   1.327 +		}		
   1.328 +
   1.329 +		mapCount++;
   1.330 +		
   1.331 +		len += pos;
   1.332 +	}
   1.333 +
   1.334 +	g_VoteMapInUse = client;
   1.335 +	g_Client_Data[client][0] = when[0];
   1.336 +
   1.337 +	DisplayVoteMapMenu(client, mapCount, maps);
   1.338 +	
   1.339 +	return Plugin_Handled;	
   1.340 +}
   1.341 +
   1.342 +public Action:Command_Nominate(client, args)
   1.343 +{
   1.344 +	if (args < 1)
   1.345 +	{
   1.346 +		ReplyToCommand(client, "[SM] Usage: sm_nominate <mapname>");
   1.347 +		return Plugin_Handled;
   1.348 +	}
   1.349 +	
   1.350 +	if (!GetConVarBool(g_Cvar_Nominate))
   1.351 +	{
   1.352 +		ReplyToCommand(client, "[SM] Nominations are currently disabled.");
   1.353 +		return Plugin_Handled;
   1.354 +	}
   1.355 +	
   1.356 +	decl String:mapname[64];
   1.357 +	GetCmdArg(1, mapname, sizeof(mapname));
   1.358 +
   1.359 +	if (FindStringInArray(g_MapList, mapname) == -1)
   1.360 +	{
   1.361 +		ReplyToCommand(client, "%t", "Map was not found", mapname);
   1.362 +		return Plugin_Handled;
   1.363 +	}
   1.364 +	
   1.365 +	if (GetArraySize(g_Nominated) > 0)
   1.366 +	{
   1.367 +		if (FindStringInArray(g_Nominated, mapname) != -1)
   1.368 +		{
   1.369 +			ReplyToCommand(client, "%t", "Map Already In Vote", mapname);
   1.370 +			return Plugin_Handled;				
   1.371 +		}
   1.372 +		
   1.373 +		ShiftArrayUp(g_Nominated, 0);
   1.374 +		SetArrayString(g_Nominated, 0, mapname);
   1.375 +		
   1.376 +		while (GetArraySize(g_Nominated) > GetConVarInt(g_Cvar_Maps))
   1.377 +		{
   1.378 +			RemoveFromArray(g_Nominated, GetConVarInt(g_Cvar_Maps));
   1.379 +		}
   1.380 +	}
   1.381 +	else
   1.382 +	{
   1.383 +		PushArrayString(g_Nominated, mapname);
   1.384 +	}
   1.385 +		
   1.386 +	decl String:item[64];
   1.387 +	for (new i = 0; i < GetMenuItemCount(g_Menu_Nominate); i++)
   1.388 +	{
   1.389 +		GetMenuItem(g_Menu_Nominate, i, item, sizeof(item));
   1.390 +		if (strcmp(item, mapname) == 0)
   1.391 +		{
   1.392 +			RemoveMenuItem(g_Menu_Nominate, i);
   1.393 +			break;
   1.394 +		}			
   1.395 +	}	
   1.396 +	
   1.397 +	ReplyToCommand(client, "%t", "Map Inserted", mapname);
   1.398 +	LogAction(client, -1, "\"%L\" inserted map \"%s\".", client, mapname);
   1.399 +
   1.400 +	return Plugin_Handled;		
   1.401 +}
   1.402 \ No newline at end of file