2009-04-29 01:58:41 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2008-10-04 22:59:11 +02:00
|
|
|
* Zombie:Reloaded
|
2009-04-29 01:58:41 +02:00
|
|
|
*
|
2009-05-06 02:28:09 +02:00
|
|
|
* File: sayhooks.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: Hook plugin say commands and redirect to their handling module.
|
2009-04-29 01:58:41 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Max number of characters in a chat text string.
|
|
|
|
*/
|
|
|
|
#define SAYHOOKS_MAX_CHAT_LENGTH 192
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @section Say command key words.
|
|
|
|
*/
|
|
|
|
#define SAYHOOKS_KEYWORD_ZMENU "!zmenu"
|
|
|
|
#define SAYHOOKS_KEYWORD_ZADMIN "!zadmin"
|
|
|
|
#define SAYHOOKS_KEYWORD_ZCLASS "!zclass"
|
|
|
|
#define SAYHOOKS_KEYWORD_ZSPAWN "!zspawn"
|
|
|
|
#define SAYHOOKS_KEYWORD_ZTELE "!ztele"
|
|
|
|
#define SAYHOOKS_KEYWORD_ZHP "!zhp"
|
|
|
|
#define SAYHOOKS_KEYWORD_ZMARKET "!zmarket"
|
|
|
|
/**
|
|
|
|
* @endsection
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
|
|
|
|
2009-04-30 07:36:57 +02:00
|
|
|
/**
|
|
|
|
* @section Say hook quiet flags.
|
|
|
|
*/
|
|
|
|
#define SAYHOOKS_KEYWORD_FLAG_ZMENU 1
|
|
|
|
#define SAYHOOKS_KEYWORD_FLAG_ZADMIN 2
|
|
|
|
#define SAYHOOKS_KEYWORD_FLAG_ZCLASS 4
|
|
|
|
#define SAYHOOKS_KEYWORD_FLAG_ZSPAWN 8
|
|
|
|
#define SAYHOOKS_KEYWORD_FLAG_ZTELE 16
|
|
|
|
#define SAYHOOKS_KEYWORD_FLAG_ZHP 32
|
|
|
|
#define SAYHOOKS_KEYWORD_FLAG_ZMARKET 64
|
|
|
|
/**
|
|
|
|
* @endsection
|
|
|
|
*/
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
/**
|
|
|
|
* Say hooks module init function.
|
|
|
|
*/
|
|
|
|
SayHooksInit()
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-29 01:58:41 +02:00
|
|
|
// Hook client's say commands.
|
|
|
|
RegConsoleCmd("say", SayHooksCmdSay);
|
|
|
|
RegConsoleCmd("say_team", SayHooksCmdSay);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
/**
|
|
|
|
* Command callback. (say, say_team)
|
|
|
|
* Catches all client's say text and takes action on key words.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param argc The number of arguments in command string.
|
|
|
|
*/
|
|
|
|
public Action:SayHooksCmdSay(client, argc)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-29 01:58:41 +02:00
|
|
|
decl String:args[SAYHOOKS_MAX_CHAT_LENGTH];
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
// Get client's command string (typically 'say "text"')
|
2008-10-04 22:59:11 +02:00
|
|
|
GetCmdArgString(args, sizeof(args));
|
2009-04-29 01:58:41 +02:00
|
|
|
|
|
|
|
// Strip away the quotes.
|
2008-10-04 22:59:11 +02:00
|
|
|
ReplaceString(args, sizeof(args), "\"", "");
|
|
|
|
|
2009-04-30 07:36:57 +02:00
|
|
|
new chatflag = SayHooksChatToFlag(args);
|
|
|
|
|
|
|
|
// If chatflag is invalid, then continue.
|
|
|
|
if (!chatflag)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-30 07:36:57 +02:00
|
|
|
return Plugin_Continue;
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-05-06 05:31:48 +02:00
|
|
|
// Define success as true until otherwise changed.
|
|
|
|
new bool:success = true;
|
|
|
|
|
2009-04-30 07:36:57 +02:00
|
|
|
switch(chatflag)
|
2009-03-30 21:40:56 +02:00
|
|
|
{
|
2009-04-30 07:36:57 +02:00
|
|
|
// Client triggered ZMenu flag.
|
|
|
|
case SAYHOOKS_KEYWORD_FLAG_ZMENU:
|
|
|
|
{
|
|
|
|
// Send main menu.
|
|
|
|
MenuMain(client);
|
|
|
|
}
|
|
|
|
// Client triggered ZAdmin flag.
|
|
|
|
case SAYHOOKS_KEYWORD_FLAG_ZADMIN:
|
|
|
|
{
|
2009-05-06 05:31:48 +02:00
|
|
|
success = ZRAdminMenu(client);
|
2009-04-30 07:36:57 +02:00
|
|
|
}
|
|
|
|
// Client triggered ZClass flag.
|
|
|
|
case SAYHOOKS_KEYWORD_FLAG_ZCLASS:
|
|
|
|
{
|
|
|
|
// Send class menu.
|
|
|
|
ClassMenuMain(client);
|
|
|
|
}
|
|
|
|
// Client triggered ZSpawn flag.
|
|
|
|
case SAYHOOKS_KEYWORD_FLAG_ZSPAWN:
|
|
|
|
{
|
|
|
|
// Spawns a late-joining client into the game.
|
2009-05-06 05:31:48 +02:00
|
|
|
success = ZSpawnClient(client);
|
2009-04-30 07:36:57 +02:00
|
|
|
}
|
|
|
|
// Client triggered ZTele flag.
|
|
|
|
case SAYHOOKS_KEYWORD_FLAG_ZTELE:
|
|
|
|
{
|
2009-05-06 05:31:48 +02:00
|
|
|
success = ZTeleClient(client);
|
2009-04-30 07:36:57 +02:00
|
|
|
}
|
|
|
|
// Client triggered ZHP flag.
|
|
|
|
case SAYHOOKS_KEYWORD_FLAG_ZHP:
|
|
|
|
{
|
|
|
|
// Toggle ZHP.
|
2009-05-06 05:31:48 +02:00
|
|
|
success = ZHPToggle(client);
|
2009-04-30 07:36:57 +02:00
|
|
|
}
|
|
|
|
// Client triggered ZMarket flag.
|
|
|
|
case SAYHOOKS_KEYWORD_FLAG_ZMARKET:
|
|
|
|
{
|
|
|
|
// Send market menu.
|
2009-05-06 05:31:48 +02:00
|
|
|
success = ZMarketMenu(client);
|
2009-04-30 07:36:57 +02:00
|
|
|
}
|
2009-03-30 21:40:56 +02:00
|
|
|
}
|
|
|
|
|
2009-04-30 07:36:57 +02:00
|
|
|
// If quiet cvar is disabled, then continue.
|
|
|
|
new bool:quiet = GetConVarBool(g_hCvarsList[CVAR_SAYHOOKS_QUIET]);
|
|
|
|
if (!quiet)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-30 07:36:57 +02:00
|
|
|
return Plugin_Continue;
|
2009-04-16 08:08:58 +02:00
|
|
|
}
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-06 05:31:48 +02:00
|
|
|
// If filter is enabled, and the command failed to be executed, then stop.
|
|
|
|
new bool:filter = GetConVarBool(g_hCvarsList[CVAR_SAYHOOKS_QUIET_FILTER]);
|
|
|
|
if (filter && !success)
|
|
|
|
{
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
2009-04-30 07:36:57 +02:00
|
|
|
// If word is flagged to be quieted, then stop.
|
|
|
|
new quietflags = GetConVarInt(g_hCvarsList[CVAR_SAYHOOKS_QUIET_FLAGS]);
|
|
|
|
if (quietflags & chatflag)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-30 07:36:57 +02:00
|
|
|
return Plugin_Handled;
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-04-30 07:36:57 +02:00
|
|
|
return Plugin_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert chat text into a defined flag.
|
|
|
|
*
|
|
|
|
* @param chat The chat text to convert.
|
|
|
|
* @return Returns flag for word given, returns 0 if matches none.
|
|
|
|
*/
|
|
|
|
SayHooksChatToFlag(const String:chat[])
|
|
|
|
{
|
|
|
|
// Return flag for chatstring.
|
|
|
|
|
|
|
|
if (StrEqual(chat, SAYHOOKS_KEYWORD_ZMENU, false))
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-30 07:36:57 +02:00
|
|
|
return SAYHOOKS_KEYWORD_FLAG_ZMENU;
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
2009-04-30 07:36:57 +02:00
|
|
|
else if (StrEqual(chat, SAYHOOKS_KEYWORD_ZADMIN, false))
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-30 07:36:57 +02:00
|
|
|
return SAYHOOKS_KEYWORD_FLAG_ZADMIN;
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
2009-04-30 07:36:57 +02:00
|
|
|
else if (StrEqual(chat, SAYHOOKS_KEYWORD_ZCLASS, false))
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-30 07:36:57 +02:00
|
|
|
return SAYHOOKS_KEYWORD_FLAG_ZCLASS;
|
|
|
|
}
|
|
|
|
else if (StrEqual(chat, SAYHOOKS_KEYWORD_ZSPAWN, false))
|
|
|
|
{
|
|
|
|
return SAYHOOKS_KEYWORD_FLAG_ZSPAWN;
|
|
|
|
}
|
|
|
|
else if (StrEqual(chat, SAYHOOKS_KEYWORD_ZTELE, false))
|
|
|
|
{
|
|
|
|
return SAYHOOKS_KEYWORD_FLAG_ZTELE;
|
|
|
|
}
|
|
|
|
else if (StrEqual(chat, SAYHOOKS_KEYWORD_ZHP, false))
|
|
|
|
{
|
|
|
|
return SAYHOOKS_KEYWORD_FLAG_ZHP;
|
|
|
|
}
|
|
|
|
else if (StrEqual(chat, SAYHOOKS_KEYWORD_ZMARKET, false))
|
|
|
|
{
|
|
|
|
return SAYHOOKS_KEYWORD_FLAG_ZMARKET;
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-04-30 07:36:57 +02:00
|
|
|
// Return 0.
|
|
|
|
return 0;
|
2009-05-01 11:22:45 +02:00
|
|
|
}
|