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 _console_included
19 #define _console_included
22 * Flags for console commands and console variables
23 * @note The descriptions for each constant come directly from the Source SDK.
25 #define FCVAR_NONE 0 /**< The default, no flags at all */
26 #define FCVAR_UNREGISTERED (1<<0) /**< If this is set, don't add to linked list, etc. */
27 #define FCVAR_LAUNCHER (1<<1) /**< Defined by launcher. */
28 #define FCVAR_GAMEDLL (1<<2) /**< Defined by the game DLL. */
29 #define FCVAR_CLIENTDLL (1<<3) /**< Defined by the client DLL. */
30 #define FCVAR_MATERIAL_SYSTEM (1<<4) /**< Defined by the material system. */
31 #define FCVAR_PROTECTED (1<<5) /**< It's a server cvar, but we don't send the data since it's a password, etc. Sends 1 if it's not bland/zero, 0 otherwise as value. */
32 #define FCVAR_SPONLY (1<<6) /**< This cvar cannot be changed by clients connected to a multiplayer server. */
33 #define FCVAR_ARCHIVE (1<<7) /**< Set to cause it to be saved to vars.rc */
34 #define FCVAR_NOTIFY (1<<8) /**< Notifies players when changed. */
35 #define FCVAR_USERINFO (1<<9) /**< Changes the client's info string. */
36 #define FCVAR_PRINTABLEONLY (1<<10) /**< This cvar's string cannot contain unprintable characters (e.g., used for player name, etc.) */
37 #define FCVAR_UNLOGGED (1<<11) /**< If this is a FCVAR_SERVER, don't log changes to the log file / console if we are creating a log */
38 #define FCVAR_NEVER_AS_STRING (1<<12) /**< Never try to print that cvar. */
39 #define FCVAR_REPLICATED (1<<13) /**< Server setting enforced on clients. */
40 #define FCVAR_CHEAT (1<<14) /**< Only useable in singleplayer / debug / multiplayer & sv_cheats */
41 #define FCVAR_STUDIORENDER (1<<15) /**< Defined by the studiorender system. */
42 #define FCVAR_DEMO (1<<16) /**< Record this cvar when starting a demo file. */
43 #define FCVAR_DONTRECORD (1<<17) /**< Don't record these command in demo files. */
44 #define FCVAR_PLUGIN (1<<18) /**< Defined by a 3rd party plugin. */
45 #define FCVAR_DATACACHE (1<<19) /**< Defined by the datacache system. */
46 #define FCVAR_TOOLSYSTEM (1<<20) /**< Defined by an IToolSystem library */
47 #define FCVAR_FILESYSTEM (1<<21) /**< Defined by the file system. */
48 #define FCVAR_NOT_CONNECTED (1<<22) /**< Cvar cannot be changed by a client that is connected to a server. */
49 #define FCVAR_SOUNDSYSTEM (1<<23) /**< Defined by the soundsystem library. */
50 #define FCVAR_ARCHIVE_XBOX (1<<24) /**< Cvar written to config.cfg on the Xbox. */
51 #define FCVAR_INPUTSYSTEM (1<<25) /**< Defined by the inputsystem DLL. */
52 #define FCVAR_NETWORKSYSTEM (1<<26) /**< Defined by the network system. */
53 #define FCVAR_VPHYSICS (1<<27) /**< Defined by vphysics. */
56 * Executes a server command as if it were on the server console (or RCON)
58 * @param format Formatting rules.
59 * @param ... Variable number of format parameters.
62 native ServerCommand(const String:format[], {Handle,Float,String,_}:...);
65 * Inserts a server command at the beginning of the server command buffer.
67 * @param format Formatting rules.
68 * @param ... Variable number of format parameters.
71 native InsertServerCommand(const String:format[], {Handle,Float,String,_}:...);
74 * Executes every command in the server's command buffer, rather than once per frame.
78 native ServerExecute();
81 * Executes a client command. Note that this will not work on clients unless
82 * they have cl_restrict_server_commands set to 0.
84 * @param client Index of the client.
85 * @param fmt Format of the client command.
86 * @param ... Format parameters/
88 * @error Invalid client index, or client not connected.
90 native ClientCommand(client, const String:fmt[], {String,Float,Handle,_}:...);
93 * Sends a message to the server console.
95 * @param format Formatting rules.
96 * @param ... Variable number of format parameters.
99 native PrintToServer(const String:format[], {Handle,Float,String,_}:...);
102 * Sends a message to a client's console.
104 * @param client Player index.
105 * @param format Formatting rules.
106 * @param ... Variable number of format parameters.
108 * @error If the client is not connected an error will be thrown.
110 native PrintToConsole(client, const String:format[], {Handle,Float,String,_}:...);
113 * Called when a server-only command is invoked.
115 * @params args Number of arguments that were in the argument string.
116 * @return A Result value. Not handling the command
117 * means that Source will report it as "not found."
119 functag SrvCmd Action:public(args);
122 * Creates a server-only console command, or hooks an already existing one.
124 * @param cmd Name of the command to hook or create.
125 * @param callback A function to use as a callback for when the command is invoked.
126 * @param description Optional description to use for command creation.
127 * @param flags Optional flags to use for command creation.
129 * @error Command name is the same as an existing convar.
131 native RegServerCmd(const String:cmd[], SrvCmd:callback, const String:description[]="", flags=0);
134 * Called when a generic console command is invoked.
136 * @param client Index of the client, or 0 from the server.
137 * @param args Number of arguments that were in the argument string.
138 * @return A Result value. Not handling the command
139 * means that Source will report it as "not found."
141 functag ConCmd Action:public(client, args);
144 * Creates a console command, or hooks an already existing one.
146 * @param cmd Name of the command to hook or create.
147 * @param callback A function to use as a callback for when the command is invoked.
148 * @param description Optional description to use for command creation.
149 * @param flags Optional flags to use for command creation.
151 * @error Command name is the same as an existing convar.
153 native RegConsoleCmd(const String:cmd[], ConCmd:callback, const String:description[]="", flags=0);
156 * Creates a console command as an administrative command. If the command does not exist,
157 * it is created. When this command is invoked, the access rights of the player are
158 * automatically checked before allowing it to continue.
160 * @param cmd String containing command to register.
161 * @param callback A function to use as a callback for when the command is invoked.
162 * @param adminflags Administrative flags (bitstring) to use for permissions.
163 * @param group String containing the command group to use. If empty,
164 * the plugin's filename will be used instead.
165 * @param description Optional description to use for help.
166 * @param flags Optional console flags.
168 * @error Command name is the same as an existing convar.
170 native RegAdminCmd(const String:cmd[],
173 const String:description[]="",
174 const String:group[]="",
178 * Returns the number of arguments from the current console or server command.
179 * @note Unlike the HL2 engine call, this does not include the command itself.
181 * @return Number of arguments to the current command.
186 * Retrieves a command argument given its index, from the current console or
188 * @note Argument indexes start at 1; 0 retrieves the command name.
190 * @param argnum Argument number to retrieve.
191 * @param buffer Buffer to use for storing the string.
192 * @param maxlength Maximum length of the buffer.
195 native GetCmdArg(argnum, String:buffer[], maxlength);
198 * Retrieves the entire command argument string in one lump from the current
199 * console or server command.
201 * @param buffer Buffer to use for storing the string.
202 * @param maxlength Maximum length of the buffer.
205 native GetCmdArgString(String:buffer[], maxlength);
208 * Creates a new console variable.
210 * @param name Name of new convar.
211 * @param defaultValue String containing the default value of new convar.
212 * @param description Optional description of the convar.
213 * @param flags Optional bitstring of flags determining how the convar should be handled. See FCVAR_* constants for more details.
214 * @param hasMin Optional boolean that determines if the convar has a minimum value.
215 * @param min Minimum floating point value that the convar can have if hasMin is true.
216 * @param hasMax Optional boolean that determines if the convar has a maximum value.
217 * @param max Maximum floating point value that the convar can have if hasMax is true.
218 * @return A handle to the newly created convar. If the convar already exists, INVALID_HANDLE is returned.
219 * @error Convar name is blank or is the same as an existing console command.
221 native Handle:CreateConVar(const String:name[], const String:defaultValue[], const String:description[]="", flags=0, bool:hasMin=false, Float:min=0.0, bool:hasMax=false, Float:max=0.0);
224 * Searches for a console variable.
226 * @param name Name of convar to find.
227 * @return A handle to the convar if it is found. INVALID_HANDLE otherwise.
229 native Handle:FindConVar(const String:name[]);
232 * Called when a console variable's value is changed.
234 * @param convar Handle to the convar that was changed.
235 * @param oldValue String containing the value of the convar before it was changed.
236 * @param newValue String containing the new value of the convar.
239 functag ConVarChanged public(Handle:convar, const String:oldValue[], const String:newValue[]);
242 * Creates a hook for when a console variable's value is changed.
244 * @param convar Handle to the convar.
245 * @param callback An OnConVarChanged function pointer.
247 * @error Invalid or corrupt Handle or invalid callback function.
249 native HookConVarChange(Handle:convar, ConVarChanged:callback);
252 * Removes a hook for when a console variable's value is changed.
254 * @param convar Handle to the convar.
255 * @param callback An OnConVarChanged function pointer.
257 * @error Invalid or corrupt Handle, invalid callback function, or no active hook on convar.
259 native UnhookConVarChange(Handle:convar, ConVarChanged:callback);
262 * Returns the boolean value of a console variable.
264 * @param convar Handle to the convar.
265 * @return The boolean value of the convar.
266 * @error Invalid or corrupt Handle.
268 native bool:GetConVarBool(Handle:convar);
271 * Sets the boolean value of a console variable.
273 * @param convar Handle to the convar.
274 * @param value New boolean value.
276 * @error Invalid or corrupt Handle.
278 native SetConVarBool(Handle:convar, bool:value);
281 * Returns the integer value of a console variable.
283 * @param convar Handle to the convar.
284 * @return The integer value of the convar.
285 * @error Invalid or corrupt Handle.
287 native GetConVarInt(Handle:convar);
290 * Sets the integer value of a console variable.
292 * @param convar Handle to the convar.
293 * @param value New integer value.
295 * @error Invalid or corrupt Handle.
297 native SetConVarInt(Handle:convar, value);
300 * Returns the floating point value of a console variable.
302 * @param convar Handle to the convar.
303 * @return The floating point value of the convar.
304 * @error Invalid or corrupt Handle.
306 native Float:GetConVarFloat(Handle:convar);
309 * Sets the floating point value of a console variable.
311 * @param convar Handle to the convar.
312 * @param value New floating point value.
314 * @error Invalid or corrupt Handle.
316 native SetConVarFloat(Handle:convar, Float:value);
319 * Retrieves the string value of a console variable.
321 * @param convar Handle to the convar.
322 * @param value Buffer to store the value of the convar.
323 * @param maxlength Maximum length of string buffer.
325 * @error Invalid or corrupt Handle.
327 native GetConVarString(Handle:convar, String:value[], maxlength);
330 * Sets the string value of a console variable.
332 * @param convar Handle to the convar.
333 * @param value New string value.
335 * @error Invalid or corrupt Handle.
337 native SetConVarString(Handle:convar, const String:value[]);
340 * Returns the bitstring of flags on a console variable.
342 * @param convar Handle to the convar.
343 * @return A bitstring containing the FCVAR_* flags that are enabled.
344 * @error Invalid or corrupt Handle.
346 native GetConVarFlags(Handle:convar);
349 * Sets the bitstring of flags on a console variable.
351 * @param convar Handle to the convar.
352 * @param flags A bitstring containing the FCVAR_* flags to enable.
354 * @error Invalid or corrupt Handle.
356 native SetConVarFlags(Handle:convar, flags);
359 * Retrieves the name of a console variable.
361 * @param convar Handle to the convar.
362 * @param value Buffer to store the name of the convar.
363 * @param maxlength Maximum length of string buffer.
365 * @error Invalid or corrupt Handle.
367 native GetConVarName(Handle:convar, const String:name[], maxlength);
370 * Retrieves the minimum floating point value that a console variable can contain.
372 * @param convar Handle to the convar.
373 * @param min By-reference cell to store the minimum floating point value.
374 * @return True if the convar has a minimum value set, false otherwise.
375 * @error Invalid or corrupt Handle.
377 native bool:GetConVarMin(Handle:convar, &Float:min);
380 * Retrieves the maximum floating point value that a console variable can contain.
382 * @param convar Handle to the convar.
383 * @param min By-reference cell to store the maximum floating point value.
384 * @return True if the convar has a maximum value set, false otherwise.
385 * @error Invalid or corrupt Handle.
387 native bool:GetConVarMax(Handle:convar, &Float:max);
390 * Resets the console variable to its default value.
392 * @param convar Handle to the convar.
394 * @error Invalid or corrupt Handle.
396 native ResetConVar(Handle:convar);