plugins/include/sourcemod.inc
author Phong Dang <teame06@gmail.com>
Wed Aug 01 18:22:53 2007 +0000 (2007-08-01)
changeset 1245 bb0611ab4bed
parent 1221 f2dc55c0ab6f
child 1268 9360f5ea2289
permissions -rw-r--r--
Updated license header.
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>
dvander@1069
    35
#include <vector>
ds@873
    36
#include <string>
dvander@429
    37
#include <handles>
dvander@601
    38
#include <functions>
ds@873
    39
#include <files>
dvander@643
    40
#include <timers>
ds@873
    41
#include <admin>
dvander@868
    42
#include <dbi>
ds@913
    43
#include <lang>
ds@873
    44
#include <sorting>
ds@913
    45
#include <textparse>
ds@873
    46
#include <clients>
ds@873
    47
#include <console>
ds@873
    48
#include <events>
ds@873
    49
#include <bitbuffer>
ds@873
    50
#include <usermessages>
ds@913
    51
#include <keyvalues>
ds@873
    52
#include <menus>
ds@898
    53
#include <halflife>
dvander@1156
    54
#include <adt>
ds@898
    55
dvander@429
    56
/**
dvander@429
    57
 * Declare this as a struct in your plugin to expose its information.
dvander@429
    58
 * Example:
dvander@429
    59
 *
dvander@429
    60
 * public Plugin:myinfo =
dvander@429
    61
 * {
dvander@429
    62
 *    name = "My Plugin",
dvander@429
    63
 *    //etc
dvander@429
    64
 * };
dvander@429
    65
 */
dvander@429
    66
public Plugin:myinfo;
dvander@429
    67
 
dvander@429
    68
/**
dvander@429
    69
 * Called when the plugin is fully initialized and all known external references are resolved.
dvander@429
    70
 * This is called even if the plugin type is "private."
dvander@619
    71
 * @note Errors in this function will cause the plugin to stop running.
dvander@429
    72
 *
dvander@429
    73
 * @noreturn
dvander@429
    74
 */
dvander@536
    75
forward OnPluginStart();
dvander@429
    76
 
dvander@429
    77
/**
dvander@979
    78
 * Called before OnPluginStart, in case the plugin wants to check for load failure.
dvander@429
    79
 * This is called even if the plugin type is "private."  Any natives from modules are 
dvander@429
    80
 * not available at this point.  Thus, this forward should only be used for explicit 
dvander@429
    81
 * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
dvander@429
    82
 * 
dvander@619
    83
 * @note It is not safe to call externally resolved natives until OnPluginStart().
dvander@619
    84
 * @note Any sort of RTE in this function will cause the plugin to fail loading.
dvander@429
    85
 *
dvander@429
    86
 * @param myself	Handle to the plugin.
dvander@429
    87
 * @param late		Whether or not the plugin was loaded "late" (after map load).
dvander@429
    88
 * @param error		Error message buffer in case load failed.
dvander@429
    89
 * @param err_max	Maximum number of characters for error message buffer.
dvander@429
    90
 * @return			True if load success, false otherwise.
dvander@429
    91
 */
dvander@429
    92
forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
dvander@429
    93
dvander@429
    94
/**
dvander@429
    95
 * Called when the plugin is about to be unloaded.
dvander@429
    96
 *
dvander@429
    97
 * @noreturn
dvander@429
    98
 */
dvander@429
    99
forward OnPluginEnd();
dvander@429
   100
dvander@429
   101
/**
dvander@429
   102
 * Called when the plugin's pause status is changing.
dvander@429
   103
 *
ds@475
   104
 * @param pause			True if the plugin is being paused, false otherwise.
dvander@429
   105
 * @noreturn
dvander@429
   106
 */
dvander@429
   107
forward OnPluginPauseChange(bool:pause);
dvander@429
   108
dvander@429
   109
/**
dvander@531
   110
 * Called before every server frame.  Note that you should avoid
dvander@531
   111
 * doing expensive computations here, and you should declare large
dvander@531
   112
 * local arrays using 'decl' instead of 'new'.
dvander@531
   113
 */
dvander@531
   114
forward OnGameFrame();
dvander@531
   115
dvander@531
   116
/**
dvander@717
   117
 * Called when the map is loaded.
dvander@717
   118
 *
dvander@723
   119
 * @note This used to be OnServerLoad(), which is now deprecated.
dvander@717
   120
 * Plugins still using the old forward will work.
dvander@643
   121
 */
