strfind + array
#1

Hey, quick question.

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

Yep, from "0 - 9"!
Reply
#3

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.
Reply
#4

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

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*/ }
Reply
#6

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);
}
Reply
#7

@T0pAz More efficient, yeah. xD
Reply
#8

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?
Reply
#9

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)