使用场景:
玩家输入文字,系统会根据文字信息,进行对应的函数回调
举例:
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;
}