dvander@717
   122
forward OnMapStart();
dvander@643
   123
dvander@643
   124
/**
dvander@718
   125
 * Called right before a map ends.
dvander@718
   126
 */
dvander@718
   127
forward OnMapEnd();
dvander@718
   128
dvander@718
   129
/**
dvander@978
   130
 * Called when the map has loaded, servercfgfile (server.cfg) has been 
dvander@978
   131
 * executed, and all plugin configs are done executing.  This is the best
dvander@978
   132
 * place to inialize plugin functions which are based on cvar data.  
dvander@723
   133
 *
dvander@978
   134
 * @note This will always be called once and only once per map.  It will be 
dvander@978
   135
 * called after OnMapStart().
dvander@978
   136
 *
dvander@978
   137
 * @noreturn
dvander@723
   138
 */
dvander@978
   139
forward OnConfigsExecuted();
dvander@723
   140
dvander@723
   141
/**
dvander@979
   142
 * @deprecated Use OnConfigsExecuted() instead.
dvander@979
   143
 */
dvander@979
   144
forward OnServerCfg();
dvander@979
   145
dvander@979
   146
/**
faluco@1221
   147
 * Called after all plugins have been loaded.
faluco@1221
   148
 */
faluco@1221
   149
forward OnAllPluginsLoaded();
faluco@1221
   150
faluco@1221
   151
/**
dvander@536
   152
 * Returns the calling plugin's Handle.
dvander@536
   153
 *
dvander@536
   154
 * @return				Handle of the calling plugin.
dvander@536
   155
 */
dvander@536
   156
native Handle:GetMyHandle();
dvander@536
   157
dvander@618
   158
/**
dvander@618
   159
 * Returns an iterator that can be used to search through plugins.
dvander@618
   160
 *
dvander@618
   161
 * @return				Handle to iterate with.  Must be closed via 
dvander@618
   162
 * 						CloseHandle().
dvander@618
   163
 * @error				Invalid Handle.
dvander@618
   164
 */
dvander@618
   165
native Handle:GetPluginIterator();
dvander@618
   166
dvander@618
   167
/**
dvander@618
   168
 * Returns whether there are more plugins available in the iterator.
dvander@618
   169
 *
dvander@618
   170
 * @param iter			Handle to the plugin iterator.
dvander@618
   171
 * @return				True on more plugins, false otherwise.
dvander@618
   172
 * @error				Invalid Handle.
dvander@618
   173
 */
dvander@618
   174
native bool:MorePlugins(Handle:iter);
dvander@618
   175
dvander@618
   176
/**
dvander@618
   177
 * Returns the current plugin in the iterator and advances the iterator.
dvander@618
   178
 *
dvander@618
   179
 * @param iter			Handle to the plugin iterator.
dvander@618
   180
 * @return				Current plugin the iterator is at, before
dvander@618
   181
 *						the iterator is advanced.
dvander@618
   182
 * @error				Invalid Handle.
dvander@618
   183
 */
dvander@618
   184
native Handle:ReadPlugin(Handle:iter);
dvander@618
   185
dvander@618
   186
/**
dvander@618
   187
 * Returns a plugin's status.
dvander@618
   188
 *
dvander@618
   189
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   190
 * @return				Status code for the plugin.
dvander@618
   191
 * @error				Invalid Handle.
dvander@618
   192
 */
dvander@618
   193
native PluginStatus:GetPluginStatus(Handle:plugin);
dvander@618
   194
dvander@618
   195
/**
dvander@618
   196
 * Retrieves a plugin's file name relative to the plugins folder.
dvander@618
   197
 *
dvander@618
   198
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   199
 * @param buffer		Buffer to the store the file name.
dvander@618
   200
 * @param maxlength		Maximum length of the name buffer.
dvander@618
   201
 * @noreturn
dvander@618
   202
 * @error				Invalid Handle.
dvander@618
   203
 */
dvander@618
   204
native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
dvander@618
   205
dvander@618
   206
/**
dvander@618
   207
 * Retrieves whether or not a plugin is being debugged.
dvander@618
   208
 *
dvander@618
   209
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   210
 * @return				True if being debugged, false otherwise.
dvander@618
   211
 * @error				Invalid Handle.
dvander@618
   212
 */
