SA-MP Forums Archive
Using strfind wrong? - 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: Using strfind wrong? (/showthread.php?tid=342266)



Using strfind wrong? - JaKe Elite - 13.05.2012

I don't know why but it also allows other players to use the clan chat here is example how i use strfind

pawn Код:
if(strfind(GetpName(playerid), "[iP]", true))
but still other players (even without [iP] tag) can use the clan chat.

Note: this was proof 100% when i use another user name like 'Rock' etc...

so tell me guys i'm using strfind wrong?


Re: Using strfind wrong? - Libra_PL - 13.05.2012

I am not sure (I also don't know strfind very well). If you change 'true' to 'false', will it be fixed (because a long time ago I used 'false', not 'true')?


Re: Using strfind wrong? - JaKe Elite - 13.05.2012

nope it didn't work


Re: Using strfind wrong? - Libra_PL - 13.05.2012

I found it in my script, try this one:

Код:
if(strfind(GetpName(playerid),"[iP]", true) != -1)



AW: Using strfind wrong? - Nero_3D - 13.05.2012

Guys, first use the wiki than pawn-lang.pdf (or the impl guide if needed) than the search function and AT LAST post a topic...

Quote:
Returns
The number of characters before the sub string (the sub string's start position) or -1 if it's not found.
After knowing that, Libra_PL version is correct


Re: Using strfind wrong? - iRage - 13.05.2012

Quote:
Originally Posted by Wiki
Returns The number of characters before the sub string (the sub string's start position) or -1 if it's not found.
Use this:
pawn Код:
if(strfind(GetpName(playerid), "[iP]", false) != -1)
Basically what made it not work is it returned 0 as there are no characters before the [iP] when you made it check a name.
It should be set to false so it someone has the tag [ip] or [Ip] he won't be able to talk on the clan chat neither.

To even make this more accurate use the following:
pawn Код:
if(!strfind(GetpName(playerid), "[iP]", false))
This will make it ONLY work if the player has [iP] before his name, example: "[iP]iRage".
It won't work if a player has [iP] anywhere else in his name, example: "iRa[iP]ge" or "iRage[iP]".


AW: Re: Using strfind wrong? - Nero_3D - 13.05.2012

Quote:
Originally Posted by iRage
Посмотреть сообщение
Use this:
pawn Код:
if(strfind(GetpName(playerid), "[iP]", false) != -1)
Basically what made it not work is it returned 0 as there are no characters before the [iP] when you made it check a name.
It should be set to false so it someone has the tag [ip] or [Ip] he won't be able to talk on the clan chat neither.

To even make this more accurate use the following:
pawn Код:
if(!strfind(GetpName(playerid), "[iP]", false))
This will make it ONLY work if the player has [iP] before his name, example: "[iP]iRage".
It won't work if a player has [iP] anywhere else in his name, example: "iRa[iP]ge" or "iRage[iP]".
In this case use strcmp because its faster

pawn Код:
if(!strcmp(GetpName(playerid), "[iP]", false, 4)) {}



Re: AW: Re: Using strfind wrong? - iRage - 13.05.2012

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
In this case use strcmp because its faster

pawn Код:
if(!strcmp(GetpName(playerid), "[iP]", false, 4)) {}
That would work too.
Anyways have you tested both and came up with your speed results or...?


Re: Using strfind wrong? - JaKe Elite - 14.05.2012

Thanks everyone it is working now thx to you iRage rep+ for you