3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is part of the SourceMod/SourcePawn SDK. This file may only be used
8 * or modified under the Terms and Conditions of its License Agreement, which is found
9 * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
10 * may change at any time. To view the latest information, see:
11 * http://www.sourcemod.net/license.php
16 #if defined _eventsmsgs_included
19 #define _eventsmsgs_included
22 * UserMsg helper values.
26 INVALID_MESSAGE_ID = -1,
30 * @section Message Flags.
32 #define USERMSG_PASSTHRU (1<<0) /**< (DEPRECATED, NO EFFECT) */
33 #define USERMSG_PASSTHRU_ALL (1<<1) /**< (DEPRECATED, NO EFFECT) */
34 #define USERMSG_RELIABLE (1<<2) /**< Message will be set on the reliable stream */
35 #define USERMSG_INITMSG (1<<3) /**< Message will be considered to be an initmsg */
36 #define USERMSG_BLOCK_MM (1<<4) /**< (DEPRECATED, NO EFFECT) */
37 #define USERMSG_BLOCK_SM (1<<5) /**< (DEPRECATED, NO EFFECT) */
38 #define USERMSG_BLOCK_ALL (1<<6) /**< (DEPRECATED, NO EFFECT) */
39 #define USERMSG_BLOCKHOOKS (1<<7) /**< Prevents the message from triggering SourceMod and Metamod hooks */
46 * Returns the ID of a given message, or -1 on failure.
48 * @param msg String containing message name (case sensitive).
49 * @return A message index, or INVALID_MESSAGE_ID on failure.
51 native UserMsg:GetUserMessageId(const String:msg[]);
54 * Retrieves the name of a message by ID.
56 * @param msg_id Message index.
57 * @param msg Buffer to store the name of the message.
58 * @param maxlength Maximum length of string buffer.
59 * @return True if message index is valid, false otherwise.
61 native bool:GetUserMessageName(UserMsg:msg_id, String:msg[], maxlength);
64 * Starts a usermessage (network message).
65 * @note Only one message can be active at a time.
66 * @note It is illegal to send any message while a non-intercept hook is in progress.
68 * @param msgname Message name to start.
69 * @param clients Array containing player indexes to broadcast to.
70 * @param numClients Number of players in the array.
71 * @param flags Optional flags to set.
72 * @return A handle to a bf_write bit packing structure, or
73 * INVALID_HANDLE on failure.
74 * @error Invalid message name or unable to start a message.
76 native Handle:StartMessage(String:msgname[], clients[], numClients, flags=0);
79 * Starts a usermessage (network message).
80 * @note Only one message can be active at a time.
81 * @note It is illegal to send any message while a non-intercept hook is in progress.
83 * @param msg Message index to start.
84 * @param clients Array containing player indexes to broadcast to.
85 * @param numClients Number of players in the array.
86 * @param flags Optional flags to set.
87 * @return A handle to a bf_write bit packing structure, or
88 * INVALID_HANDLE on failure.
89 * @error Invalid message name or unable to start a message.
91 native Handle:StartMessageEx(UserMsg:msg, clients[], numClients, flags=0);
94 * Ends a previously started user message (network message).
101 * Called when a message is hooked
103 * @param msg_id Message index.
104 * @param bf Handle to the input bit buffer of the message.
105 * @param players Array containing player indexes.
106 * @param playersNum Number of players in the array.
107 * @param reliable True if message is reliable, false otherwise.
108 * @param init True if message is an initmsg, false otherwise.
109 * @return Ignored for normal hooks. For intercept hooks, false blocks
110 * the message from being sent, and true continues.
112 functag MsgHook Action:public(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init);
115 * Called when a message is finished sending.
117 * @param msg_id Message index.
119 functag MsgSentNotify public(UserMsg:msg_id);
122 * Hooks a user message.
124 * @param msg_id Message index.
125 * @param hook Function to use as a hook.
126 * @param intercept If intercept is true, message will be fully intercepted,
127 * allowing the user to block the message. Otherwise,
128 * the hook is normal and ignores the return value.
129 * @param notify Notification function.
131 * @error Invalid message index.
133 native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgSentNotify:notify=MsgSentNotify:-1);
136 * Removes one usermessage hook.
138 * @param msg_id Message index.
139 * @param hook Function used for the hook.
140 * @param intercept Specifies whether the hook was an intercept hook or not.
142 * @error Invalid message index.
144 native UnhookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
147 * Starts a usermessage (network message) that broadcasts to all clients.
148 * @note See StartMessage or StartMessageEx().
150 * @param msgname Message name to start.
151 * @param flags Optional flags to set.
152 * @return A handle to a bf_write bit packing structure, or
153 * INVALID_HANDLE on failure.
155 stock Handle:StartMessageAll(String:msgname[], flags=0)
157 new maxClients = GetMaxClients();
159 new clients[maxClients];
160 for (new i=1; i<=maxClients; i++)
162 if (IsClientConnected(i))
164 clients[total++] = i;
167 return StartMessage(msgname, clients, total, flags);
171 * Starts a simpler usermessage (network message) for one client.
172 * @note See StartMessage or StartMessageEx().
174 * @param msgname Message name to start.
175 * @param client Client to send to.
176 * @param flags Optional flags to set.
177 * @return A handle to a bf_write bit packing structure, or
178 * INVALID_HANDLE on failure.
180 stock Handle:StartMessageOne(String:msgname[], client, flags=0)
186 return StartMessage(msgname, players, 1, flags);