if (strfind(text, "idiot") != -1)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
SetTimer("Botanswer3",500,false);
//SendChat(string);
}
if (strfind(text, "idiot") != -1)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
SetTimer("Botanswer3",500,false);
//SendChat(string);
return 0;
}
|
pawn Code:
|
public OnPlayerText(playerid, text[])
{
if(strfind(text, "idiot") != -1)
{
new Position = strfind(text, "idiot", true);
strdel(text, Position, Position+5);
strins(text, "censored", Position, 10);
SendPlayerMessageToAll(playerid, text);
return 0;
}
}
return 1;
|
Try:
pawn Code:
|
new
badwords[4][16] =
{
{ "idiot\0" },
{ "stupid\0" },
{ "asshole\0" },
{ "fuck\0" }
};
public OnPlayerText(playerid, text[])
{
new
i,
j,
sub;
for(; i < 4; ++i)
if((sub = strfind(text, badwords[i], true)) != -1)
for(; sub < strlen(text), j < strlen(badwords[i]); ++sub, ++j)
if(text[sub] == badwords[i][j])
{
strdel(text, sub, sub + 1);
strins(text, "*", sub);
}
return 1;
}
|
Not entirely sure how OnPlayerText works regarding the sending of the messages and whatnot, but here's a quick filtering method I just whipped up:
Code:
new
badwords[4][16] =
{
{ "idiot\0" },
{ "stupid\0" },
{ "asshole\0" },
{ "fuck\0" }
};
public OnPlayerText(playerid, text[])
{
new
i,
j,
sub;
for(; i < 4; ++i)
if((sub = strfind(text, badwords[i], true)) != -1)
for(; sub < strlen(text), j < strlen(badwords[i]); ++sub, ++j)
if(text[sub] == badwords[i][j])
{
strdel(text, sub, sub + 1);
strins(text, "*", sub);
}
return 1;
}
|
|
This sounds good but how can i add more than 4 words, cause i get initialisation data exceeds declared size
|
#define MAX_BADWORDS 4
new
badwords[MAX_BADWORDS][16] =
{
{ "idiot\0" },
{ "stupid\0" },
{ "asshole\0" },
{ "fuck\0" }
};
public OnPlayerText(playerid, text[])
{
new
i,
j,
sub;
for(; i < MAX_BADWORDS; ++i)
if((sub = strfind(text, badwords[i], true)) != -1)
for(j = 0; sub < strlen(text), j < strlen(badwords[i]); ++sub, ++j)
if( text[sub] == badwords[i][j] ||
text[sub] == (badwords[i][j] - 32))
{
strdel(text, sub, sub + 1);
strins(text, "*", sub, strlen(text));
}
return 1;
}
|
The filtering of strings works fine, I just haven't tested it with OnPlayerText.
Try this: Code:
#define MAX_BADWORDS 4
new
badwords[MAX_BADWORDS][16] =
{
{ "idiot\0" },
{ "stupid\0" },
{ "asshole\0" },
{ "fuck\0" }
};
public OnPlayerText(playerid, text[])
{
new
i,
j,
sub;
for(; i < MAX_BADWORDS; ++i)
if((sub = strfind(text, badwords[i], true)) != -1)
for(j = 0; sub < strlen(text), j < strlen(badwords[i]); ++sub, ++j)
if( text[sub] == badwords[i][j] ||
text[sub] == (badwords[i][j] - 32))
{
strdel(text, sub, sub + 1);
strins(text, "*", sub, strlen(text));
}
return 1;
}
|