3 * =============================================================================
4 * SourceMod (C)2004-2008 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 */
58 * Returns the ID of a given message, or -1 on failure.
60 * @param msg String containing message name (case sensitive).
61 * @return A message index, or INVALID_MESSAGE_ID on failure.
63 native UserMsg:GetUserMessageId(const String:msg[]);
66 * Retrieves the name of a message by ID.
68 * @param msg_id Message index.
69 * @param msg Buffer to store the name of the message.
70 * @param maxlength Maximum length of string buffer.
71 * @return True if message index is valid, false otherwise.
73 native bool:GetUserMessageName(UserMsg:msg_id, String:msg[], maxlength);
76 * Starts a usermessage (network message).
77 * @note Only one message can be active at a time.
78 * @note It is illegal to send any message while a non-intercept hook is in progress.
80 * @param msgname Message name to start.
81 * @param clients Array containing player indexes to broadcast to.
82 * @param numClients Number of players in the array.
83 * @param flags Optional flags to set.
84 * @return A handle to a bf_write bit packing structure, or
85 * INVALID_HANDLE on failure.
86 * @error Invalid message name or unable to start a message.
88 native Handle:StartMessage(String:msgname[], clients[], numClients, flags=0);
91 * Starts a usermessage (network message).
92 * @note Only one message can be active at a time.
93 * @note It is illegal to send any message while a non-intercept hook is in progress.
95 * @param msg Message index to start.
96 * @param clients Array containing player indexes to broadcast to.
97 * @param numClients Number of players in the array.
98 * @param flags Optional flags to set.
99 * @return A handle to a bf_write bit packing structure, or
100 * INVALID_HANDLE on failure.
101 * @error Invalid message name or unable to start a message.
103 native Handle:StartMessageEx(UserMsg:msg, clients[], numClients, flags=0);
106 * Ends a previously started user message (network message).
113 * Called when a message is hooked
115 * @param msg_id Message index.
116 * @param bf Handle to the input bit buffer of the message.
117 * @param players Array containing player indexes.
118 * @param playersNum Number of players in the array.
119 * @param reliable True if message is reliable, false otherwise.
120 * @param init True if message is an initmsg, false otherwise.
121 * @return Ignored for normal hooks. For intercept hooks, Plugin_Handled
122 * blocks the message from being sent, and Plugin_Continue
123 * resumes normal functionality.
125 functag MsgHook Action:public(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init);
128 * Called when a message is finished sending.
130 * @param msg_id Message index.
132 functag MsgSentNotify public(UserMsg:msg_id);
135 * Hooks a user message.
137 * @param msg_id Message index.
138 * @param hook Function to use as a hook.
139 * @param intercept If intercept is true, message will be fully intercepted,
140 * allowing the user to block the message. Otherwise,
141 * the hook is normal and ignores the return value.
142 * @param notify Notification function.
144 * @error Invalid message index.
146 native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgSentNotify:notify=MsgSentNotify:-1);
149 * Removes one usermessage hook.
151 * @param msg_id Message index.
152 * @param hook Function used for the hook.
153 * @param intercept Specifies whether the hook was an intercept hook or not.
155 * @error Invalid message index.
157 native UnhookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
160 * Starts a usermessage (network message) that broadcasts to all clients.
161 * @note See StartMessage or StartMessageEx().
163 * @param msgname Message name to start.
164 * @param flags Optional flags to set.
165 * @return A handle to a bf_write bit packing structure, or
166 * INVALID_HANDLE on failure.
168 stock Handle:StartMessageAll(String:msgname[], flags=0)
170 new maxClients = GetMaxClients();
172 new clients[maxClients];
173 for (new i=1; i<=maxClients; i++)
175 if (IsClientConnected(i))
177 clients[total++] = i;
180 return StartMessage(msgname, clients, total, flags);
184 * Starts a simpler usermessage (network message) for one client.
185 * @note See StartMessage or StartMessageEx().
187 * @param msgname Message name to start.
188 * @param client Client to send to.
189 * @param flags Optional flags to set.
190 * @return A handle to a bf_write bit packing structure, or
191 * INVALID_HANDLE on failure.
193 stock Handle:StartMessageOne(String:msgname[], client, flags=0)
199 return StartMessage(msgname, players, 1, flags);