onplayertext problem
#1

pawn Код:
public OnPlayerText(playerid, text[])
{
    if((strfind(text,"fuck",true,0))== 0){
    new name[24];
    new string[128];
    GetPlayerName(playerid,name,24);
    format(string, 256, "%s Is A Fool",name);
    SendClientMessageToAll(COLOR_GREEN,string);
    }
   
    return 1;
}
it works good , but it sends his message too , i don't want that
Reply
#2

"return 0;" just under your "SendClientMessageToAll"
Reply
#3

ok , this works , but if i say "fuck this server" doesn't works
Reply
#4

Quote:
Originally Posted by Serediucr
ok , this works , but if i say "fuck this server" doesn't works
pawn Код:
public OnPlayerText(playerid, text[])
{
    if((strfind(text,"fuck",true))== 0){
    new name[24];
    new string[128];
    GetPlayerName(playerid,name,24);
    format(string, 256, "%s Is A Fool",name);
    SendClientMessageToAll(COLOR_GREEN,string);
    }
   
    return 1;
}
Try out this.
Reply
#5

pawn Код:
public OnPlayerText(playerid,text[])
{
  if(strfind(text,"fuck",true)!=-1)
  {
    new name[MAX_PLAYER_NAME],
       string[128];
    GetPlayerName(playerid,name,MAX_PLAYER_NAME);
    format(string,sizeof(string),"%s Is A Fool.",name);
    SendClientMessageToAll(COLOR_GREEN,string);
    return 0;
  }
  // if you want the chat to be avaiable (the regular one of sa-mp) return it with 1.
  return 0;
}
Reply
#6

Quote:
Originally Posted by MenaceX^
pawn Код:
public OnPlayerText(playerid,text[])
{
  if(strfind(text,"fuck",true)!=-1)
  {
    new name[MAX_PLAYER_NAME],
       string[128];
    GetPlayerName(playerid,name,MAX_PLAYER_NAME);
    format(string,sizeof(string),"%s Is A Fool.",name);
    SendClientMessageToAll(COLOR_GREEN,string);
    return 0;
  }
  // if you want the chat to be avaiable (the regular one of sa-mp) return it with 1.
  return 0;
}
ok , it worked , but if i want to add another word?
Reply
#7

pawn Код:
new BadWords[][] =
{
    "Fuck",
    "Shit",
    "Dick",
    "Asshole"
};
pawn Код:
for(new a; a<sizeof(BadWords); a++)
{
    if(strfind(text, BadWords[a], true) != -1)
    {
        new name[MAX_PLAYER_NAME];
        string[128];
        GetPlayerName(playerid,name,MAX_PLAYER_NAME);
        format(string,sizeof(string),"%s Is A Fool.",name);
        SendClientMessageToAll(COLOR_GREEN,string);
        return 0;
     }
}

Something like that...
Reply
#8

look , your script gives me errors , but i modified to not give errors like this:
pawn Код:
public OnPlayerText(playerid,text[])
{
new string[128];
new BadWords[]=
{
    "Fuck",
    "Shit",
    "Dick",
    "Asshole"
};

if(strfind(text, BadWords, true) != -1)
    {
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid,name,MAX_PLAYER_NAME);
        format(string,sizeof(string),"%s Is A Fool.",name);
        SendClientMessageToAll(COLOR_GREEN,string);
        return 0;
     }
return 1;
}
but it works only with "fuck"
Reply
#9

What errors did you get?
Reply
#10

BadWords has 4 words in it. Your last code checks only one of that. You have to loop through the array as Gergo showed. Also I don't recommend you to constantly recreate the name string. Just create it once and use it everywhere.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)