SA-MP Forums Archive
strfind, strcmp - 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, strcmp (/showthread.php?tid=281344)



strfind, strcmp - Wesley221 - 05.09.2011

Which function should i use for checking names for forbidden words?

strfind(), strcmp()
I know how they both work, im just not sure if it matters if i use strfind or strcmp.
Maybe one of them is faster then the other?

~Wesley


Re: strfind, strcmp - JaTochNietDan - 05.09.2011

Well they are both completely different. strcmp is string compare, it is used for comparing two strings and seeing if they match. strfind is string find, it is used for finding a string within a string.

So which one do you think you need to use?


Re: strfind, strcmp - Wesley221 - 05.09.2011

Hm, duh.. Should be strfind then.. Haha
Thanks


Re: strfind, strcmp - =WoR=Varth - 05.09.2011

Quote:
Originally Posted by Wesley221
Посмотреть сообщение
Which function should i use for checking names for forbidden words?

strfind(), strcmp()
I know how they both work, im just not sure if it matters if i use strfind or strcmp.
Maybe one of them is faster then the other?

~Wesley
strcmp will check the whole name. But strfind will check part of name.
pawn Код:
if(!strcmp(name,"forbidden_name"))

if(strfind(name,"forbidden") != -1)
if(strfind(name,"name") != -1)



Re: strfind, strcmp - Wesley221 - 05.09.2011

Im getting kicked by using the name "Lemmy_Lusion[NL]" when im using this piece of code:
pawn Код:
for( new i = 0; i < MAX_FORBIDDEN_NAMES; i ++ )
    {
        if( strfind(ForbiddenNames[i], GetName(playerid), true ) )
        {
            SendClientMessage(playerid, COLOR_ORANGE, " ** We found a forbidden word in your name! Please remove it and re-connect. ");
            Kick(playerid);
            return 1;
        }
    }
I never used the strfind function before, is this the right way?
Note: There are no parts of my name in the forbiddennames variable


Re: strfind, strcmp - =WoR=Varth - 05.09.2011

pawn Код:
for( new i = 0; i < MAX_FORBIDDEN_NAMES; i ++ )
    {
        if( strfind(ForbiddenNames[i], GetName(playerid), true ) != -1)
        {
            SendClientMessage(playerid, COLOR_ORANGE, " ** We found a forbidden word in your name! Please remove it and re-connect. ");
            Kick(playerid);
            return 1;
        }
    }



Re: strfind, strcmp - Wesley221 - 05.09.2011

Im not getting kicked now, but now my register/login dialog wont show neither. Ive already tried to remove the 'return 1;', but still didnt show the dialog.
pawn Код:
public OnPlayerConnect(playerid)
{
    for( new i = 0; i < MAX_FORBIDDEN_NAMES; i ++ )
    {
        if( strfind( ForbiddenNames[i], GetName(playerid), true ) != -1 )
        {
            SendClientMessage(playerid, COLOR_ORANGE, " ** We found a forbidden word in your name! Please remove it and re-connect. ");
            Kick(playerid);
        }
    }
    if(!fexist(UserPath(playerid)))
    {
        Register
        return 1;
    }
    else if (fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        if( PlayerInfo[playerid][pBanned] == 1 ) return Kick(playerid), SendClientMessage(playerid, COLOR_RED, " ** You are banned and cannot log in! ");
        printf("|| TotalKills: %i || TotalDeaths: %i || TotalKD: %0.2f || Useown: %i ||", PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], Float:floatdiv(PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths]), WeaponInfo[playerid][pUseOwn]);
        Login
        return 1;
    }



Re: strfind, strcmp - =WoR=Varth - 05.09.2011

Quote:
Originally Posted by Wesley221
Посмотреть сообщение
Im not getting kicked now, but now my register/login dialog wont show neither. Ive already tried to remove the 'return 1;', but still didnt show the dialog.
pawn Код:
public OnPlayerConnect(playerid)
{
    for( new i = 0; i < MAX_FORBIDDEN_NAMES; i ++ )
    {
        if( strfind( ForbiddenNames[i], GetName(playerid), true ) != -1 )
        {
            SendClientMessage(playerid, COLOR_ORANGE, " ** We found a forbidden word in your name! Please remove it and re-connect. ");
            Kick(playerid);
        }
    }
    if(!fexist(UserPath(playerid)))
    {
        Register
        return 1;
    }
    else if (fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        if( PlayerInfo[playerid][pBanned] == 1 ) return Kick(playerid), SendClientMessage(playerid, COLOR_RED, " ** You are banned and cannot log in! ");
        printf("|| TotalKills: %i || TotalDeaths: %i || TotalKD: %0.2f || Useown: %i ||", PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], Float:floatdiv(PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths]), WeaponInfo[playerid][pUseOwn]);
        Login
        return 1;
    }
A don't see anywhere in your code that show dialog.


Re: strfind, strcmp - Wesley221 - 05.09.2011

Its the "Register Login". I defined the ShowPlayerDialog in them, so i dont have to have long lines everywhere.
Also i just debugged the script like this:
pawn Код:
for( new i = 0; i < MAX_FORBIDDEN_NAMES; i ++ )
    {
        printf("%s start loop", GetName(playerid));
        if( strfind( ForbiddenNames[i], GetName(playerid), true ) != -1 )
        {
            printf("%s forbidden name found", GetName(playerid));
            SendClientMessage(playerid, COLOR_ORANGE, " ** We found a forbidden word in your name! Please remove it and re-connect. ");
            printf("%s kicked", GetName(playerid));
            Kick(playerid);
        }
        printf("%s end loop", GetName(playerid));
    }
This is what it shows:
Код:
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop // 31 time, but doesnt end
Just the last one doesnt stop.


Re: strfind, strcmp - =WoR=Varth - 05.09.2011

Show us your ForbiddenNames variable.