dvander@618
   213
native bool:IsPluginDebugging(Handle:hndl);
dvander@618
   214
dvander@618
   215
/**
dvander@618
   216
 * Retrieves a plugin's public info.
dvander@618
   217
 *
dvander@618
   218
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   219
 * @param info			Plugin info property to retrieve.
dvander@618
   220
 * @param buffer		Buffer to store info in.
dvander@618
   221
 * @param maxlength		Maximum length of buffer.
dvander@618
   222
 * @return				True on success, false if property is not available.
dvander@618
   223
 * @error				Invalid Handle.
dvander@618
   224
 */
dvander@618
   225
native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
dvander@560
   226
dvander@560
   227
/**
dvander@837
   228
 * Causes the plugin to enter a failed state.  An error will be thrown and
dvander@837
   229
 * the plugin will be paused until it is unloaded or reloaded.
dvander@837
   230
 *
dvander@837
   231
 * @param string		Message to print.
dvander@837
   232
 * @noreturn
dvander@838
   233
 * @error				Always throws SP_ERROR_ABORT.
dvander@837
   234
 */
dvander@837
   235
native SetFailState(const String:string[]);
dvander@837
   236
dvander@837
   237
/**
dvander@560
   238
 * Aborts the current callback and throws an error.  This function
dvander@560
   239
 * does not return in that no code is executed following it.
dvander@560
   240
 *
dvander@560
   241
 * @param format		String format.
dvander@560
   242
 * @param ...			Format arguments.
dvander@560
   243
 * @noreturn
dvander@560
   244
 * @error				Always!
dvander@560
   245
 */
ds@634
   246
native ThrowError(const String:fmt[], any:...);
dvander@560
   247
dvander@536
   248
/**
dvander@429
   249
 * Logs a plugin message to the SourceMod logs.
dvander@429
   250
 *
ds@475
   251
 * @param format		String format.
ds@475
   252
 * @param ...			Format arguments.
dvander@429
   253
 * @noreturn
dvander@429
   254
 */
ds@634
   255
native LogMessage(const String:format[], any:...);
dvander@429
   256
dvander@429
   257
/**
dvander@429
   258
 * Logs a plugin error message to the SourceMod logs.
dvander@429
   259
 *
ds@475
   260
 * @param format		String format.
ds@475
   261
 * @param ...			Format arguments.
dvander@429
   262
 * @noreturn
dvander@429
   263
 */
ds@634
   264
native LogError(const String:format[], any:...);
dvander@460
   265
dvander@530
   266
/**
dvander@595
   267
 * Gets the system time as a unix timestamp.
dvander@595
   268
 *
dvander@595
   269
 * @param bigStamp		Optional array to store the 64bit timestamp in.
dvander@595
   270
 * @return				32bit timestamp (number of seconds since unix epoch).
dvander@595
   271
 */
dvander@595
   272
native GetTime(bigStamp[2]={0,0});
dvander@595
   273
dvander@595
   274
/**
faluco@1037
   275
 * Format date and time.
faluco@1037
   276
 *
faluco@1037
   277
 * @param buffer		Destination string buffer.
faluco@1037
   278
 * @param maxlength		Maximum length of output string buffer.
faluco@1037
   279
 * @param format		Formatting rules.
faluco@1041
   280
 * @param stamp			Optional time stamp.
faluco@1037
   281
 * @noreturn
faluco@1037
   282
 */
faluco@1041
   283
native FormatTime(String:buffer[], maxlength, const String:format[], stamp=-1);
faluco@1037
   284
faluco@1037
   285
/**
faluco@703
   286
 * Loads a game config file.
faluco@703
   287
 *
faluco@703
   288
 * @param file			File to load.  The path must be relative to the 'gamedata' folder under the config folder 
faluco@703
   289
 *					and the extension should be omitted.
faluco@703
   290
 * @return			A handle to the game config file or INVALID_HANDLE in failure.
faluco@703
   291
 */
faluco@703
   292
native Handle:LoadGameConfigFile(const String:file[]);
faluco@703
   293
faluco@703
   294
/**
faluco@703
   295
 * Returns an offset value.
faluco@703
   296
 *
faluco@703
   297
 * @param gc			Game config handle.
faluco@703
   298
 * @param key			Key to retrieve from the offset section.
faluco@703
   299
 * @return			An offset, or -1 on failure.
faluco@703
   300
 */
