plugins/include/sourcemod.inc
author David Anderson <dvander@alliedmods.net>
Mon Jun 18 07:09:47 2007 +0000 (2007-06-18)
changeset 979 083adc349611
parent 978 54782a83a1ef
child 1037 86af3790fcb7
permissions -rw-r--r--
added deprecation warning
dvander@429
     1
/**
ds@475
     2
 * vim: set ts=4 :
dvander@429
     3
 * ===============================================================
dvander@429
     4
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
dvander@429
     5
 * ===============================================================
dvander@429
     6
 *
dvander@429
     7
 *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be used 
dvander@429
     8
 * or modified under the Terms and Conditions of its License Agreement, which is found 
dvander@429
     9
 * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
dvander@429
    10
 * may change at any time.  To view the latest information, see:
dvander@429
    11
 *   http://www.sourcemod.net/license.php
dvander@429
    12
 *
faluco@506
    13
 * Version: $Id$
dvander@429
    14
 */
dvander@429
    15
dvander@429
    16
#if defined _sourcemod_included
dvander@429
    17
 #endinput
dvander@429
    18
#endif
dvander@429
    19
#define _sourcemod_included
dvander@429
    20
dvander@619
    21
/**
dvander@619
    22
 * Plugin public information.
dvander@619
    23
 */
dvander@429
    24
struct Plugin
dvander@429
    25
{
dvander@619
    26
   const String:name[],			/**< Plugin Name */
dvander@619
    27
   const String:description[],	/**< Plugin Description */
dvander@619
    28
   const String:author[],		/**< Plugin Author */
dvander@619
    29
   const String:version[],		/**< Plugin Version */
dvander@619
    30
   const String:url[],			/**< Plugin URL */
dvander@429
    31
};
dvander@429
    32
dvander@429
    33
#include <core>
dvander@429
    34
#include <float>
ds@873
    35
#include <string>
dvander@429
    36
#include <handles>
dvander@601
    37
#include <functions>
ds@873
    38
#include <files>
dvander@643
    39
#include <timers>
ds@873
    40
#include <admin>
dvander@868
    41
#include <dbi>
ds@913
    42
#include <lang>
ds@873
    43
#include <sorting>
ds@913
    44
#include <textparse>
ds@873
    45
#include <clients>
ds@873
    46
#include <console>
ds@873
    47
#include <events>
ds@873
    48
#include <bitbuffer>
ds@873
    49
#include <usermessages>
ds@913
    50
#include <keyvalues>
ds@873
    51
#include <menus>
ds@898
    52
#include <halflife>
ds@898
    53
dvander@429
    54
/**
dvander@429
    55
 * Declare this as a struct in your plugin to expose its information.
dvander@429
    56
 * Example:
dvander@429
    57
 *
dvander@429
    58
 * public Plugin:myinfo =
dvander@429
    59
 * {
dvander@429
    60
 *    name = "My Plugin",
dvander@429
    61
 *    //etc
dvander@429
    62
 * };
dvander@429
    63
 */
dvander@429
    64
public Plugin:myinfo;
dvander@429
    65
 
dvander@429
    66
/**
dvander@429
    67
 * Called when the plugin is fully initialized and all known external references are resolved.
dvander@429
    68
 * This is called even if the plugin type is "private."
dvander@619
    69
 * @note Errors in this function will cause the plugin to stop running.
dvander@429
    70
 *
dvander@429
    71
 * @noreturn
dvander@429
    72
 */
dvander@536
    73
forward OnPluginStart();
dvander@429
    74
 
dvander@429
    75
