PrivateMessage v1.0 by CrAsH

Shadowless

Пользователь
Регистрация
24 Фев 2019
Сообщения
237
Симпатии
4
Пол
Мужской
solved
 
Последнее редактирование:

Shadowless

Пользователь
Регистрация
24 Фев 2019
Сообщения
237
Симпатии
4
Пол
Мужской
bump
 

present

Пользователь
Регистрация
27 Сен 2017
Сообщения
87
Симпатии
-73
try this
Код:
#include <amxmodx>

#pragma semicolon 1

#define PLUGIN_NAME "Private Message"
#define PLUGIN_VERSION "0.8"
#define PLUGIN_AUTHOR "Denzer"

// EN: Prefix in chat
// RU: Префикс в чат
new const PREFIX[] = "[^4PM^1]";

// EN: List of commands to cancel
// RU: Список команд для отмены
new const BLOCK_CMD[] =
{
    "cancel",
    "otmena",
    "отмена"
};

new const g_szLogFile[] = "private_message";

new g_iType;
new bool: g_bBlock;
new Float: g_fDelay;
new g_sAccess[24];
new bool: g_bLogging;
new g_iPlayer[MAX_PLAYERS + 1];
new bool: g_bChatBlocked;
new bool: g_bHookSay[MAX_PLAYERS + 1];
new bool: g_bType[MAX_PLAYERS + 1];
new bool: g_bPlayerBlocked[MAX_PLAYERS + 1][MAX_PLAYERS + 1];
new Float: g_fChattingDelay[MAX_PLAYERS + 1];
new Array: g_aIndex[MAX_PLAYERS + 1];

public plugin_init()
{
    register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);

    new pCvar;
    pCvar = create_cvar("pm_type", "1", FCVAR_NONE, "All can write messages each other, 2 - messages can write only: alive to alive, deat for dead, 3 - only to teammates", true, 1.0, true, 3.0);
    bind_pcvar_num(pCvar, g_iType);

    pCvar = create_cvar("pm_delay", "2.5", FCVAR_NONE, "Time between messages", true, 0.0, true, 10.0);
    bind_pcvar_float(pCvar, g_fDelay);

    pCvar = create_cvar("pm_access", "m", FCVAR_NONE, "Access flag to function of chat blocking");
    bind_pcvar_string(pCvar, g_sAccess, charsmax(g_sAccess));

    AutoExecConfig(true, "private_message");

    pCvar = create_cvar("pm_block", "1", FCVAR_NONE, "Allows admin to block PM-system", true, 0.0, true, 1.0);
    g_bBlock = bool:get_pcvar_num(pCvar);

    pCvar = create_cvar("pm_logging", "1", FCVAR_NONE, "Message logging", true, 0.0, true, 1.0);
    g_bLogging = bool:get_pcvar_num(pCvar);

    register_clcmd("pm", "CmdSay");
    register_clcmd("say /pm", "CmdMain");

    for(new i = 0; i < sizeof(BLOCK_CMD); i++)
        register_saycmd(BLOCK_CMD[i], "CmdHookSay");

    register_clcmd("say", "CmdSayChat");
    register_clcmd("say_team", "CmdSayChat");

    if(g_bBlock)
    {
        register_clcmd("say /pmblock", "CmdChatBlocked");
        register_clcmd("pmblock", "CmdChatBlocked");\
    }

    register_dictionary("private_message.txt");
}

public client_putinserver(id)
{
    g_bHookSay[id] = false;
    g_bType[id] = false;
    g_aIndex[id] = ArrayCreate();
}

public client_disconnected(id)
{
    ArrayDestroy(g_aIndex[id]);
    g_aIndex[id] = Invalid_Array;
    for(new i = 0 ; i < MAX_PLAYERS; i++)
    {
        if(!g_aIndex[i])
            continue;

        new found = ArrayFindValue(g_aIndex[i], id);
        if(found != -1)
        {
            ArrayDeleteItem(g_aIndex[i], found);
        }
    }
}

public CmdSay(id)
{
    new iPlayer = g_iPlayer[id];
    if(!is_user_connected(iPlayer))
       return PLUGIN_HANDLED;

    new sMsg[140];
    read_args(sMsg, charsmax(sMsg));
    remove_quotes(sMsg);
    replace_wrong_simbols(sMsg);

    client_print_color(id, print_team_default, "%L", LANG_SERVER, "PM_MESSAGE_TO", iPlayer, sMsg);
    client_print_color(iPlayer, print_team_default, "%L", LANG_SERVER, "PM_MESSAGE_FROM", id, sMsg);

    if(g_bLogging)
        log_to_file(g_szLogFile, "%L", LANG_SERVER, "PM_WROTE_PLAYER", id, iPlayer, sMsg);

    g_fChattingDelay[id] = get_gametime() + g_fDelay;
    return PLUGIN_HANDLED;
}

