plugins/include/sourcemod.inc
author David Anderson <dvander@alliedmods.net>
Tue Jul 24 01:18:28 2007 +0000 (2007-07-24)
changeset 1156 a80f4ebe389f
parent 1124 a397d51fb986
child 1221 f2dc55c0ab6f
permissions -rw-r--r--
initial import of adt array natives for amb576
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
/**
dvander@536
   147
 * Returns the calling plugin's Handle.
dvander@536
   148
 *
dvander@536
   149
 * @return				Handle of the calling plugin.
dvander@536
   150
 */
dvander@536
   151
native Handle:GetMyHandle();
dvander@536
   152
dvander@618
   153
/**
dvander@618
   154
 * Returns an iterator that can be used to search through plugins.
dvander@618
   155
 *
dvander@618
   156
 * @return				Handle to iterate with.  Must be closed via 
dvander@618
   157
 * 						CloseHandle().
dvander@618
   158
 * @error				Invalid Handle.
dvander@618
   159
 */
dvander@618
   160
native Handle:GetPluginIterator();
dvander@618
   161
dvander@618
   162
/**
dvander@618
   163
 * Returns whether there are more plugins available in the iterator.
dvander@618
   164
 *
dvander@618
   165
 * @param iter			Handle to the plugin iterator.
dvander@618
   166
 * @return				True on more plugins, false otherwise.
dvander@618
   167
 * @error				Invalid Handle.
dvander@618
   168
 */
dvander@618
   169
native bool:MorePlugins(Handle:iter);
dvander@618
   170
dvander@618
   171
/**
dvander@618
   172
 * Returns the current plugin in the iterator and advances the iterator.
dvander@618
   173
 *
dvander@618
   174
 * @param iter			Handle to the plugin iterator.
dvander@618
   175
 * @return				Current plugin the iterator is at, before
dvander@618
   176
 *						the iterator is advanced.
dvander@618
   177
 * @error				Invalid Handle.
dvander@618
   178
 */
dvander@618
   179
native Handle:ReadPlugin(Handle:iter);
dvander@618
   180
dvander@618
   181
/**
dvander@618
   182
 * Returns a plugin's status.
dvander@618
   183
 *
dvander@618
   184
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   185
 * @return				Status code for the plugin.
dvander@618
   186
 * @error				Invalid Handle.
dvander@618
   187
 */
dvander@618
   188
native PluginStatus:GetPluginStatus(Handle:plugin);
dvander@618
   189
dvander@618
   190
/**
dvander@618
   191
 * Retrieves a plugin's file name relative to the plugins folder.
dvander@618
   192
 *
dvander@618
   193
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   194
 * @param buffer		Buffer to the store the file name.
dvander@618
   195
 * @param maxlength		Maximum length of the name buffer.
dvander@618
   196
 * @noreturn
dvander@618
   197
 * @error				Invalid Handle.
dvander@618
   198
 */
dvander@618
   199
native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
dvander@618
   200
dvander@618
   201
/**
dvander@618
   202
 * Retrieves whether or not a plugin is being debugged.
dvander@618
   203
 *
dvander@618
   204
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   205
 * @return				True if being debugged, false otherwise.
dvander@618
   206
 * @error				Invalid Handle.
dvander@618
   207
 */
dvander@618
   208
native bool:IsPluginDebugging(Handle:hndl);
dvander@618
   209
dvander@618
   210
/**
dvander@618
   211
 * Retrieves a plugin's public info.
dvander@618
   212
 *
dvander@618
   213
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   214
 * @param info			Plugin info property to retrieve.
dvander@618
   215
 * @param buffer		Buffer to store info in.
dvander@618
   216
 * @param maxlength		Maximum length of buffer.
dvander@618
   217
 * @return				True on success, false if property is not available.
dvander@618
   218
 * @error				Invalid Handle.
dvander@618
   219
 */
dvander@618
   220
native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
dvander@560
   221
dvander@560
   222
