SA-MP Forums Archive
onplayertext problem - 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: onplayertext problem (/showthread.php?tid=86317)



onplayertext problem - Serediucr - 13.07.2009

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


Re: onplayertext problem - Djiango - 13.07.2009

"return 0;" just under your "SendClientMessageToAll"


Re: onplayertext problem - Serediucr - 13.07.2009

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


Re: onplayertext problem - Gergo1352 - 13.07.2009

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.


Re: onplayertext problem - MenaceX^ - 13.07.2009

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;
}



Re: onplayertext problem - Serediucr - 13.07.2009

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?


Re: onplayertext problem - Gergo1352 - 13.07.2009

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...


Re: onplayertext problem - Serediucr - 13.07.2009

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"


Re: onplayertext problem - Gergo1352 - 13.07.2009

What errors did you get?


Re: onplayertext problem - c0der. - 13.07.2009

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.