/**
dvander@979
    76
 * Called before OnPluginStart, in case the plugin wants to check for load failure.
dvander@429
    77
 * This is called even if the plugin type is "private."  Any natives from modules are 
dvander@429
    78
 * not available at this point.  Thus, this forward should only be used for explicit 
dvander@429
    79
 * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
dvander@429
    80
 * 
dvander@619
    81
 * @note It is not safe to call externally resolved natives until OnPluginStart().
dvander@619
    82
 * @note Any sort of RTE in this function will cause the plugin to fail loading.
dvander@429
    83
 *
dvander@429
    84
 * @param myself	Handle to the plugin.
dvander@429
    85
 * @param late		Whether or not the plugin was loaded "late" (after map load).
dvander@429
    86
 * @param error		Error message buffer in case load failed.
dvander@429
    87
 * @param err_max	Maximum number of characters for error message buffer.
dvander@429
    88
 * @return			True if load success, false otherwise.
dvander@429
    89
 */
dvander@429
    90
forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
dvander@429
    91
dvander@429
    92
/**
dvander@429
    93
 * Called when the plugin is about to be unloaded.
dvander@429
    94
 *
dvander@429
    95
 * @noreturn
dvander@429
    96
 */
dvander@429
    97
forward OnPluginEnd();
dvander@429
    98
dvander@429
    99
/**
dvander@429
   100
 * Called when the plugin's pause status is changing.
dvander@429
   101
 *
ds@475
   102
 * @param pause			True if the plugin is being paused, false otherwise.
dvander@429
   103
 * @noreturn
dvander@429
   104
 */
dvander@429
   105
forward OnPluginPauseChange(bool:pause);
dvander@429
   106
dvander@429
   107
/**
dvander@531
   108
 * Called before every server frame.  Note that you should avoid
dvander@531
   109
 * doing expensive computations here, and you should declare large
dvander@531
   110
 * local arrays using 'decl' instead of 'new'.
dvander@531
   111
 */
dvander@531
   112
forward OnGameFrame();
dvander@531
   113
dvander@531
   114
/**
dvander@717
   115
 * Called when the map is loaded.
dvander@717
   116
 *
dvander@723
   117
 * @note This used to be OnServerLoad(), which is now deprecated.
dvander@717
   118
 * Plugins still using the old forward will work.
dvander@643
   119
 */
dvander@717
   120
forward OnMapStart();
dvander@643
   121
dvander@643
   122
/**
dvander@718
   123
 * Called right before a map ends.
dvander@718
   124
 */
dvander@718
   125
forward OnMapEnd();
dvander@718
   126
dvander@718
   127
/**
dvander@978
   128
 * Called when the map has loaded, servercfgfile (server.cfg) has been 
dvander@978
   129
 * executed, and all plugin configs are done executing.  This is the best
dvander@978
   130
 * place to inialize plugin functions which are based on cvar data.  
dvander@723
   131
 *
dvander@978
   132
 * @note This will always be called once and only once per map.  It will be 
dvander@978
   133
 * called after OnMapStart().
dvander@978
   134
 *
dvander@978
   135
 * @noreturn
dvander@723
   136
 */
dvander@978
   137
forward OnConfigsExecuted();
dvander@723
   138
dvander@723
   139
/**
dvander@979
   140
 * @deprecated Use OnConfigsExecuted() instead.
dvander@979
   141
 */
dvander@979
   142
forward OnServerCfg();
dvander@979
   143
dvander@979
   144
/**
dvander@536
   145
 * Returns the calling plugin's Handle.
dvander@536
   146
 *
dvander@536
   147
 * @return				Handle of the calling plugin.
dvander@536
   148
 */
dvander@536
   149
native Handle:GetMyHandle();
dvander@536
   150
dvander@618
   151
/**
dvander@618
   152
 * Returns an iterator that can be used to search through plugins.
dvander@618
   153
 *
dvander@618
   154
 * @return				Handle to iterate with.  Must be closed via 
dvander@618
   155
 * 						CloseHandle().
dvander@618
   156
 * @error				Invalid Handle.
dvander@618
   157
 */
dvander@618
   158
native Handle:GetPluginIterator();
dvander@618
   159
dvander@618
   160
/**
dvander@618
   161
 * Returns whether there are more plugins available in the iterator.
dvander@618
   162
 *
dvander@618
   163
 * @param iter			Handle to the plugin iterator.
dvander@618
   164
 * @return				True on more plugins, false otherwise.
dvander@618
   165
 * @error				Invalid Handle.
dvander@618
   166
 */
