SA-MP Forums Archive
strfind - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: strfind (/showthread.php?tid=79853)



strfind - rafay - 31.05.2009

What's up with this code ?

pawn Код:
if(strfind(text, "brb", true) == 1)
    {
    afk[playerid] = 1;
    SendClientMessage(playerid,0xCC0000AA,"You are now in BRB mode.");
    }
Basically, when a player says "brb" in his chat line, he should gp into brb mode. But here, it doesn't. Anyway to fix ?


Re: strfind - pspleo - 31.05.2009

You should put == 0 instead of == 1. It's the same as strcmp.

Leopard


Re: strfind - rafay - 31.05.2009

0 -> True
1 -> False
right ? I left scripting for a long time.


Re: strfind - rafay - 31.05.2009

Bump.!


Re: strfind - OmeRinG - 31.05.2009

Ye.... but instead doing == 0 do !strfind(asdlask)


Re: strfind - Donny_k - 31.05.2009

Rafay false is 0, true is anything which isn't false.

@all:

Read this.


Re: strfind - rafay - 31.05.2009

I solved the problem using strcmp. Thanks anyway.


Re: strfind - pulposlaw - 31.05.2009

I know, you've solved your problem, but there is another way:

Instead of
pawn Код:
if(strfind(text, "brb", true) == 1)
    {
    afk[playerid] = 1;
    SendClientMessage(playerid,0xCC0000AA,"You are now in BRB mode.");
    }
You should do
pawn Код:
if(strfind(text, "brb", true) != -1)
    {
    afk[playerid] = 1;
    SendClientMessage(playerid,0xCC0000AA,"You are now in BRB mode.");
    }
strfind returns -1 when it doesn't find the substring. Otherwise, it returns position of the substring in a string.