|
ds@873
|
1 |
/** |
|
ds@873
|
2 |
* vim: set ts=4 : |
|
ds@873
|
3 |
* =============================================================== |
|
ds@873
|
4 |
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. |
|
ds@873
|
5 |
* =============================================================== |
|
ds@873
|
6 |
* |
|
ds@873
|
7 |
* This file is part of the SourceMod/SourcePawn SDK. This file may only be used |
|
ds@873
|
8 |
* or modified under the Terms and Conditions of its License Agreement, which is found |
|
ds@873
|
9 |
* in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins |
|
ds@873
|
10 |
* may change at any time. To view the latest information, see: |
|
ds@873
|
11 |
* http://www.sourcemod.net/license.php |
|
ds@873
|
12 |
* |
|
ds@873
|
13 |
* Version: $Id$ |
|
ds@873
|
14 |
*/ |
|
ds@873
|
15 |
|
|
ds@873
|
16 |
#if defined _halflife_included |
|
ds@873
|
17 |
#endinput |
|
ds@873
|
18 |
#endif |
|
ds@873
|
19 |
#define _halflife_included |
|
ds@873
|
20 |
|
|
faluco@1218
|
21 |
#define MOTDPANEL_TYPE_TEXT 0 /**< Treat msg as plain text */ |
|
faluco@1218
|
22 |
#define MOTDPANEL_TYPE_INDEX 1 /**< Msg is auto determined by the engine */ |
|
faluco@1218
|
23 |
#define MOTDPANEL_TYPE_URL 2 /**< Treat msg as an URL link */ |
|
faluco@1218
|
24 |
#define MOTDPANEL_TYPE_FILE 3 /**< Treat msg as a filename to be openned */ |
|
faluco@1218
|
25 |
|
|
ds@873
|
26 |
enum DialogType |
|
ds@873
|
27 |
{ |
|
ds@873
|
28 |
DialogType_Msg = 0, /**< just an on screen message */ |
|
ds@873
|
29 |
DialogType_Menu, /**< an options menu */ |
|
ds@873
|
30 |
DialogType_Text, /**< a richtext dialog */ |
|
ds@873
|
31 |
DialogType_Entry /**< an entry box */ |
|
ds@873
|
32 |
}; |
|
ds@873
|
33 |
|
|
ds@873
|
34 |
/** |
|
ds@873
|
35 |
* Logs a generic message to the HL2 logs. |
|
ds@873
|
36 |
* |
|
ds@873
|
37 |
* @param format String format. |
|
ds@873
|
38 |
* @param ... Format arguments. |
|
ds@873
|
39 |
* @noreturn |
|
ds@873
|
40 |
*/ |
|
ds@873
|
41 |
native LogToGame(const String:format[], any:...); |
|
ds@873
|
42 |
|
|
ds@873
|
43 |
/** |
|
dvander@1003
|
44 |
* Sets the seed value for the global Half-Life 2 Random Stream. |
|
ds@873
|
45 |
* |
|
ds@873
|
46 |
* @param seed Seed value. |
|
ds@873
|
47 |
* @noreturn |
|
ds@873
|
48 |
*/ |
|
ds@873
|
49 |
native SetRandomSeed(seed); |
|
ds@873
|
50 |
|
|
ds@873
|
51 |
/** |
|
dvander@1003
|
52 |
* Returns a random floating point number from the Half-Life 2 Random Stream. |
|
ds@873
|
53 |
* |
|
ds@873
|
54 |
* @param fMin Minimum random bound. |
|
ds@873
|
55 |
* @param fMax Maximum random bound. |
|
ds@873
|
56 |
* @return A random number between (inclusive) fMin and fMax. |
|
ds@873
|
57 |
*/ |
|
ds@873
|
58 |
native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0); |
|
ds@873
|
59 |
|
|
ds@873
|
60 |
/** |
|
dvander@1003
|
61 |
* Returns a random number from the Half-Life 2 Random Stream. |
|
ds@873
|
62 |
* |
|
ds@873
|
63 |
* @param nmin Minimum random bound. |
|
ds@873
|
64 |
* @param nmax Maximum random bound. |
|
ds@873
|
65 |
* @return A random number between (inclusive) nmin and nmax. |
|
ds@873
|
66 |
*/ |
|
ds@873
|
67 |
native GetRandomInt(nmin, nmax); |
|
ds@873
|
68 |
|
|
ds@873
|
69 |
/** |
|
ds@873
|
70 |
* Returns whether a map is valid or not. |
|
ds@873
|
71 |
* |
|
ds@873
|
72 |
* @param Map name, excluding .bsp extension. |
|
ds@873
|
73 |
* @return True if valid, false otherwise. |
|
ds@873
|
74 |
*/ |
|
ds@873
|
75 |
native bool:IsMapValid(const String:map[]); |
|
ds@873
|
76 |
|
|
ds@873
|
77 |
/** |
|
ds@873
|
78 |
* Returns whether the server is dedicated. |
|
ds@873
|
79 |
* |
|
ds@873
|
80 |
* @return True if dedicated, false otherwise. |
|
ds@873
|
81 |
*/ |
|
ds@873
|
82 |
native bool:IsDedicatedServer(); |
|
ds@873
|
83 |
|
|
ds@873
|
84 |
/** |
|
ds@873
|
85 |
* Returns a high-precision time value for profiling the engine. |
|
ds@873
|
86 |
* |
|
ds@873
|
87 |
* @return A floating point time value. |
|
ds@873
|
88 |
*/ |
|
ds@873
|
89 |
native Float:GetEngineTime(); |
|
ds@873
|
90 |
|
|
ds@873
|
91 |
/** |
|
ds@873
|
92 |
* Returns the game time based on the game tick. |
|
ds@873
|
93 |
* |
|
ds@873
|
94 |
* @return Game tick time. |
|
ds@873
|
95 |
*/ |
|
ds@873
|
96 |
native Float:GetGameTime(); |
|
ds@873
|
97 |
|
|
ds@873
|
98 |
/** |
|
ds@873
|
99 |
* Returns the game description from the mod. |
|
ds@873
|
100 |
* |
|
ds@873
|
101 |
* @param buffer Buffer to store the description. |
|
ds@873
|
102 |
* @param maxlength Maximum size of the buffer. |
|
ds@873
|
103 |
* @param original If true, retrieves the original game description, |
|
ds@873
|
104 |
* ignoring any potential hooks from plugins. |
|
ds@873
|
105 |
* @return Number of bytes written to the buffer (UTF-8 safe). |
|
ds@873
|
106 |
*/ |
|
ds@873
|
107 |
native GetGameDescription(String:buffer[], maxlength, bool:original=false); |
|
ds@873
|
108 |
|
|
ds@873
|
109 |
/** |
|
ds@873
|
110 |
* Returns the name of the game's directory. |
|
ds@873
|
111 |
* |
|
ds@873
|
112 |
* @param buffer Buffer to store the directory name. |
|
ds@873
|
113 |
* @param maxlength Maximum size of the buffer. |
|
ds@873
|
114 |
* |
|
ds@873
|
115 |
* return Number of bytes written to the buffer (UTF-8 safe). |
|
ds@873
|
116 |
*/ |
|
ds@873
|
117 |
native GetGameFolderName(String:buffer[], maxlength); |
|
ds@873
|
118 |
|
|
ds@873
|
119 |
/** |
|
ds@873
|
120 |
* Returns the current map name. |
|
ds@873
|
121 |
* |
|
ds@873
|
122 |
* @param buffer Buffer to store map name. |
|
ds@873
|
123 |
* @param maxlength Maximum length of buffer. |
|
ds@873
|
124 |
* @return Number of bytes written (UTF-8 safe). |
|
ds@873
|
125 |
*/ |
|
ds@873
|
126 |
native GetCurrentMap(String:buffer[], maxlength); |
|
ds@873
|
127 |
|
|
ds@873
|
128 |
/** |
|
ds@873
|
129 |
* Precaches a given model. |
|
ds@873
|
130 |
* |
|
ds@873
|
131 |
* @param model Name of the model to precache. |
|
ds@873
|
132 |
* @param preload If preload is true the file will be precached before level startup. |
|
ds@892
|
133 |
* @return Returns the model index, 0 for error. |
|
ds@873
|
134 |
*/ |
|
ds@873
|
135 |
native PrecacheModel(const String:model[], bool:preload=false); |
|
ds@873
|
136 |
|
|
ds@873
|
137 |
/** |
|
ds@873
|
138 |
* Precaches a given sentence file. |
|
ds@873
|
139 |
* |
|
ds@873
|
140 |
* @param file Name of the sentence file to precache. |
|
ds@873
|
141 |
* @param preload If preload is true the file will be precached before level startup. |
|
ds@892
|
142 |
* @return Returns a sentence file index. |
|
ds@873
|
143 |
*/ |
|
ds@873
|
144 |
native PrecacheSentenceFile(const String:file[], bool:preload=false); |
|
ds@873
|
145 |
|
|
ds@873
|
146 |
/** |
|
ds@873
|
147 |
* Precaches a given decal. |
|
ds@873
|
148 |
* |
|
ds@873
|
149 |
* @param decal Name of the decal to precache. |
|
ds@873
|
150 |
* @param preload If preload is true the file will be precached before level startup. |
|
ds@892
|
151 |
* @return Returns a decal index. |
|
ds@873
|
152 |
*/ |
|
ds@873
|
153 |
native PrecacheDecal(const String:decal[], bool:preload=false); |
|
ds@873
|
154 |
|
|
ds@873
|
155 |
/** |
|
ds@873
|
156 |
* Precaches a given generic file. |
|
ds@873
|
157 |
* |
|
ds@873
|
158 |
* @param generic Name of the generic file to precache. |
|
ds@873
|
159 |
* @param preload If preload is true the file will be precached before level startup. |
|
ds@892
|
160 |
* @return Returns a generic file index. |
|
ds@873
|
161 |
*/ |
|
ds@873
|
162 |
native PrecacheGeneric(const String:generic[], bool:preload=false); |
|
ds@873
|
163 |
|
|
ds@873
|
164 |
/** |
|
ds@873
|
165 |
* Returns if a given model is precached. |
|
ds@873
|
166 |
* |
|
ds@873
|
167 |
* @param model Name of the model to check. |
|
ds@892
|
168 |
* @return True if precached, false otherwise. |
|
ds@873
|
169 |
*/ |
|
ds@873
|
170 |
native bool:IsModelPrecached(const String:model[]); |
|
ds@873
|
171 |
|
|
ds@873
|
172 |
/** |
|
ds@873
|
173 |
* Returns if a given decal is precached. |
|
ds@873
|
174 |
* |
|
ds@873
|
175 |
* @param decal Name of the decal to check. |
|
ds@892
|
176 |
* @return True if precached, false otherwise. |
|
ds@873
|
177 |
*/ |
|
ds@873
|
178 |
native bool:IsDecalPrecached(const String:decal[]); |
|
ds@873
|
179 |
|
|
ds@873
|
180 |
/** |
|
ds@873
|
181 |
* Returns if a given generic file is precached. |
|
ds@873
|
182 |
* |
|
ds@873
|
183 |
* @param decal Name of the generic file to check. |
|
ds@892
|
184 |
* @return True if precached, false otherwise. |
|
ds@873
|
185 |
*/ |
|
ds@873
|
186 |
native bool:IsGenericPrecached(const String:generic[]); |
|
ds@873
|
187 |
|
|
ds@873
|
188 |
/** |
|
ds@873
|
189 |
* Precaches a given sound. |
|
ds@873
|
190 |
* |
|
ds@873
|
191 |
* @param sound Name of the sound to precache. |
|
ds@873
|
192 |
* @param preload If preload is true the file will be precached before level startup. |
|
ds@892
|
193 |
* @return True if successfully precached, false otherwise. |
|
ds@873
|
194 |
*/ |
|
ds@873
|
195 |
native bool:PrecacheSound(const String:sound[], bool:preload=false); |
|
ds@873
|
196 |
|
|
ds@873
|
197 |
/** |
|
ds@873
|
198 |
* Returns if a given sound is precached. |
|
ds@873
|
199 |
* |
|
ds@873
|
200 |
* @param sound Name of the sound to check. |
|
ds@892
|
201 |
* @return True if precached, false otherwise. |
|
ds@873
|
202 |
*/ |
|
ds@873
|
203 |
native bool:IsSoundPrecached(const String:sound[]); |
|
ds@873
|
204 |
|
|
ds@873
|
205 |
/** |
|
ds@873
|
206 |
* Creates different types of ingame messages. |
|
ds@873
|
207 |
* |
|
ds@873
|
208 |
* @param client Index of the client. |
|
ds@873
|
209 |
* @param kv KeyValues handle to set the menu keys and options. (Check iserverplugin.h for more information). |
|
ds@873
|
210 |
* @param type Message type to display ingame. |
|
ds@873
|
211 |
* @noreturn |
|
ds@873
|
212 |
* @error Invalid client index, or client not connected. |
|
ds@873
|
213 |
*/ |
|
ds@873
|
214 |
native CreateDialog(client, Handle:kv, DialogType:type); |
|
ds@873
|
215 |
|
|
ds@873
|
216 |
/** |
|
ds@892
|
217 |
* Prints a message to a specific client in the chat area. |
|
ds@873
|
218 |
* |
|
ds@892
|
219 |
* @param client Client index. |
|
ds@873
|
220 |
* @param format Formatting rules. |
|
ds@873
|
221 |
* @param ... Variable number of format parameters. |
|
ds@873
|
222 |
* @noreturn |
|
ds@873
|
223 |
* @error If the client is not connected an error will be thrown. |
|
ds@873
|
224 |
*/ |
|
ds@873
|
225 |
native PrintToChat(client, const String:format[], any:...); |
|
ds@873
|
226 |
|
|
ds@873
|
227 |
/** |
|
ds@892
|
228 |
* Prints a message to all clients in the chat area. |
|
ds@873
|
229 |
* |
|
ds@892
|
230 |
* @param format Formatting rules. |
|
ds@892
|
231 |
* @param ... Variable number of format parameters. |
|
ds@892
|
232 |
* @noreturn |
|
ds@892
|
233 |
*/ |
|
ds@892
|
234 |
stock PrintToChatAll(const String:format[], any:...) |
|
ds@892
|
235 |
{ |
|
ds@915
|
236 |
new maxClients = GetMaxClients(); |
|
ds@898
|
237 |
decl String:buffer[192]; |
|
ds@892
|
238 |
|
|
ds@915
|
239 |
for (new i = 1; i <= maxClients; i++) |
|
ds@892
|
240 |
{ |
|
ds@892
|
241 |
if (IsClientInGame(i)) |
|
ds@892
|
242 |
{ |
|
dvander@1034
|
243 |
SetGlobalTransTarget(i); |
|
dvander@1034
|
244 |
VFormat(buffer, sizeof(buffer), format, 2); |
|
ds@892
|
245 |
PrintToChat(i, "%s", buffer); |
|
ds@892
|
246 |
} |
|
ds@892
|
247 |
} |
|
ds@892
|
248 |
} |
|
ds@892
|
249 |
|
|
ds@892
|
250 |
/** |
|
ds@892
|
251 |
* Prints a message to a specific client in the center of the screen. |
|
ds@892
|
252 |
* |
|
ds@892
|
253 |
* @param client Client index. |
|
ds@873
|
254 |
* @param format Formatting rules. |
|
ds@873
|
255 |
* @param ... Variable number of format parameters. |
|
ds@873
|
256 |
* @noreturn |
|
ds@873
|
257 |
* @error If the client is not connected an error will be thrown. |
|
ds@873
|
258 |
*/ |
|
ds@873
|
259 |
native PrintCenterText(client, const String:format[], any:...); |
|
ds@892
|
260 |
|
|
ds@892
|
261 |
/** |
|
ds@892
|
262 |
* Prints a message to all clients in the center of the screen. |
|
ds@892
|
263 |
* |
|
ds@892
|
264 |
* @param format Formatting rules. |
|
ds@892
|
265 |
* @param ... Variable number of format parameters. |
|
ds@892
|
266 |
* @noreturn |
|
ds@892
|
267 |
*/ |
|
ds@892
|
268 |
stock PrintCenterTextAll(const String:format[], any:...) |
|
ds@892
|
269 |
{ |
|
ds@915
|
270 |
new maxClients = GetMaxClients(); |
|
ds@898
|
271 |
decl String:buffer[192]; |
|
teame06@1217
|
272 |
|
|
ds@915
|
273 |
for (new i = 1; i <= maxClients; i++) |
|
ds@892
|
274 |
{ |
|
ds@892
|
275 |
if (IsClientInGame(i)) |
|
ds@892
|
276 |
{ |
|
teame06@1217
|
277 |
SetGlobalTransTarget(i); |
|
teame06@1217
|
278 |
VFormat(buffer, sizeof(buffer), format, 2); |
|
ds@892
|
279 |
PrintCenterText(i, "%s", buffer); |
|
ds@892
|
280 |
} |
|
ds@892
|
281 |
} |
|
ds@892
|
282 |
} |
|
faluco@1218
|
283 |
|
|
faluco@1218
|
284 |
/** |
|
faluco@1218
|
285 |
* Prints a message to a specific client with a hint box. |
|
faluco@1218
|
286 |
* |
|
faluco@1218
|
287 |
* @param client Client index. |
|
faluco@1218
|
288 |
* @param format Formatting rules. |
|
faluco@1218
|
289 |
* @param ... Variable number of format parameters. |
|
faluco@1218
|
290 |
* @noreturn |
|
faluco@1218
|
291 |
* @error If the client is not connected an error will be thrown. |
|
faluco@1218
|
292 |
*/ |
|
faluco@1218
|
293 |
native PrintHintText(client, const String:format[], any:...); |
|
faluco@1218
|
294 |
|
|
faluco@1218
|
295 |
/** |
|
faluco@1218
|
296 |
* Prints a message to all clients with a hint box. |
|
faluco@1218
|
297 |
* |
|
faluco@1218
|
298 |
* @param format Formatting rules. |
|
faluco@1218
|
299 |
* @param ... Variable number of format parameters. |
|
faluco@1218
|
300 |
* @noreturn |
|
faluco@1218
|
301 |
*/ |
|
faluco@1218
|
302 |
stock PrintHintTextToAll(const String:format[], any:...) |
|
faluco@1218
|
303 |
{ |
|
faluco@1218
|
304 |
new maxClients = GetMaxClients(); |
|
faluco@1218
|
305 |
decl String:buffer[192]; |
|
faluco@1218
|
306 |
|
|
faluco@1218
|
307 |
for (new i = 1; i <= maxClients; i++) |
|
faluco@1218
|
308 |
{ |
|
faluco@1218
|
309 |
if (IsClientInGame(i)) |
|
faluco@1218
|
310 |
{ |
|
faluco@1218
|
311 |
SetGlobalTransTarget(i); |
|
faluco@1218
|
312 |
VFormat(buffer, sizeof(buffer), format, 2); |
|
faluco@1218
|
313 |
PrintHintText(i, "%s", buffer); |
|
faluco@1218
|
314 |
} |
|
faluco@1218
|
315 |
} |
|
faluco@1218
|
316 |
} |
|
faluco@1218
|
317 |
|
|
faluco@1218
|
318 |
/** |
|
faluco@1218
|
319 |
* Shows a VGUI panel to a specific client. |
|
faluco@1218
|
320 |
* |
|
faluco@1218
|
321 |
* @param client Client index. |
|
faluco@1218
|
322 |
* @param name Panel type name (Check viewport_panel_names.h to see a list of some panel names). |
|
faluco@1218
|
323 |
* @param Kv KeyValues handle with all the data for the panel setup (Depends on the panel type and may be unused). |
|
faluco@1218
|
324 |
* @param show True to show the panel, or false to remove it from the client screen. |
|
faluco@1218
|
325 |
* @noreturn |
|
faluco@1218
|
326 |
* @error If the client is not connected an error will be thrown. |
|
faluco@1218
|
327 |
*/ |
|
faluco@1218
|
328 |
native ShowVGUIPanel(client, const String:name[], Handle:Kv=INVALID_HANDLE, bool:show=true); |
|
faluco@1218
|
329 |
|
|
faluco@1218
|
330 |
/** |
|
faluco@1218
|
331 |
* Shows a MOTD panel to a specific client. |
|
faluco@1218
|
332 |
* |
|
faluco@1218
|
333 |
* @param client Client index. |
|
faluco@1218
|
334 |
* @param title Title of the panel (printed on the top border of the window). |
|
faluco@1218
|
335 |
* @param msg Contents of the panel, it can be treated as an url, filename or plain text |
|
faluco@1218
|
336 |
* depending on the type parameter (WARNING: msg has to be 192 bytes maximum!) |
|
faluco@1218
|
337 |
* @param type Determines the way to treat the message body of the panel. |
|
faluco@1218
|
338 |
* @noreturn |
|
faluco@1218
|
339 |
* @error If the client is not connected an error will be thrown. |
|
faluco@1218
|
340 |
*/ |
|
faluco@1218
|
341 |
stock ShowMOTDPanel(client, const String:title[], const String:msg[], type=MOTDPANEL_TYPE_INDEX) |
|
faluco@1218
|
342 |
{ |
|
faluco@1218
|
343 |
decl String:num[3]; |
|
faluco@1218
|
344 |
new Handle:Kv = CreateKeyValues("data"); |
|
faluco@1218
|
345 |
IntToString(type, num, sizeof(num)); |
|
faluco@1218
|
346 |
|
|
faluco@1218
|
347 |
KvSetString(Kv, "title", title); |
|
faluco@1218
|
348 |
KvSetString(Kv, "type", num); |
|
faluco@1218
|
349 |
KvSetString(Kv, "msg", msg); |
|
faluco@1218
|
350 |
ShowVGUIPanel(client, "info", Kv); |
|
faluco@1218
|
351 |
CloseHandle(Kv); |
|
faluco@1218
|
352 |
} |