Thread: Two questions!
View Single Post
Old 06-09-2006, 03:42 PM   #16
Dom_152
Rookie
 
Dom_152's Avatar
 
Join Date: Jan 2006
Location: England
Posts: 150
Wow! I'm rather pleased with myself! I managed to create Partial name detection all on my own! Weee!

BOO OK I didn't... no Matter what name I enter it always kills me :S.
Anyhelp?

Code:
int G_ClientNumberFromPartialName(char *partial)
{
	int clientnumber = 0;
	gentity_t *tent;
	gentity_t *final;
	char *tempname = "";
	char *partialname = "";	
	char *name;
	int i;
	int y = 0;
	int x;	
	int matches[MAX_CLIENTS];	
	int finalmatch = 0;
	//char finalname[1024];
	int max_value = 0;
	int max_index = -1;

	//SanitizeString2(partial, partialname);
	partialname = partial;

	//First client pass
	for(i = 0; i < MAX_CLIENTS; i++)
	{
		tent = &g_entities[i];
		name = tent->client->pers.netname; 
		tempname = name;
		//SanitizeString2(name, tempname);

		if(!tent->client)
		{
			break; //if the client doesn't exist move on to the next one.
		}
		//Second Name pass
		//We compare each letter in the partial name ot the name of the client we are checking
		//And note down any matches
		for(x = 0; x < sizeof(tempname); x++)
		{
			if(partialname[y] == tempname[x])
			{
				matches[i]++; //Increase the number of matches for this client
				y++; //Move on to the next letter in the partial name
			}
			else
			{
				 continue; //If they don't match just try the next letter
			}
		}
	}

	//Check which client has the most amount of matches
	for(x = 0 ; x < MAX_CLIENTS ; x++)
	{
		if(matches[x] > max_value)
		{		
			max_value = matches[x];
			finalmatch = x;
		}
		
		//If there is more than one final match just quit the function
		if(matches[x] == max_value)
		{
			return -1; //The calling function will knwo this means More than one match
		}
	}	
	
	final = &g_entities[finalmatch];	
	clientnumber = G_ClientNumberFromStrippedName(final->client->pers.netname);

	return clientnumber;

}

Last edited by Dom_152; 06-09-2006 at 04:14 PM.
Dom_152 is offline   you may: quote & reply,