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,
29 #define USERMSG_PASSTHRU (1<<0) /**< (DEPRECATED, NO EFFECT) */
30 #define USERMSG_PASSTHRU_ALL (1<<1) /**< (DEPRECATED, NO EFFECT) */
31 #define USERMSG_RELIABLE (1<<2) /**< Message will be set on the reliable stream */
32 #define USERMSG_INITMSG (1<<3) /**< Message will be considered to be an initmsg */
33 #define USERMSG_BLOCK_MM (1<<4) /**< Message will be blocked from going through MM:S hooks */
34 #define USERMSG_BLOCK_SM (1<<5) /**< Message will be blocked from going through SourceMod hooks */
35 #define USERMSG_BLOCK_ALL (1<<6) /**< Message will be blocked from going through any hooks */
38 * Returns the ID of a given message, or -1 on failure.
40 * @param msg String containing message name (case sensitive).
41 * @return A message index, or INVALID_MESSAGE_ID on failure.
43 native UserMsg:GetUserMessageId(const String:msg[]);
46 * Retrieves the name of a message by ID.
48 * @param msg_id Message index.
49 * @param msg Buffer to store the name of the message.
50 * @param maxlength Maximum length of string buffer.
51 * @return True if message index is valid, false otherwise.
53 native bool:GetUserMessageName(UserMsg:msg_id, String:msg[], maxlength);
56 * Starts a usermessage (network message).
57 * @note Only one message can be active at a time.
58 * @note It is illegal to send any message while a non-intercept hook is in progress.
60 * @param msgname Message name to start.
61 * @param clients Array containing player indexes to broadcast to.
62 * @param numClients Number of players in the array.
63 * @param flags Optional flags to set.
64 * @return A handle to a bf_write bit packing structure, or
65 * INVALID_HANDLE on failure.
66 * @error Invalid message name or unable to start a message.
68 native Handle:StartMessage(String:msgname[], clients[], numClients, flags=0);
71 * Starts a usermessage (network message).
72 * @note Only one message can be active at a time.
73 * @note It is illegal to send any message while a non-intercept hook is in progress.
75 * @param msg Message index to start.
76 * @param clients Array containing player indexes to broadcast to.
77 * @param numClients Number of players in the array.
78 * @param flags Optional flags to set.
79 * @return A handle to a bf_write bit packing structure, or
80 * INVALID_HANDLE on failure.
81 * @error Invalid message name or unable to start a message.
83 native Handle:StartMessageEx(UserMsg:msg, clients[], numClients, flags=0);
86 * Ends a previously started user message (network message).
93 * Called when a message is hooked
95 * @param msg_id Message index.
96 * @param bf Handle to the input bit buffer of the message.
97 * @param players Array containing player indexes.
98 * @param playersNum Number of players in the array.
99 * @param reliable True if message is reliable, false otherwise.
100 * @param init True if message is an initmsg, false otherwise.
101 * @return Ignored for normal hooks. For intercept hooks, false blocks
102 * the message from being sent, and true continues.
104 functag MsgHook Action:public(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init);
107 * Called when a message is finished sending.
109 * @param msg_id Message index.
111 functag MsgSentNotify public(UserMsg:msg_id);
114 * Hooks a user message.
116 * @param msg_id Message index.
117 * @param hook Function to use as a hook.
118 * @param intercept If intercept is true, message will be fully intercepted,
119 * allowing the user to block the message. Otherwise,
120 * the hook is normal and ignores the return value.
121 * @param notify Notification function.
123 * @error Invalid message index.
125 native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgSentNotify:notify=MsgSentNotify:-1);
128 * Removes one usermessage hook.
130 * @param msg_id Message index.
131 * @param hook Function used for the hook.
132 * @param intercept Specifies whether the hook was an intercept hook or not.
134 * @error Invalid message index.
136 native UnhookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
139 * Starts a usermessage (network message) that broadcasts to all clients.
140 * @note See StartMessage or StartMessageEx().
142 * @param msgname Message name to start.
143 * @param flags Optional flags to set.
144 * @return A handle to a bf_write bit packing structure, or
145 * INVALID_HANDLE on failure.
147 stock Handle:StartMessageAll(String:msgname[], flags=0)
149 new maxClients = GetMaxClients();
151 new clients[maxClients];
152 for (new i=1; i<=maxClients; i++)
154 if (IsClientConnected(i))
156 clients[total++] = i;
159 return StartMessage(msgname, clients, total, flags);
163 * Starts a simpler usermessage (network message) for one client.
164 * @note See StartMessage or StartMessageEx().
166 * @param msgname Message name to start.
167 * @param client Client to send to.
168 * @param flags Optional flags to set.
169 * @return A handle to a bf_write bit packing structure, or
170 * INVALID_HANDLE on failure.
172 stock Handle:StartMessageOne(String:msgname[], client, flags=0)
178 return StartMessage(msgname, players, 1, flags);