OnPlayerText
#3

Quote:
Originally Posted by CH | FuDo
Посмотреть сообщение
I want to make, when player in OnPlayerText type text which contains forbbiden word or some IP adress to send message only to admins, but not to show the text. How can I do it? Thank you.
pawn Код:
//A function called "DetectAdv" which will detect if an IP is found on the str.

stock DetectAdv(stradv[])
{
    new temp_Count;
    for(new i; stradv[i] != 0; ++i) {
        if(('0' <= stradv[i] <= '9') || stradv[i] == '.' || stradv[i] == ':') {
            if((stradv[i] == '.') && (stradv[i + 1] != '.') && ('0' <= stradv[i - 1] <= '9')) {
                ++temp_Count;
            }
            continue;
        }
    }
    return (temp_Count > 2);
}

//An array called "badwords" which contains a list of badwords.


new badwords[][] =
{
    {"fuck"},
    {"bitch"},
    {"asshole"}}; //You can add more, the last word doesn't need to have a , .

public OnPlayerText(playerid, text[])
{
    new
        bool:Found = false;
    for(new i; i< sizeof(badwords); i++) //Looping around the array which contains badwords.
    {
        //If the chat contains any words specified on the array, it will detect.
        if(strfind(text, badwords[i], true) != -1) Found = true;
    }
    if(DetectAdv(text)) Found = true; //Or if an IP is pasted, it will detect.
    if(Found == true) //If detected!
    {
        new
            string[128],
            Lname[MAX_PLAYER_NAME];
        //Getting the player's name to show it to admins.
        GetPlayerName(playerid, Lname, sizeof(Lname));
        //Formatting the text to show it to admin with player's name and ID!
        format(string, sizeof(string), "%s(ID:%d) : %s", Lname, playerid, text);
        for(new i; i< GetMaxPlayers(); i++) //Looping through all players.
        {
            if(!IsPlayerConnected(i)) continue; //If not connected, it will skip.
            if(!IsPlayerAdmin(i)) continue; //The same goes here too.
            SendClientMessage(i, -1, string); //Sends to online RCON admins.
        }
        return !SendClientMessage(playerid, 0xFF0000FF, "Warning! You're not allowed to use forbidden chat!");
    }
    return 1;
}
Haven't tested on game, but it seems to be working.
Reply


Messages In This Thread
OnPlayerText - by CH | FuDo - 03.02.2014, 14:13
AW: OnPlayerText - by ReD_HunTeR - 03.02.2014, 16:35
Re: OnPlayerText - by Lordzy - 03.02.2014, 17:08
Re: OnPlayerText - by CH | FuDo - 11.02.2014, 18:31
Re: OnPlayerText - by Blademaster680 - 11.02.2014, 19:55

Forum Jump:


Users browsing this thread: 1 Guest(s)