public CmdHookSay(id)
{
    if(!g_bHookSay[id])
        return PLUGIN_HANDLED;
    
    g_bHookSay[id] = false;
    client_print_color(id, print_team_default, "%s %L", PREFIX, LANG_SERVER, "PM_CANCEL");
    return PLUGIN_HANDLED;
}

public CmdSayChat(id)
{   
    new sMsg[140];
    new iPlayer = g_iPlayer[id];
    read_args(sMsg, charsmax(sMsg));
    remove_quotes(sMsg);
    replace_wrong_simbols(sMsg);

    if(!is_user_connected(iPlayer))
        return PLUGIN_CONTINUE;

    if(g_bType[id] && g_bHookSay[id])
    {
        g_bHookSay[id] = false;
        g_fChattingDelay[id] = get_gametime() + g_fDelay;
        client_print_color(id, print_team_default, "%L", LANG_SERVER, "PM_MESSAGE_TO", iPlayer, sMsg);
        client_print_color(iPlayer, print_team_default, "%L", LANG_SERVER, "PM_MESSAGE_FROM", id, sMsg);

        if(g_bLogging)
            log_to_file(g_szLogFile, "%L", LANG_SERVER, "PM_WROTE_PLAYER", id, iPlayer, sMsg);
        
        return PLUGIN_HANDLED;
    }
    
    return PLUGIN_CONTINUE;
}

public CmdChatBlocked(id)
{       
    if(~get_user_flags(id) & read_flags(g_sAccess))
        return PLUGIN_HANDLED;

    g_bChatBlocked = !g_bChatBlocked;
    client_print_color(0, print_team_default, "%s %L", PREFIX, LANG_SERVER, "PM_BLOCKED_ADMIN", id, LANG_SERVER, g_bChatBlocked ? "PM_BLOCKED_FOR" : "PM_BLOCKED_COUNT");
    return PLUGIN_CONTINUE;
}

public CmdMain(id)
{
    new szBuff[64], lang[64], chat[64], messagemode[64], recipient[64], recipient_none[64];
    formatex(lang, charsmax(lang), "%L", LANG_SERVER, "PM_TITLE_MESSAGES");
    new menu = menu_create(lang, "MainHandler");

    formatex(lang, charsmax(lang), "%L", LANG_SERVER, "PM_WRITE");
    menu_additem(menu, lang);

    formatex(lang, charsmax(lang), "%L", LANG_SERVER, "PM_BLOCK");
    menu_additem(menu, lang);

    formatex(chat, charsmax(chat), "%L", LANG_SERVER, "PM_CHAT");
    formatex(messagemode, charsmax(messagemode), "%L", LANG_SERVER, "PM_MESSAGEMODE");
    menu_additem(menu, g_bType[id] ? chat : messagemode);

    formatex(recipient, charsmax(recipient), "%L", LANG_SERVER, "PM_RECIPIENT");
    formatex(recipient_none, charsmax(recipient_none), "%L", LANG_SERVER, "PM_RECIPIENT_NONE");
    menu_addtext2(menu, ArraySize(g_aIndex[id]) ? recipient : recipient_none);

    if(ArraySize(g_aIndex[id]))
    {
        new save_index[MAX_PLAYERS + 1][MAX_PLAYERS + 1];
        new szPlayer[10];
        for(new i = 0; i < ArraySize(g_aIndex[id]); i++)
        {
            new get = ArrayGetCell(g_aIndex[id], i);
            /*server_print(">>> ArrayGetCell(g_aIndex[id], i): %d", get);
            server_print(">>> save_index[id][get]: %d", save_index[id][get]);*/
            if(save_index[id][get] == get || !is_user_connected(get))
                continue;
            
            formatex(szBuff, charsmax(szBuff), "%n", get);
            num_to_str(get, szPlayer, charsmax(szPlayer));
            menu_additem(menu, szBuff, szPlayer);
            save_index[id][get] = get;
        }
    }

    formatex(lang, charsmax(lang), "%L", LANG_SERVER, "PM_NEXT");
    menu_setprop(menu, MPROP_NEXTNAME, lang);
    formatex(lang, charsmax(lang), "%L", LANG_SERVER, "PM_BACK");
    menu_setprop(menu, MPROP_BACKNAME, lang);
    formatex(lang, charsmax(lang), "%L", LANG_SERVER, "PM_EXIT");
    menu_setprop(menu, MPROP_EXITNAME, lang);
    menu_display(id, menu, 0);
 
    return PLUGIN_HANDLED;
}