dvander@618
   167
native bool:MorePlugins(Handle:iter);
dvander@618
   168
dvander@618
   169
/**
dvander@618
   170
 * Returns the current plugin in the iterator and advances the iterator.
dvander@618
   171
 *
dvander@618
   172
 * @param iter			Handle to the plugin iterator.
dvander@618
   173
 * @return				Current plugin the iterator is at, before
dvander@618
   174
 *						the iterator is advanced.
dvander@618
   175
 * @error				Invalid Handle.
dvander@618
   176
 */
dvander@618
   177
native Handle:ReadPlugin(Handle:iter);
dvander@618
   178
dvander@618
   179
/**
dvander@618
   180
 * Returns a plugin's status.
dvander@618
   181
 *
dvander@618
   182
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   183
 * @return				Status code for the plugin.
dvander@618
   184
 * @error				Invalid Handle.
dvander@618
   185
 */
dvander@618
   186
native PluginStatus:GetPluginStatus(Handle:plugin);
dvander@618
   187
dvander@618
   188
/**
dvander@618
   189
 * Retrieves a plugin's file name relative to the plugins folder.
dvander@618
   190
 *
dvander@618
   191
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   192
 * @param buffer		Buffer to the store the file name.
dvander@618
   193
 * @param maxlength		Maximum length of the name buffer.
dvander@618
   194
 * @noreturn
dvander@618
   195
 * @error				Invalid Handle.
dvander@618
   196
 */
dvander@618
   197
native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
dvander@618
   198
dvander@618
   199
/**
dvander@618
   200
 * Retrieves whether or not a plugin is being debugged.
dvander@618
   201
 *
dvander@618
   202
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   203
 * @return				True if being debugged, false otherwise.
dvander@618
   204
 * @error				Invalid Handle.
dvander@618
   205
 */
dvander@618
   206
native bool:IsPluginDebugging(Handle:hndl);
dvander@618
   207
dvander@618
   208
/**
dvander@618
   209
 * Retrieves a plugin's public info.
dvander@618
   210
 *
dvander@618
   211
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   212
 * @param info			Plugin info property to retrieve.
dvander@618
   213
 * @param buffer		Buffer to store info in.
dvander@618
   214
 * @param maxlength		Maximum length of buffer.
dvander@618
   215
 * @return				True on success, false if property is not available.
dvander@618
   216
 * @error				Invalid Handle.
dvander@618
   217
 */
dvander@618
   218
native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
dvander@560
   219
dvander@560
   220
/**
dvander@837
   221
 * Causes the plugin to enter a failed state.  An error will be thrown and
dvander@837
   222
 * the plugin will be paused until it is unloaded or reloaded.
dvander@837
   223
 *
dvander@837
   224
 * @param string		Message to print.
dvander@837
   225
 * @noreturn
dvander@838
   226
 * @error				Always throws SP_ERROR_ABORT.
dvander@837
   227
 */
dvander@837
   228
native SetFailState(const String:string[]);
dvander@837
   229
dvander@837
   230
/**
dvander@560
   231
 * Aborts the current callback and throws an error.  This function
dvander@560
   232
 * does not return in that no code is executed following it.
dvander@560
   233
 *
dvander@560
   234
 * @param format		String format.
dvander@560
   235
 * @param ...			Format arguments.
dvander@560
   236
 * @noreturn
dvander@560
   237
 * @error				Always!
dvander@560
   238
 */
ds@634
   239
native ThrowError(const String:fmt[], any:...);
dvander@560
   240
dvander@536
   241
/**
dvander@429
   242
 * Logs a plugin message to the SourceMod logs.
dvander@429
   243
 *
ds@475
   244
 * @param format		String format.
ds@475
   245
 * @param ...			Format arguments.
dvander@429
   246
 * @noreturn
dvander@429
   247
 */
