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
23 INVALID_MESSAGE_ID = -1,
26 #define USERMSG_PASSTHRU (1<<0) /**< Message will pass through other SourceMM plugins */
27 #define USERMSG_PASSTHRU_ALL (1<<1) /**< Message will pass through other SourceMM plugins AND SourceMod */
28 #define USERMSG_RELIABLE (1<<2) /**< Message will be set to reliable */
29 #define USERMSG_INITMSG (1<<3) /**< Message will be considered to be an initmsg */
32 * Returns the ID of a given message, or -1 on failure.
34 * @param msg String containing message name (case sensitive).
35 * @return A message index, or INVALID_MESSAGE_ID on failure.
37 native UserMsg:GetUserMessageId(const String:msg[]);
40 * Retrieves the name of a message by ID.
42 * @param msg_id Message index.
43 * @param msg Buffer to store the name of the message.
44 * @param maxlength Maximum length of string buffer.
45 * @return True if message index is valid, false otherwise.
47 native bool:GetUserMessageName(UserMsg:msg_id, String:msg[], maxlength);
50 * Starts a usermessage (network message).
51 * @note Only one message can be active at a time.
52 * @note It is illegal to send any message while a non-intercept hook is in progress.
54 * @param msgname Message name to start.
55 * @param clients Array containing player indexes to broadcast to.
56 * @param numClients Number of players in the array.
57 * @return A handle to a bf_write bit packing structure, or
58 * INVALID_HANDLE on failure.
59 * @error Invalid message name or unable to start a message.
61 native Handle:StartMessage(String:msgname[], clients[], numClients, flags);
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 msg Message index to start.
69 * @param clients Array containing player indexes to broadcast to.
70 * @param numClients Number of players in the array.
71 * @return A handle to a bf_write bit packing structure, or
72 * INVALID_HANDLE on failure.
73 * @error Invalid message name or unable to start a message.
75 native Handle:StartMessageEx(UserMsg:msg, clients[], numClients, flags);
78 * Ends a previously started user message (network message).
85 * @brief Called when a message is hooked
87 * @param msg_id Message index.
88 * @param players Array containing player indexes.
89 * @param playersNum Number of players in the array.
90 * @param reliable True if message is reliable, false otherwise.
91 * @param init True if message is an initmsg, false otherwise.
92 * @return Ignored for normal hooks. For intercept hooks, false blocks
93 * the message from being sent, and true continues.
95 functag MsgHook bool:public(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init);
98 * @brief Hooks a user message.
100 * @param msg_id Message index.
101 * @param hook Function to use as a hook.
102 * @param intercept If intercept is true, message will be fully intercepted,
103 * allowing the user to block the message. Otherwise,
104 * the hook is normal and ignores the return value.
106 * @error Invalid message index.
108 native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
111 * @brief Removes one usermessage hook.
113 * @param msg_id Message index.
114 * @param hook Function used for the hook.
115 * @param intercept Specifies whether the hook was an intercept hook or not.
117 * @error Invalid message index.
119 native UnHookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false);
122 * @brief Called when a message is finished sending.
124 * @param msg_id Message index.
126 functag MsgSentNotify public(UserMsg:msg_id);
129 * @brief Notifies when a message has finished sending.
131 * @param msg_id Message index.
132 * @param notify Notification function.
134 * @error Invalid message index.
136 native NotifyUserMessage(UserMsg:msg_id, MsgSentNotify:notify);
139 * @brief Removes a user message notification.
141 * @param msg_id Message index.
142 * @param notify Notification function.
144 * @error Invalid message index.
146 native RemoveNotifyUserMessage(UserMsg:msg_id, MsgSentNotify:notify);
149 * Starts a usermessage (network message) that broadcasts to all clients.
150 * @note See StartMessage or StartMessageEx().
152 * @param msgname Message name to start.
153 * @param flags Optional flags to set.
154 * @return A handle to a bf_write bit packing structure, or
155 * INVALID_HANDLE on failure.
157 stock Handle:StartMessageAll(String:msgname[], flags=0)
159 new maxClients = GetMaxClients();
161 new clients[maxClients];
162 for (new i=1; i<=maxClients; i++)
164 if (IsClientConnected(i))
166 clients[total++] = i;
169 return StartMessage(msgname, clients, total, flags);
173 * Starts a simpler usermessage (network message) for one client.
174 * @note See StartMessage or StartMessageEx().
176 * @param msgname Message name to start.
177 * @param client Client to send to.
178 * @param flags Optional flags to set.
179 * @return A handle to a bf_write bit packing structure, or
180 * INVALID_HANDLE on failure.
182 stock Handle:StartMessageOne(String:msgname[], client, flags=0)
188 return StartMessage(msgname, players, 1, flags);