/**
dvander@837
   223
 * Causes the plugin to enter a failed state.  An error will be thrown and
dvander@837
   224
 * the plugin will be paused until it is unloaded or reloaded.
dvander@837
   225
 *
dvander@837
   226
 * @param string		Message to print.
dvander@837
   227
 * @noreturn
dvander@838
   228
 * @error				Always throws SP_ERROR_ABORT.
dvander@837
   229
 */
dvander@837
   230
native SetFailState(const String:string[]);
dvander@837
   231
dvander@837
   232
/**
dvander@560
   233
 * Aborts the current callback and throws an error.  This function
dvander@560
   234
 * does not return in that no code is executed following it.
dvander@560
   235
 *
dvander@560
   236
 * @param format		String format.
dvander@560
   237
 * @param ...			Format arguments.
dvander@560
   238
 * @noreturn
dvander@560
   239
 * @error				Always!
dvander@560
   240
 */
ds@634
   241
native ThrowError(const String:fmt[], any:...);
dvander@560
   242
dvander@536
   243
/**
dvander@429
   244
 * Logs a plugin message to the SourceMod logs.
dvander@429
   245
 *
ds@475
   246
 * @param format		String format.
ds@475
   247
 * @param ...			Format arguments.
dvander@429
   248
 * @noreturn
dvander@429
   249
 */
ds@634
   250
native LogMessage(const String:format[], any:...);
dvander@429
   251
dvander@429
   252
/**
dvander@429
   253
 * Logs a plugin error message to the SourceMod logs.
dvander@429
   254
 *
ds@475
   255
 * @param format		String format.
ds@475
   256
 * @param ...			Format arguments.
dvander@429
   257
 * @noreturn
dvander@429
   258
 */
ds@634
   259
native LogError(const String:format[], any:...);
dvander@460
   260
dvander@530
   261
/**
dvander@595
   262
 * Gets the system time as a unix timestamp.
dvander@595
   263
 *
dvander@595
   264
 * @param bigStamp		Optional array to store the 64bit timestamp in.
dvander@595
   265
 * @return				32bit timestamp (number of seconds since unix epoch).
dvander@595
   266
 */
dvander@595
   267
native GetTime(bigStamp[2]={0,0});
dvander@595
   268
dvander@595
   269
/**
faluco@1037
   270
 * Format date and time.
faluco@1037
   271
 *
faluco@1037
   272
 * @param buffer		Destination string buffer.
faluco@1037
   273
 * @param maxlength		Maximum length of output string buffer.
faluco@1037
   274
 * @param format		Formatting rules.
faluco@1041
   275
 * @param stamp			Optional time stamp.
faluco@1037
   276
 * @noreturn
faluco@1037
   277
 */
faluco@1041
   278
native FormatTime(String:buffer[], maxlength, const String:format[], stamp=-1);
faluco@1037
   279
faluco@1037
   280
/**
faluco@703
   281
 * Loads a game config file.
faluco@703
   282
 *
faluco@703
   283
 * @param file			File to load.  The path must be relative to the 'gamedata' folder under the config folder 
faluco@703
   284
 *					and the extension should be omitted.
faluco@703
   285
 * @return			A handle to the game config file or INVALID_HANDLE in failure.
faluco@703
   286
 */
faluco@703
   287
native Handle:LoadGameConfigFile(const String:file[]);
faluco@703
   288
faluco@703
   289
/**
faluco@703
   290
 * Returns an offset value.
faluco@703
   291
 *
faluco@703
   292
 * @param gc			Game config handle.
faluco@703
   293
 * @param key			Key to retrieve from the offset section.
faluco@703
   294
 * @return			An offset, or -1 on failure.
faluco@703
   295
 */
faluco@703
   296
native GameConfGetOffset(Handle:gc, const String:key[]);
faluco@703
   297
faluco@703
   298
