SA-MP Forums Archive
Strfind [Issue] [0.3c] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Strfind [Issue] [0.3c] (/showthread.php?tid=304252)



Strfind [Issue] [0.3c] - Berky - 17.12.2011

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];
}



Re: Strfind [Issue] [0.3c] - MP2 - 17.12.2011

!= -1 not 0


Re: Strfind [Issue] [0.3c] - Berky - 17.12.2011

!= -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'.


Re: Strfind [Issue] [0.3c] - Berky - 17.12.2011

What would you suggest me to do ******?


Re: Strfind [Issue] [0.3c] - cessil - 17.12.2011

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)


Re: Strfind [Issue] [0.3c] - Berky - 17.12.2011

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..


Re: Strfind [Issue] [0.3c] - Babul - 17.12.2011

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?


Re: Strfind [Issue] [0.3c] - Berky - 18.12.2011

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.


Re: Strfind [Issue] [0.3c] - Berky - 19.12.2011

Found the solution - Closed. >.<