added function for resolving team names -> indexes
authorDavid Anderson <dvander@alliedmods.net>
Sun Oct 21 00:16:46 2007 +0000 (2007-10-21)
changeset 1616173e015bac82
parent 1615 acf9a0befda7
child 1617 e0bcb6bb82fd
added function for resolving team names -> indexes
plugins/include/sdktools.inc
plugins/include/sdktools_stocks.inc
     1.1 --- a/plugins/include/sdktools.inc	Sat Oct 20 23:47:15 2007 +0000
     1.2 +++ b/plugins/include/sdktools.inc	Sun Oct 21 00:16:46 2007 +0000
     1.3 @@ -189,6 +189,7 @@
     1.4   */
     1.5  native any:SDKCall(Handle:call, any:...);
     1.6  
     1.7 +#include <sdktools_stocks>
     1.8  
     1.9  /**
    1.10   * Do not edit below this line!
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/plugins/include/sdktools_stocks.inc	Sun Oct 21 00:16:46 2007 +0000
     2.3 @@ -0,0 +1,76 @@
     2.4 +/**
     2.5 + * vim: set ts=4 :
     2.6 + * =============================================================================
     2.7 + * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     2.8 + * =============================================================================
     2.9 + *
    2.10 + * This file is part of the SourceMod/SourcePawn SDK.
    2.11 + *
    2.12 + * This program is free software; you can redistribute it and/or modify it under
    2.13 + * the terms of the GNU General Public License, version 3.0, as published by the
    2.14 + * Free Software Foundation.
    2.15 + * 
    2.16 + * This program is distributed in the hope that it will be useful, but WITHOUT
    2.17 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    2.18 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    2.19 + * details.
    2.20 + *
    2.21 + * You should have received a copy of the GNU General Public License along with
    2.22 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    2.23 + *
    2.24 + * As a special exception, AlliedModders LLC gives you permission to link the
    2.25 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    2.26 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    2.27 + * by the Valve Corporation.  You must obey the GNU General Public License in
    2.28 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    2.29 + * this exception to all derivative works.  AlliedModders LLC defines further
    2.30 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    2.31 + * or <http://www.sourcemod.net/license.php>.
    2.32 + *
    2.33 + * Version: $Id$
    2.34 + */
    2.35 +
    2.36 +#if defined _sdktools_stocks_included
    2.37 +  #endinput
    2.38 +#endif
    2.39 +#define _sdktools_stocks_included
    2.40 +
    2.41 +/**
    2.42 + * Given a partial team name, attempts to find a matching team.
    2.43 + *
    2.44 + * The search is performed case insensitively and only against the 
    2.45 + * first N characters of the team names, where N is the number of 
    2.46 + * characters in the search pattern.
    2.47 + *
    2.48 + * @param name		Partial or full team name.  
    2.49 + * @return			A valid team index on success.
    2.50 + * 					-1 if no team matched.
    2.51 + *					-2 if more than one team matched.
    2.52 + */
    2.53 +stock FindTeamByName(const String:name[])
    2.54 +{
    2.55 +	new name_len = strlen(name);
    2.56 +	new num_teams = GetTeamCount();
    2.57 +	decl String:team_name[32];
    2.58 +	new found_team = -1
    2.59 +
    2.60 +	for (new i = 0; i < num_teams; i++)
    2.61 +	{
    2.62 +		GetTeamName(i, team_name, sizeof(team_name));
    2.63 +
    2.64 +		if (strncmp(team_name, name, name_len) == 0)
    2.65 +		{
    2.66 +			if (found_team >= 0)
    2.67 +			{
    2.68 +				return -2;
    2.69 +			}
    2.70 +			else
    2.71 +			{
    2.72 +				found_team = i;
    2.73 +			}
    2.74 +		}
    2.75 +	}
    2.76 +
    2.77 +	return found_team;
    2.78 +}
    2.79 +