/**
faluco@703
   299
 * Gets the value of a key from the "Keys" section.
faluco@703
   300
 *
faluco@703
   301
 * @param gc			Game config handle.
faluco@703
   302
 * @param key			Key to retrieve from the Keys section.
faluco@703
   303
 * @param buffer		Destination string buffer.
faluco@703
   304
 * @param maxlen		Maximum length of output string buffer.
dvander@886
   305
 * @return				True if key existed, false otherwise.
faluco@703
   306
 */
faluco@703
   307
native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
faluco@703
   308
dvander@886
   309
/**
dvander@886
   310
 * Returns the operating system's "tick count," which is a number of 
dvander@886
   311
 * milliseconds since the operating system loaded.  This can be used
dvander@886
   312
 * for basic benchmarks.
dvander@886
   313
 *
dvander@886
   314
 * @return				Tick count in milliseconds.
dvander@886
   315
 */
dvander@886
   316
native GetSysTickCount();
dvander@886
   317
dvander@978
   318
/**
dvander@978
   319
 * Specifies that the given config file should be executed after plugin load.
dvander@978
   320
 * OnConfigsExecuted() will not be called until the config file has executed, 
dvander@978
   321
 * but it will be called if the execution fails.
dvander@978
   322
 *
dvander@978
   323
 * @param autoCreate	If true, and the config file does not exist, such a config
dvander@978
   324
 *						file will be automatically created and populated with
dvander@978
   325
 *						information from the plugin's registered cvars.
dvander@978
   326
 * @param name			Name of the config file, excluding the .cfg extension.
dvander@978
   327
 *						If empty, <plugin.filename.cfg> is assumed.
dvander@978
   328
 * @param folder		Folder under cfg/ to use.  By default this is "sourcemod."
dvander@978
   329
 * @noreturn
dvander@978
   330
 */
dvander@978
   331
native AutoExecConfig(bool:autoCreate=true, const String:name[]="", const String:folder[]="sourcemod");
dvander@978
   332
faluco@1112
   333
/**
faluco@1112
   334
 * Sets a native as optional, such that if it is unloaded, removed,
faluco@1112
   335
 * or otherwise non-existent, the plugin will still work.  Calling
faluco@1112
   336
 * removed natives results in a run-time error.
faluco@1112
   337
 *
faluco@1112
   338
 * @param name			Native name.
faluco@1112
   339
 * @noreturn
faluco@1112
   340
 */
faluco@1112
   341
native MarkNativeAsOptional(const String:name[]);
faluco@1112
   342
faluco@1112
   343
/**
faluco@1112
   344
 * Registers a library name for identifying as a dependency to 
faluco@1112
   345
 * other plugins.
faluco@1112
   346
 *
faluco@1112
   347
 * @param name			Library name.
faluco@1112
   348
 * @noreturn
faluco@1112
   349
 */
faluco@1112
   350
native RegPluginLibrary(const String:name[]);
faluco@1112
   351
dvander@1124
   352
/**
dvander@1124
   353
 * Returns whether a library exists.
dvander@1124
   354
 *
dvander@1124
   355
 * @param name			Library name.
dvander@1124
   356
 * @return				True if exists, false otherwise.
dvander@1124
   357
 */
dvander@1124
   358
native bool:LibraryExists(const String:name[]);
dvander@1124
   359
dvander@1124
   360
/**
dvander@1124
   361
 * Called after a library (plugin) is added that the 
dvander@1124
   362
 * current plugin references optionally.
dvander@1124
   363
 *
dvander@1124
   364
 * @param name			Library name.
dvander@1124
   365
 */
dvander@1124
   366
forward OnLibraryAdded(const String:name[]);
dvander@1124
   367
dvander@1124
   368
/**
dvander@1124
   369
 * Called right before a library (plugin) is removed that the 
dvander@1124
   370
 * current plugin references optionally.
dvander@1124
   371
 *
dvander@1124
   372
 * @param name			Library name.
dvander@1124
   373
 */
dvander@1124
   374
forward OnLibraryRemoved(const String:name[]);
dvander@1124
   375
dvander@460
   376
#include <helpers>
dvander@560
   377
#include <entity>