Max 8 numbers in one chat. -
Necip - 14.03.2014
Hey all. So I have a function which detects if the player is trying to advertise a server, but I want to make it to max 8 numbers only and remove the dots and colons, like only 7 numbers allowed in chat. Here is the function:
pawn Код:
stock IsAnIP(const str[])
{
new i;
new colon;
new dots;
new numbers;
new len = strlen(str);
while (i < len)
{
if (str[i] == ':') colon++;
else if (str[i] == '.') dots++;
else if (str[i] >= '0' || str[i] <= '9') numbers++;
i++;
}
if (colon > 0 && dots > 2 && numbers > 4) return 1;
return 0;
}
Thanks for helping.
Re : Max 8 numbers in one chat. -
Golimad - 14.03.2014
Find a way to use this :
pawn Код:
for( new i = 0; i < len; i++)
{
if(str[i] == '0' || str[i] == '1' || str[i] == '2' || str[i] == '3' ... to 9 )
{
if( count >= 7 )
{
strdel(str, i,i);
strins(str, "x", i);
}
count++;
}
}
I think this may work, I hope it works, good luck
Re: Max 8 numbers in one chat. -
Necip - 14.03.2014
Any other ideas?
Re : Max 8 numbers in one chat. -
Golimad - 14.03.2014
Did it work or not ?b
Re: Max 8 numbers in one chat. -
Necip - 15.03.2014
Bump. I made something, but the problem is, when it detects 8 characters, any of them, it says advertising. Here is the script. Can someone make it with numbers only?
pawn Код:
stock IsAnIP(const str[])
{
new i;
new numbers;
new len = strlen(str);
while (i < len)
{
if (str[i] >= '0' || str[i] <= '9') numbers++;
i++;
}
if (numbers > 7) return 1;
return 0;
}
Re : Max 8 numbers in one chat. -
Golimad - 15.03.2014
Dude, did what I gave work or not
AW: Max 8 numbers in one chat. -
CutX - 15.03.2014
Quote:
Originally Posted by Necip
Bump. I made something, but the problem is, when it detects 8 characters, any of them, it says advertising. Here is the script. Can someone make it with numbers only?
pawn Код:
stock IsAnIP(const str[]) { new i; new numbers; new len = strlen(str); while (i < len) { if (str[i] >= '0' || str[i] <= '9') numbers++; i++; } if (numbers > 7) return 1; return 0; }
|
there's just one small mistake you've made

instead of using OR, you have to use AND
cuz that control structure should only result in true when the char is within the range you defined by '0' and '9'
c++ example checking for uppercase chars and replacing them with lower case ones:
Код:
void strKlein(char *c)
{
for (short i = 0; c[i] != '\0'; i++)
c[i] = (c[i] > 64 && c[i] < 91) ? (c[i]+32) : (c[i]);
}
replace this line
Код:
if (str[i] >= '0' || str[i] <= '9') numbers++;
with this
Код:
if (str[i] >= '0' && str[i] <= '9') numbers++;
and it'll be fine
Re: Max 8 numbers in one chat. - Emmet_ - 15.03.2014
That looks just like my old "IsAnIP" function that I made about ~3 years ago

.
Try this, using sscanf:
pawn Код:
stock IsAnIP(ip[])
{
static
num[4];
if (sscanf(ip, "p<.>dddd", num[0], num[1], num[2], num[3]))
{
return 0;
}
return 1;
}
Re: Max 8 numbers in one chat. -
Djole1337 - 15.03.2014
Use regex.
Re: Max 8 numbers in one chat. -
RajatPawar - 15.03.2014
Quote:
Originally Posted by Djole1337
Use regex.
|
Actually - I exactly did that, and almost replied - but I tried compiling the code, and it returned "invalid character constant."
I tried other regex methods however they were not
as accurate.
Could you mind posting one that
compiles?