public MainHandler(id, menu, item)
{
    if(item == MENU_EXIT)
    {
        menu_destroy(menu);
        return PLUGIN_HANDLED;
    }
    
    if(g_bChatBlocked)
    {
        client_print_color(id, print_team_default, "%s %L", PREFIX, LANG_SERVER, "PM_BLOCKED");
        return PLUGIN_HANDLED;
    }
    
    new s_Data[6], s_Name[64], i_Access, i_Callback;
    menu_item_getinfo(menu, item, i_Access, s_Data, charsmax(s_Data), s_Name, charsmax(s_Name), i_Callback);
    new tempid = str_to_num(s_Data);
    new iPlayer = g_iPlayer[id] = tempid;

    switch(item)
    {
        case 0:
            CmdPM(id);
        case 1:
            CmdBlock(id);
        case 2:
        {
            g_bType[id] = !g_bType[id];
            CmdMain(id);
        }
        default:
        {
            /*server_print(">>> g_fChattingDelay[id]: %1.f", g_fChattingDelay[id]);
            server_print(">>> get_gametime(): %1.f", get_gametime());
            server_print(">>> %d", g_fChattingDelay[id] > get_gametime() ? 1 : 0);*/

            if(!ArraySize(g_aIndex[id]))
                return PLUGIN_HANDLED;

            if(g_fChattingDelay[id] > get_gametime())
            {
                client_print_color(id, print_team_default, "%s %L", PREFIX, LANG_SERVER, "PM_FLOOD");
                return PLUGIN_HANDLED;
            }

            if(g_bPlayerBlocked[iPlayer][id])
            {
                client_print_color(id, print_team_default, "%s %L", PREFIX, LANG_SERVER, "PM_PLAYER_BLOCKED", iPlayer);
                return PLUGIN_HANDLED;
            }

            if(g_bType[id])
            {
                g_bHookSay[id] = true;
                client_print_color(id, print_team_default, "%s %L", PREFIX, LANG_SERVER, "PM_OPEN_CHAT");
            }
            else
            {
                g_bHookSay[id] = false;
                client_cmd(id, "messagemode pm");
            }

            //server_print(">>> otpravlyaem: %n, %d", iPlayer, iPlayer);
        }
    }
    menu_destroy(menu);
    return PLUGIN_HANDLED;
}

public CmdPM(id)
{
    new lang[64], iPlayers[MAX_PLAYERS], iNum, szPlayer[10], iPlayer, szName[MAX_NAME_LENGTH];
    formatex(lang, charsmax(lang), "%L", LANG_SERVER, "PM_TITLE_WRITE");
    new menu = menu_create(lang, "PMHandler");

    get_players(iPlayers, iNum, "ch");
    for (new i; i < iNum; i++)
    {
        iPlayer = iPlayers[i];

        if(id == iPlayer)
            continue;

        get_user_name(iPlayer, szName, charsmax(szName));
        num_to_str(iPlayer, szPlayer, charsmax(szPlayer));

        switch(g_iType)
        {
            case 1: menu_additem(menu, szName, szPlayer);
            case 2:
            {
                if(is_user_alive(id) == is_user_alive(iPlayer))
                    menu_additem(menu, szName, szPlayer);
            }
            case 3:
            {
                if(get_user_team(id) == get_user_team(iPlayer))
                    menu_additem(menu, szName, szPlayer);
            }
        }
    }

    formatex(lang, charsmax(lang), "%L", LANG_SERVER, "PM_NEXT");
    menu_setprop(menu, MPROP_NEXTNAME, lang);
    formatex(lang, charsmax(lang), "%L", LANG_SERVER, "PM_BACK");
    menu_setprop(menu, MPROP_BACKNAME, lang);
    formatex(lang, charsmax(lang), "%L", LANG_SERVER, "PM_EXIT");
    menu_setprop(menu, MPROP_EXITNAME, lang);
    menu_display(id, menu, 0);

    return PLUGIN_CONTINUE;
}

