Strfind [Issue] [0.3c]
#1

I tried making this to prevent people from replacing the character 'l' with an capitalized 'i'. Unfortunally it didn't go like I expected it to go. I used to code below to make it work and got kicked everytime, even when I used a random name which didn't even have the 'I' or 'i' included.. I basically got the player's first and lastname seperately and checked them for a capitalized 'I', when the 'I' was used but not as first letter it would end up being invalid and result in a kick.
Код:
stock GetPlayerInvalidCharacterName(playerid)
{
	if(strfind(GetPlayerFirstName(playerid), "I", true) != 0)
	{
		printf("Firstname %s.", GetPlayerFirstName(playerid));
		printf("Firstname %d.", strfind(GetPlayerFirstName(playerid), "I") != 0);
		return 1;
	}
	if(strfind(GetPlayerLastName(playerid), "I", true) != 0)
	{
		printf("Firstname %s.", GetPlayerLastName(playerid));
		printf("Lastname %d.", strfind(GetPlayerLastName(playerid), "I") != 0);
		return 1;
	}
	return 0;
}
This was used in OnPlayerLogin:
Код:
if(GetPlayerInvalidCharacterName(playerid))
{
	SendClientMessage(playerid, COLOR_LIGHTRED, "[SERVER] Your username contains characters which aren't       allowed on this server.");
	Kick(playerid);
}
And this was used to get the seperate firstname and lastname of a player:
Код:
stock GetPlayerFirstName(playerid)
{
	new namestring[2][MAX_PLAYER_NAME];
	new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid,name,MAX_PLAYER_NAME);
	split(name, namestring, '_');
	return namestring[0];
}

stock GetPlayerLastName(playerid)
{
	new namestring[2][MAX_PLAYER_NAME];
	new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid,name,MAX_PLAYER_NAME);
	split(name, namestring, '_');
	return namestring[1];
}
Reply
#2

!= -1 not 0
Reply
#3

!= -1 means it starts with -1. I want the Strfind to start with 0 so the first letter won't get read. Like Berky_Brada. It should only read 'erky_rada'. If I would use != -1 it would perform a check of the whole name 'Berky_Brada'.
Reply
#4

What would you suggest me to do ******?
Reply
#5

you should learn the functions before you use them.
using true would be ignoring the case so it'd react to i as well as I, if it returns -1 then its not found, if it returns 0 then it's the first position.

native strfind(const string[], const sub[], bool:ignorecase=false, pos=0);

if(strfind(GetPlayerFirstName(playerid), "I", false,1) != -1)
Reply
#6

Ah yeah I know, I did use nothing because default was 'False' already so I tried 'true' maybe that would work which didn't. So both don't work actually..
Reply
#7

did you try to test like that?
Код:
if(strfind(GetPlayerFirstName(playerid), "I", false) > 0)
..so a > instead !=
strfind returns -1 if no match. 0 at Name[0], like "B" on "Babul", or 1 at "a", so the >0 should work?
Reply
#8

I also included printf's in the code I made which result in:
Код:
Firstname: Berky_Brada.
Firstname: 1. (result of strfind)
Which is weird because 'e' doesn't equal 'I'?! It's set to false also which means it only looks for the 'I' and nothing else.
Reply
#9

Found the solution - Closed. >.<
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)