This is a replacement for the messagemode/messagemode2 commands.
About the plugin [top]
So as everyone probably already knows, Valve added messagemode to the list of the commands that cannot be executed by the game server for security reasons (visit this site for more informations:
https://thehackernews.com/2019/03/co...e-servers.html). This compromised the plugins that use the command, so that's why I did this API. It allows you to retrieve what the player write in chat through say/say_team. This could be done even without it, but I thought interesting to do for flexibility reasons.
Functions [top]
Code:
/**
* Registers a messagemode hook.
*
* @note Below is the prototype of callback:
* -
* Called when player write the data.
*
* @param index Client index
* @param message Text that the player wrote
*
* @noreturn
*
* public OnWriteData(index, message[])
* -
* @param callback The forward to call
* @param cancel If true, player will be able to cancel the hook by typing /cancel
*
* @return Returns a handle to the forward on success, -1 otherwise.
* @error If the specified callback is invalid, an error will be thrown.
*/
native mm_register_hook(const callback[], bool:cancel = true);
Code:
/**
* Starts a messagemode hook.
*
* @param func_id The forward to start
* @param index Client index
*
* @return 1 on success, 0 otherwise.
* @error If the index is not within the range of 1 to MaxClients or
* the client is not connected, or if the specified function is invalid,
* an error will be thrown.
*/
native mm_parse_hook(func_id, index);
Installation [top]
- Download and compile messagemode_api.sma and put the compiled binary (.amxx) in addons/amxmodx/plugins, then enabled it in addons/amxmodx/configs/plugins.ini.
- Download messagemode_api.inc and put it in addons/amxmodx/scripting/include.
- Download messagemode_api.txt and put it in addons/amxmodx/data/lang.
Examples [top]
Code:
#include <amxmodx>
#include <amxmisc>
#include <messagemode_api>
new g_iHookId;
public plugin_init()
{
register_plugin("Messagemode API - Example", "1.0", "Crazy");
g_iHookId = mm_register_hook("OnWriteData", true);
register_concmd("amx_messagemode", "CmdMessageMode", ADMIN_CHAT);
}
public OnWriteData(index, message[])
{
new szName[32];
get_user_name(index, szName, charsmax(szName));
log_amx("Admin %s says ^"%s^"", szName, message);
}
public CmdMessageMode(index, level, command_id)
{
if (!(cmd_access(index, level, command_id, 1)))
return PLUGIN_HANDLED;
mm_parse_hook(g_iHookId, index);
return PLUGIN_HANDLED;
}
messagemode_api.inc [top]
Code:
#if defined _messagemode_api_included
#endinput
#endif
#define _messagemode_api_included
#pragma reqlib messagemode_api
#if !defined AMXMODX_NOAUTOLOAD
#pragma loadlib messagemode_api
#endif
/**
* Registers a messagemode hook.
*
* @note Below is the prototype of callback:
* -
* Called when player write the data.
*
* @param index Client index
* @param message Text that the player wrote
*
* @noreturn
*
* public OnWriteData(index, message[])
* -
* @param callback The forward to call
* @param cancel If true, player will be able to cancel the hook by typing /cancel
*
* @return Returns a handle to the forward on success, -1 otherwise.
* @error If the specified callback is invalid, an error will be thrown.
*/
native mm_register_hook(const callback[], bool:cancel = true);
/**
* Starts a messagemode hook (replaces the current hook of the player if any).
*
* @param func_id The forward to start
* @param index Client index
*
* @return 1 on success, 0 otherwise.
* @error If the index is not within the range of 1 to MaxClients or
* the client is not connected, or if the specified function is invalid,
* an error will be thrown.
*/
native mm_parse_hook(func_id, index);
messagemode_api.txt [top]
Code:
[en]
MM_TYPE_START = * You are in input mode, type /cancel to back to chat.
MM_TYPE_CANCEL = * You are no longer in input mode.
[bp]
MM_TYPE_START = * Voce esta no modo de entrada de texto, digite /cancel para voltar ao chat.
MM_TYPE_CANCEL = * Voce nao esta mais no modo de entrada de texto.
Credits [top]