聊天窗口命令监听

我不当学长 管理员组 2022-4-21 1457

使用场景:

玩家输入文字,系统会根据文字信息,进行对应的函数回调

举例:

Sample [deathmatch.sp]:deathmatch 死斗模式插件

public void OnPluginStart()
{    
/* Listen For Client Commands */
    AddCommandListener(Event_Say, "say");
    AddCommandListener(Event_Say, "say_team");
}

public Action Event_Say(int client, const char[] command, int argc)
{
    static char menuTriggers[][] = { "gun", "!gun", "/gun", "guns", "!guns", "/guns", "menu", "!menu", "/menu", "weapon", "!weapon", "/weapon", "weapons", "!weapons", "/weapons" };
    static char hsOnlyTriggers[][] = { "hs", "!hs", "/hs", "headshot", "!headshot", "/headshot" };

    if (g_cvDM_enabled.BoolValue && IsValidClient(client) && (GetClientTeam(client) >= CS_TEAM_T))
    {
        /* Retrieve and clean up text. */
        char text[24];
        GetCmdArgString(text, sizeof(text));
        StripQuotes(text);
        TrimString(text);

        for (int i = 0; i < sizeof(menuTriggers); i++)
        {
            if (StrEqual(text, menuTriggers[i], false))
            {
                if (g_cvDM_gun_menu_mode.IntValue == 1 || g_cvDM_gun_menu_mode.IntValue == 2 || g_cvDM_gun_menu_mode.IntValue == 3)
                    DisplayOptionsMenu(client);
                else
                    CPrintToChat(client, "[\x04DM\x01] %t", "Guns Disabled");
                return Plugin_Handled;
            }
        }
        if (g_cvDM_headshot_only_allow_client.BoolValue)
        {
            for (int i = 0; i < sizeof(hsOnlyTriggers); i++)
            {
                if (StrEqual(text, hsOnlyTriggers[i], false))
                {
                    g_bHSOnlyClient[client] = !g_bHSOnlyClient[client];
                    char buffer[64];
                    char cEnable[32];
                    char cHSOnly[16];
                    cEnable = g_bHSOnlyClient[client] ? "Enabled" : "Disabled";
                    cHSOnly =  g_bHSOnlyClient[client] ? "1" : "0";
                    Format(buffer, sizeof(buffer), "HS Only Client %s", cEnable);
                    CPrintToChat(client, "[\x04DM\x01]  %t", buffer);
                    SetClientCookie(client, g_hHSOnly_Cookie, cHSOnly);
                    return Plugin_Handled;
                }
            }
        }
    }
    return Plugin_Continue;
}

CSGO插件分享-申明 1、本网站名称:CSGO插件分享-中文站  网址:https://bbs.csgocn.net
2、本站的宗旨在于为CSGO玩家提供一个插件分享的中文资源平台,多数插件来源于SourceMod论坛,并配以中文介绍和安装教程。
3、欢迎有能力的朋友共享有趣的CSGO插件资源。
4、本站资源大多为百度网盘,如发现链接失效,可以点: 这里进行反馈,我们会第一时间更新。
最新回复 (0)
返回