sm-zombiereloaded-3/src/zr/sayhooks.inc

182 lines
4.6 KiB
PHP
Raw Normal View History

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
*
* File: sayhooks.inc
* Description: Hook plugin say commands and redirect to their handling module.
*
* ============================================================================
*/
/**
* 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
*/
/**
* @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), "\"", "");
new chatflag = SayHooksChatToFlag(args);
// If chatflag is invalid, then continue.
if (!chatflag)
2008-10-04 22:59:11 +02:00
{
return Plugin_Continue;
2008-10-04 22:59:11 +02:00
}
switch(chatflag)
{
// Client triggered ZMenu flag.
case SAYHOOKS_KEYWORD_FLAG_ZMENU:
{
// Send main menu.
MenuMain(client);
}
// Client triggered ZAdmin flag.
case SAYHOOKS_KEYWORD_FLAG_ZADMIN:
{
ZRAdminMenu(client);
}
// 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.
ZSpawnClient(client);
}
// Client triggered ZTele flag.
case SAYHOOKS_KEYWORD_FLAG_ZTELE:
{
ZTele(client);
}
// Client triggered ZHP flag.
case SAYHOOKS_KEYWORD_FLAG_ZHP:
{
// Toggle ZHP.
ZHPToggle(client);
}
// Client triggered ZMarket flag.
case SAYHOOKS_KEYWORD_FLAG_ZMARKET:
{
// Send market menu.
ZMarketMenu(client);
}
}
// 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
{
return Plugin_Continue;
}
2008-10-04 22:59:11 +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
{
return Plugin_Handled;
2008-10-04 22:59:11 +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
{
return SAYHOOKS_KEYWORD_FLAG_ZMENU;
2008-10-04 22:59:11 +02:00
}
else if (StrEqual(chat, SAYHOOKS_KEYWORD_ZADMIN, false))
2008-10-04 22:59:11 +02:00
{
return SAYHOOKS_KEYWORD_FLAG_ZADMIN;
2008-10-04 22:59:11 +02:00
}
else if (StrEqual(chat, SAYHOOKS_KEYWORD_ZCLASS, false))
2008-10-04 22:59:11 +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
}
// Return 0.
return 0;
2008-10-04 22:59:11 +02:00
}