plugins/include/sdktools_stocks.inc
author David Anderson <dvander@alliedmods.net>
Sun Aug 11 11:31:55 2013 -0700 (2013-08-11)
changeset 3986 f49be7182920
parent 2447 a780bc83f8d7
permissions -rw-r--r--
Remove InfoVars::stp (bug 5844 part 3, r=fyren).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     5  * =============================================================================
     6  *
     7  * This file is part of the SourceMod/SourcePawn SDK.
     8  *
     9  * This program is free software; you can redistribute it and/or modify it under
    10  * the terms of the GNU General Public License, version 3.0, as published by the
    11  * Free Software Foundation.
    12  * 
    13  * This program is distributed in the hope that it will be useful, but WITHOUT
    14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    16  * details.
    17  *
    18  * You should have received a copy of the GNU General Public License along with
    19  * this program.  If not, see <http://www.gnu.org/licenses/>.
    20  *
    21  * As a special exception, AlliedModders LLC gives you permission to link the
    22  * code of this program (as well as its derivative works) to "Half-Life 2," the
    23  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    24  * by the Valve Corporation.  You must obey the GNU General Public License in
    25  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    26  * this exception to all derivative works.  AlliedModders LLC defines further
    27  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    28  * or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #if defined _sdktools_stocks_included
    34   #endinput
    35 #endif
    36 #define _sdktools_stocks_included
    37 
    38 /**
    39  * Given a partial team name, attempts to find a matching team.
    40  *
    41  * The search is performed case insensitively and only against the 
    42  * first N characters of the team names, where N is the number of 
    43  * characters in the search pattern.
    44  *
    45  * @param name		Partial or full team name.  
    46  * @return			A valid team index on success.
    47  * 					-1 if no team matched.
    48  *					-2 if more than one team matched.
    49  */
    50 stock FindTeamByName(const String:name[])
    51 {
    52 	new name_len = strlen(name);
    53 	new num_teams = GetTeamCount();
    54 	decl String:team_name[32];
    55 	new found_team = -1;
    56 
    57 	for (new i = 0; i < num_teams; i++)
    58 	{
    59 		GetTeamName(i, team_name, sizeof(team_name));
    60 
    61 		if (strncmp(team_name, name, name_len, false) == 0)
    62 		{
    63 			if (found_team >= 0)
    64 			{
    65 				return -2;
    66 			}
    67 			else
    68 			{
    69 				found_team = i;
    70 			}
    71 		}
    72 	}
    73 
    74 	return found_team;
    75 }
    76