public PMHandler(id, menu, item)
{
    if(item == MENU_EXIT)
    {
        menu_destroy(menu);
        return PLUGIN_HANDLED;
    }

    new s_Data[6], s_Name[64], i_Access, i_Callback;
    menu_item_getinfo(menu, item, i_Access, s_Data, charsmax(s_Data), s_Name, charsmax(s_Name), i_Callback);

    new tempid = str_to_num(s_Data);
    new iPlayer = g_iPlayer[id] = tempid;

    if(g_fChattingDelay[id] > get_gametime())
    {
        client_print_color(id, print_team_default, "%s %L", PREFIX, LANG_SERVER, "PM_FLOOD");
        return PLUGIN_HANDLED;
    }

    if(g_bPlayerBlocked[iPlayer][id])
    {
        client_print_color(id, print_team_default, "%s %L", PREFIX, LANG_SERVER, "PM_PLAYER_BLOCKED", iPlayer);
        return PLUGIN_HANDLED;
    }
    
    if(g_bType[id])
    {
        client_print_color(id, print_team_default, "%s %L", PREFIX, LANG_SERVER, "PM_OPEN_CHAT");
        g_bHookSay[id] = true;
    }
    else
        client_cmd(id, "messagemode pm");

    ArrayPushCell(g_aIndex[id], iPlayer);
    
    if(ArraySize(g_aIndex[id]) > 3)
    {
        ArrayDeleteItem(g_aIndex[id], 0);
    }

    menu_destroy(menu);
    return PLUGIN_HANDLED;
}

public CmdBlock(id)
{
    new lang[64], iPlayers[MAX_PLAYERS], iNum, szPlayer[10], iPlayer, szBuff[64], szName[MAX_NAME_LENGTH];
    formatex(lang, charsmax(lang), "%L", LANG_SERVER, "PM_TITLE_BLOCK");
    new menu = menu_create(lang, "BlockHandler");

    get_players(iPlayers, iNum, "ch");
    for(new i; i < iNum; i++)
    {
        iPlayer = iPlayers[i];

        if(id == iPlayer)
            continue;

        get_user_name(iPlayer, szName, charsmax(szName));
        formatex(szBuff, charsmax(szBuff), "%s %L", szName, LANG_SERVER, "PM_MENU_BLOCKED");
        num_to_str(iPlayer, szPlayer, charsmax(szPlayer));

        if(g_bPlayerBlocked[id][iPlayer])
            menu_additem(menu, szBuff, szPlayer);
        else
            menu_additem(menu, szName, szPlayer);
    }

    formatex(lang, charsmax(lang), "%L", LANG_SERVER, "PM_NEXT");
    menu_setprop(menu, MPROP_NEXTNAME, lang);
    formatex(lang, charsmax(lang), "%L", LANG_SERVER, "PM_BACK");
    menu_setprop(menu, MPROP_BACKNAME, lang);
    formatex(lang, charsmax(lang), "%L", LANG_SERVER, "PM_EXIT");
    menu_setprop(menu, MPROP_EXITNAME, lang);
    menu_display(id, menu, 0);

    return PLUGIN_CONTINUE;
}

public BlockHandler(id, menu, item)
{
    if(item == MENU_EXIT)
    {
        menu_destroy(menu);
        return PLUGIN_HANDLED;
    }

    new s_Data[6], s_Name[64], i_Access, i_Callback;
    menu_item_getinfo(menu, item, i_Access, s_Data, charsmax(s_Data), s_Name, charsmax(s_Name), i_Callback);

    new tempid = str_to_num(s_Data);
    new iPlayer = g_iPlayer[id] = tempid;

    g_bPlayerBlocked[id][iPlayer] = !g_bPlayerBlocked[id][iPlayer];
    CmdBlock(id);

    menu_destroy(menu);
    return PLUGIN_HANDLED;
}

// mx?!
stock register_saycmd(const szSayCmd[], szFunc[])
{
    new const szPrefix[][] = { "say /", "say_team /", "say .", "say_team ." };
    for(new i; i < sizeof(szPrefix); i++)
        register_clcmd(fmt("%s%s", szPrefix[i], szSayCmd), szFunc);
}

stock replace_wrong_simbols(string[])
{
    new len = 0;
    for(new i; string[i] != EOS; i++)
    {
        if(string[i] == '%' || string[i] == '#' || 0x01 <= string[i] <= 0x04)
            continue;
        string[len++] = string[i];
    }
    string[len] = EOS;
}
 

Вложения

Сверху Снизу