faluco@703
   301
native GameConfGetOffset(Handle:gc, const String:key[]);
faluco@703
   302
faluco@703
   303
/**
faluco@703
   304
 * Gets the value of a key from the "Keys" section.
faluco@703
   305
 *
faluco@703
   306
 * @param gc			Game config handle.
faluco@703
   307
 * @param key			Key to retrieve from the Keys section.
faluco@703
   308
 * @param buffer		Destination string buffer.
faluco@703
   309
 * @param maxlen		Maximum length of output string buffer.
dvander@886
   310
 * @return				True if key existed, false otherwise.
faluco@703
   311
 */
faluco@703
   312
native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
faluco@703
   313
dvander@886
   314
/**
dvander@886
   315
 * Returns the operating system's "tick count," which is a number of 
dvander@886
   316
 * milliseconds since the operating system loaded.  This can be used
dvander@886
   317
 * for basic benchmarks.
dvander@886
   318
 *
dvander@886
   319
 * @return				Tick count in milliseconds.
dvander@886
   320
 */
dvander@886
   321
native GetSysTickCount();
dvander@886
   322
dvander@978
   323
/**
dvander@978
   324
 * Specifies that the given config file should be executed after plugin load.
dvander@978
   325
 * OnConfigsExecuted() will not be called until the config file has executed, 
dvander@978
   326
 * but it will be called if the execution fails.
dvander@978
   327
 *
dvander@978
   328
 * @param autoCreate	If true, and the config file does not exist, such a config
dvander@978
   329
 *						file will be automatically created and populated with
dvander@978
   330
 *						information from the plugin's registered cvars.
dvander@978
   331
 * @param name			Name of the config file, excluding the .cfg extension.
dvander@978
   332
 *						If empty, <plugin.filename.cfg> is assumed.
dvander@978
   333
 * @param folder		Folder under cfg/ to use.  By default this is "sourcemod."
dvander@978
   334
 * @noreturn
dvander@978
   335
 */
dvander@978
   336
native AutoExecConfig(bool:autoCreate=true, const String:name[]="", const String:folder[]="sourcemod");
dvander@978
   337
faluco@1112
   338
/**
faluco@1112
   339
 * Sets a native as optional, such that if it is unloaded, removed,
faluco@1112
   340
 * or otherwise non-existent, the plugin will still work.  Calling
faluco@1112
   341
 * removed natives results in a run-time error.
faluco@1112
   342
 *
faluco@1112
   343
 * @param name			Native name.
faluco@1112
   344
 * @noreturn
faluco@1112
   345
 */
faluco@1112
   346
native MarkNativeAsOptional(const String:name[]);
faluco@1112
   347
faluco@1112
   348
/**
faluco@1112
   349
 * Registers a library name for identifying as a dependency to 
faluco@1112
   350
 * other plugins.
faluco@1112
   351
 *
faluco@1112
   352
 * @param name			Library name.
faluco@1112
   353
 * @noreturn
faluco@1112
   354
 */
faluco@1112
   355
native RegPluginLibrary(const String:name[]);
faluco@1112
   356
dvander@1124
   357
/**
dvander@1124
   358
 * Returns whether a library exists.
dvander@1124
   359
 *
dvander@1124
   360
 * @param name			Library name.
dvander@1124
   361
 * @return				True if exists, false otherwise.
dvander@1124
   362
 */
dvander@1124
   363
native bool:LibraryExists(const String:name[]);
dvander@1124
   364
dvander@1124
   365
/**
dvander@1124
   366
 * Called after a library (plugin) is added that the 
dvander@1124
   367
 * current plugin references optionally.
dvander@1124
   368
 *
dvander@1124
   369
 * @param name			Library name.
dvander@1124
   370
 */
dvander@1124
   371
forward OnLibraryAdded(const String:name[]);
dvander@1124
   372
dvander@1124
   373
/**
dvander@1124
   374
 * Called right before a library (plugin) is removed that the 
dvander@1124
   375
 * current plugin references optionally.
dvander@1124
   376
 *
dvander@1124
   377
 * @param name			Library name.
dvander@1124
   378
 */
dvander@1124
   379
forward OnLibraryRemoved(const String:name[]);
dvander@1124
   380
dvander@460
   381
#include <helpers>
dvander@560
   382
#include <entity>