Permission to write 3 numbers, rest of it censured. - 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: Permission to write 3 numbers, rest of it censured. (
/showthread.php?tid=189357)
Permission to write 3 numbers, rest of it censured. -
Whizion - 11.11.2010
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.
Re: Permission to write 3 numbers, rest of it censured. -
rs.pect - 11.11.2010
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.
Re: Permission to write 3 numbers, rest of it censured. -
JaTochNietDan - 11.11.2010
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
Re: Permission to write 3 numbers, rest of it censured. -
Whizion - 11.11.2010
Thanks a lot, it works great.