ds@634
   248
native LogMessage(const String:format[], any:...);
dvander@429
   249
dvander@429
   250
/**
dvander@429
   251
 * Logs a plugin error message to the SourceMod logs.
dvander@429
   252
 *
ds@475
   253
 * @param format		String format.
ds@475
   254
 * @param ...			Format arguments.
dvander@429
   255
 * @noreturn
dvander@429
   256
 */
ds@634
   257
native LogError(const String:format[], any:...);
dvander@460
   258
dvander@530
   259
/**
dvander@595
   260
 * Gets the system time as a unix timestamp.
dvander@595
   261
 *
dvander@595
   262
 * @param bigStamp		Optional array to store the 64bit timestamp in.
dvander@595
   263
 * @return				32bit timestamp (number of seconds since unix epoch).
dvander@595
   264
 */
dvander@595
   265
native GetTime(bigStamp[2]={0,0});
dvander@595
   266
dvander@595
   267
/**
faluco@703
   268
 * Loads a game config file.
faluco@703
   269
 *
faluco@703
   270
 * @param file			File to load.  The path must be relative to the 'gamedata' folder under the config folder 
faluco@703
   271
 *					and the extension should be omitted.
faluco@703
   272
 * @return			A handle to the game config file or INVALID_HANDLE in failure.
faluco@703
   273
 */
faluco@703
   274
native Handle:LoadGameConfigFile(const String:file[]);
faluco@703
   275
faluco@703
   276
/**
faluco@703
   277
 * Returns an offset value.
faluco@703
   278
 *
faluco@703
   279
 * @param gc			Game config handle.
faluco@703
   280
 * @param key			Key to retrieve from the offset section.
faluco@703
   281
 * @return			An offset, or -1 on failure.
faluco@703
   282
 */
faluco@703
   283
native GameConfGetOffset(Handle:gc, const String:key[]);
faluco@703
   284
faluco@703
   285
/**
faluco@703
   286
 * Gets the value of a key from the "Keys" section.
faluco@703
   287
 *
faluco@703
   288
 * @param gc			Game config handle.
faluco@703
   289
 * @param key			Key to retrieve from the Keys section.
faluco@703
   290
 * @param buffer		Destination string buffer.
faluco@703
   291
 * @param maxlen		Maximum length of output string buffer.
dvander@886
   292
 * @return				True if key existed, false otherwise.
faluco@703
   293
 */
faluco@703
   294
native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
faluco@703
   295
dvander@886
   296
/**
dvander@886
   297
 * Returns the operating system's "tick count," which is a number of 
dvander@886
   298
 * milliseconds since the operating system loaded.  This can be used
dvander@886
   299
 * for basic benchmarks.
dvander@886
   300
 *
dvander@886
   301
 * @return				Tick count in milliseconds.
dvander@886
   302
 */
dvander@886
   303
native GetSysTickCount();
dvander@886
   304
dvander@978
   305
/**
dvander@978
   306
 * Specifies that the given config file should be executed after plugin load.
dvander@978
   307
 * OnConfigsExecuted() will not be called until the config file has executed, 
dvander@978
   308
 * but it will be called if the execution fails.
dvander@978
   309
 *
dvander@978
   310
 * @param autoCreate	If true, and the config file does not exist, such a config
dvander@978
   311
 *						file will be automatically created and populated with
dvander@978
   312
 *						information from the plugin's registered cvars.
dvander@978
   313
 * @param name			Name of the config file, excluding the .cfg extension.
dvander@978
   314
 *						If empty, <plugin.filename.cfg> is assumed.
dvander@978
   315
 * @param folder		Folder under cfg/ to use.  By default this is "sourcemod."
dvander@978
   316
 * @noreturn
dvander@978
   317
 */
dvander@978
   318
native AutoExecConfig(bool:autoCreate=true, const String:name[]="", const String:folder[]="sourcemod");
dvander@978
   319
dvander@460
   320
#include <helpers>
dvander@560
   321
#include <entity>