SA-MP Forums Archive
strfind + array - 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 + array (/showthread.php?tid=322199)



strfind + array - milanosie - 01.03.2012

Hey, quick question.

pawn Код:
new numfind = strfind(params, "{0,9}", true);
            if(numfind != -1)
This will check if any Number is found right?


Re: strfind + array - Twisted_Insane - 01.03.2012

Yep, from "0 - 9"!


Re: strfind + array - Vince - 01.03.2012

No, this just checks if "{0,9}" is in the string. I'm aware of that guy that advised you to use the regex plugin in your previous topic, but that doesn't mean any function will now accept regex values.


Re: strfind + array - milanosie - 01.03.2012

So how do I check if a number is found? Except from doing like 10 strfind ?


Re: strfind + array - iPLEOMAX - 01.03.2012

pawn Код:
stock IsNumberPresent(string[])
{
    for(new i=0; i<strlen(string); i++)
    if(string[i] >= '0' && string[i] <= '9') return true;
    return false;
}
Use:

pawn Код:
if(IsNumberPresent("Haha This is so cool!!1!!1")) printf("ipleo is a N00b");
Other

pawn Код:
if(IsNumberPresent(",.;-`~!!##%^)@*#&!#_&*<:{:{<><:}!!"))
printf("Something wrong with your computer");

if(IsNumberPresent(",.;-`~!!##%^)@*#&!#_&*<:{:{<><:}!! 1 "))
printf("Hah, alright.");
In your case:

pawn Код:
if(IsNumberPresent(params)) { /*code*/ }



Re: strfind + array - T0pAz - 01.03.2012

The way I did.
pawn Код:
stock bool:HasNum( str[] )
{
    for ( new i, l = strlen( string ); i != l; i++ )
        if ( str[i] >= '0' && str[i] <= '9' ) return(true);
    return(false);
}



Re: strfind + array - iPLEOMAX - 01.03.2012

@T0pAz More efficient, yeah. xD


Re: strfind + array - milanosie - 01.03.2012

So how to use it in here?

pawn Код:
CMD:o(playerid, params[])
{
    new SenderName[MAX_PLAYER_NAME],string[128];
    GetPlayerName(playerid,SenderName,sizeof(SenderName));
    if(isnull(params)) return SendClientMessage(playerid, COLOR_GREY,"Usage: /o [OOC CHAT]");
    if(oocon == 1)
    {
            new ipfind = strfind(params, ".", true);
            new portfind = strfind(params, ":", true);
           
            if(ipfind != -1 && portfind != -1 && HasNum(params) == true)
            {
                if(PlayerInfo[playerid][AdminLevel] < 3)
                {
                    new string43[128];
                    format(string43, sizeof(string43), "%s just got kicked for Advertising by **AntiCheat V2.0**", SenderName);
                    ProxDetector(10000000000.0, playerid, string43, 0xFF0000FF, 0xFF0000FF, 0xFF0000FF, 0xFF0000FF, 0xFF0000FF);
                    SendClientMessage(playerid, COLOR_RED, "Advertising is not allowed!");
                    Kick(playerid);
                }
            }

pawn Код:
stock bool:HasNum( str[] )
{
    for ( new i, l = strlen( string ); i != l; i++ )
        if ( str[i] >= '0' && str[i] <= '9' ) return(true);
    return(false);
}
Is that how to use it?


Re: strfind + array - Stylock - 01.03.2012

That's a very poor advertisement checker. You'll get kicked for typing "Time is 12:00." for example.


Re: strfind + array - milanosie - 01.03.2012

Quote:
Originally Posted by YJIET
Посмотреть сообщение
That's a very poor advertisement checker. You'll get kicked for typing "Time is 12:00." for example.
Well its an example. And your right, but I never work with strfind etc, so im experimenting a bit