3 * =============================================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, version 3.0, as published by the
11 * Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
21 * As a special exception, AlliedModders LLC gives you permission to link the
22 * code of this program (as well as its derivative works) to "Half-Life 2," the
23 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
24 * by the Valve Corporation. You must obey the GNU General Public License in
25 * all respects for all other code used. Additionally, AlliedModders LLC grants
26 * this exception to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
28 * or <http://www.sourcemod.net/license.php>.
33 #if defined _eventsmsgs_included
36 #define _eventsmsgs_included
39 * UserMsg helper values.
43 INVALID_MESSAGE_ID = -1,
47 * @section Message Flags.
49 #define USERMSG_RELIABLE (1<<2) /**< Message will be set on the reliable stream */
50 #define USERMSG_INITMSG (1<<3) /**< Message will be considered to be an initmsg */
51 #define USERMSG_BLOCKHOOKS (1<<7) /**< Prevents the message from triggering SourceMod and Metamod hooks */
53 #pragma deprecated Constant has no effect
54 #define USERMSG_PASSTHRU (1<<0) /**< (DEPRECATED, NO EFFECT) */
55 #pragma deprecated Constant has no effect
56 #define USERMSG_PASSTHRU_ALL (1<<1) /**< (DEPRECATED, NO EFFECT) */
57 #pragma deprecated Constant has no effect
58 #define USERMSG_BLOCK_MM (1<<4) /**< (DEPRECATED, NO EFFECT) */
59 #pragma deprecated Constant has no effect
60 #define USERMSG_BLOCK_SM (1<<5) /**< (DEPRECATED, NO EFFECT) */
61 #pragma deprecated Constant has no effect
62 #define USERMSG_BLOCK_ALL (1<<6) /**< (DEPRECATED, NO EFFECT) */
69 * Returns the ID of a given message, or -1 on failure.
71 * @param msg String containing message name (case sensitive).
72 * @return A message index, or INVALID_MESSAGE_ID on failure.
74 native UserMsg:GetUserMessageId(const String:msg[]);
77 * Retrieves the name of a message by ID.
79 * @param msg_id Message index.
80 * @param msg Buffer to store the name of the message.
81 * @param maxlength Maximum length of string buffer.
82 * @return True if message index is valid, false otherwise.
84 native bool:GetUserMessageName(UserMsg:msg_id, String:msg[], maxlength);
87 * Starts a usermessage (network message).
88 * @note Only one message can be active at a time.
89 * @note It is illegal to send any message while a non-intercept hook is in progress.
91 * @param msgname Message name to start.
92 * @param clients Array containing player indexes to broadcast to.
93 * @param numClients Number of players in the array.
94 * @param flags Optional flags to set.
95 * @return A handle to a bf_write bit packing structure, or
96 * INVALID_HANDLE on failure.
97 * @error Invalid message name or unable to start a message.
99 native Handle:StartMessage(String:msgname[], clients[], numClients, flags=0);
102 * Starts a usermessage (network message).
103 * @note Only one message can be active at a time.
104 * @note It is illegal to send any message while a non-intercept hook is in progress.
106 * @param msg Message index to start.
107 * @param clients Array containing player indexes to broadcast to.
108 * @param numClients Number of players in the array.
109 * @param flags Optional flags to set.
110 * @return A handle to a bf_write bit packing structure, or
111 * INVALID_HANDLE on failure.
112 * @error Invalid message name or unable to start a message.
114 native Handle:StartMessageEx(UserMsg:msg, clients[], numClients, flags=0);
117 * Ends a previously started user message (network message).
124 * Called when a message is hooked
126 * @param msg_id Message index.
127 * @param bf Handle to the input bit buffer of the message.
128 * @param players Array containing player indexes.
129 * @param playersNum Number of players in the array.
130 * @param reliable True if message is reliable, false otherwise.
131 * @param init True if message is an initmsg, false otherwise.
132 * @return Ignored for normal hooks. For intercept hooks, false blocks
133 * the message from being sent, and true continues.
135 functag MsgHook Action:public(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init);
138 * Called when a message is finished sending.
140 * @param msg_id Message index.
142 functag MsgSentNotify public(UserMsg:msg_id);
145 * Hooks a user message.
147 * @param msg_id Message index.
148 * @param hook Function to use as a hook.
149 * @param intercept If intercept is true, message will be fully intercepted,
150 * allowing the user to block the message. Otherwise,
151 * the hook is normal and ignores the return value.
152 * @param notify Notification function.
154 * @error Invalid message index.
156 native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgSentNotify:notify=MsgSentNotify:-1);
159 * Removes one usermessage hook.
161 * @param msg_id Message index.
162 * @param hook Function used for the hook.
163 * @param intercept Specifies whether the hook was an intercept hook or not.
165 * @error Invalid message index.
167 native UnhookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
170 * Starts a usermessage (network message) that broadcasts to all clients.
171 * @note See StartMessage or StartMessageEx().
173 * @param msgname Message name to start.
174 * @param flags Optional flags to set.
175 * @return A handle to a bf_write bit packing structure, or
176 * INVALID_HANDLE on failure.
178 stock Handle:StartMessageAll(String:msgname[], flags=0)
180 new maxClients = GetMaxClients();
182 new clients[maxClients];
183 for (new i=1; i<=maxClients; i++)
185 if (IsClientConnected(i))
187 clients[total++] = i;
190 return StartMessage(msgname, clients, total, flags);
194 * Starts a simpler usermessage (network message) for one client.
195 * @note See StartMessage or StartMessageEx().
197 * @param msgname Message name to start.
198 * @param client Client to send to.
199 * @param flags Optional flags to set.
200 * @return A handle to a bf_write bit packing structure, or
201 * INVALID_HANDLE on failure.
203 stock Handle:StartMessageOne(String:msgname[], client, flags=0)
209 return StartMessage(msgname, players, 1, flags);