Permission to write 3 numbers, rest of it censured.
#1

So if a player types in something like this:

Hi my name is Whizion, i write about 500-700 lines of code a day.

It would count how many numbers does that string have and it would censor it like this:

If the string has more than 3 numbers in it.

Hi my name is Whizion, i write about 500-*** lines of code a day.

How would i do that? Thank you.
Reply
#2

OnPlayerText:

pawn Код:
new numbers,
    pos;

while(text[pos])
{
    if('0' <= text[pos] <= '9')
    {
        if(numbers == 3)
            text[pos] = '*';
        else
            numbers++;
    }
    pos++;
}
Not tested, but should work.
Reply
#3

I guess you could do a loop to go through each character in the string and check if it's numeric, and if it is, censor it. For example:

pawn Код:
new string[] = "Hello world 127.0.0.1";
new count = 0;
for(new i = 0; i < sizeof(string); i++)
{
    if (((string[i] <= '9' && string[i] >= '0') || !(i==0 && (string[i]=='-' || string[i]=='+')))) // Taken from IsNumeric by DracoBlue
    {
        count++;
        if(count > 3) string[i] = '*';
    }
}
Edit: Someone beat me to it
Reply
#4

Thanks a lot, it works great.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)