plugins/include/sourcemod.inc
author David Anderson <dvander@alliedmods.net>
Fri Jun 01 02:30:29 2007 +0000 (2007-06-01)
changeset 868 bdbf922e246f
parent 849 fe1e531a19ce
child 873 a2136b3be10d
permissions -rw-r--r--
-initial import of database natives + config
-initial import of completed database layer
-CreateIdentity now requires a non-optional second pointer. This breaks backwards compatibility for CreateIdentity(), however, this is not a function extension authors are supposed to be calling
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@429
    35
#include <handles>
dvander@429
    36
#include <string>
dvander@429
    37
#include <admin>
dvander@429
    38
#include <files>
ds@457
    39
#include <console>
faluco@505
    40
#include <bitbuffer>
dvander@535
    41
#include <sorting>
dvander@545
    42
#include <clients>
ds@576
    43
#include <usermessages>
ds@576
    44
#include <events>
dvander@601
    45
#include <functions>
dvander@643
    46
#include <timers>
dvander@868
    47
#include <dbi>
dvander@429
    48
faluco@682
    49
enum DialogType
faluco@682
    50
{
faluco@682
    51
	DialogType_Msg = 0,		/**< just an on screen message */
faluco@682
    52
	DialogType_Menu, 		/**< an options menu */
faluco@682
    53
	DialogType_Text, 		/**< a richtext dialog */
faluco@682
    54
	DialogType_Entry 		/**< an entry box */
faluco@682
    55
};
faluco@682
    56
dvander@429
    57
/**
dvander@429
    58
 * Declare this as a struct in your plugin to expose its information.
dvander@429
    59
 * Example:
dvander@429
    60
 *
dvander@429
    61
 * public Plugin:myinfo =
dvander@429
    62
 * {
dvander@429
    63
 *    name = "My Plugin",
dvander@429
    64
 *    //etc
dvander@429
    65
 * };
dvander@429
    66
 */
dvander@429
    67
public Plugin:myinfo;
dvander@429
    68
 
dvander@429
    69
/**
dvander@429
    70
 * Called when the plugin is fully initialized and all known external references are resolved.
dvander@429
    71
 * This is called even if the plugin type is "private."
dvander@619
    72
 * @note Errors in this function will cause the plugin to stop running.
dvander@429
    73
 *
dvander@429
    74
 * @noreturn
dvander@429
    75
 */
dvander@536
    76
forward OnPluginStart();
dvander@429
    77
 
dvander@429
    78
/**
dvander@429
    79
 *   Called before OnPluginStart, in case the plugin wants to check for load failure.
dvander@429
    80
 * This is called even if the plugin type is "private."  Any natives from modules are 
dvander@429
    81
 * not available at this point.  Thus, this forward should only be used for explicit 
dvander@429
    82
 * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
dvander@429
    83
 * 
dvander@619
    84
 * @note It is not safe to call externally resolved natives until OnPluginStart().
dvander@619
    85
 * @note Any sort of RTE in this function will cause the plugin to fail loading.
dvander@429
    86
 *
dvander@429
    87
 * @param myself	Handle to the plugin.
dvander@429
    88
 * @param late		Whether or not the plugin was loaded "late" (after map load).
dvander@429
    89
 * @param error		Error message buffer in case load failed.
dvander@429
    90
 * @param err_max	Maximum number of characters for error message buffer.
dvander@429
    91
 * @return			True if load success, false otherwise.
dvander@429
    92
 */
dvander@429
    93
forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
dvander@429
    94
dvander@429
    95
/**
dvander@429
    96
 * Called when the plugin is about to be unloaded.
dvander@429
    97
 *
dvander@429
    98
 * @noreturn
dvander@429
    99
 */
dvander@429
   100
forward OnPluginEnd();
dvander@429
   101
dvander@429
   102
/**
dvander@429
   103
 * Called when the plugin's pause status is changing.
dvander@429
   104
 *
ds@475
   105
 * @param pause			True if the plugin is being paused, false otherwise.
dvander@429
   106
 * @noreturn
dvander@429
   107
 */
dvander@429
   108
forward OnPluginPauseChange(bool:pause);
dvander@429
   109
dvander@429
   110
/**
dvander@531
   111
 * Called before every server frame.  Note that you should avoid
dvander@531
   112
 * doing expensive computations here, and you should declare large
dvander@531
   113
 * local arrays using 'decl' instead of 'new'.
dvander@531
   114
 */
dvander@531
   115
forward OnGameFrame();
dvander@531
   116
dvander@531
   117
/**
dvander@717
   118
 * Called when the map is loaded.
dvander@717
   119
 *
dvander@723
   120
 * @note This used to be OnServerLoad(), which is now deprecated.
dvander@717
   121
 * Plugins still using the old forward will work.
dvander@643
   122
 */
dvander@717
   123
forward OnMapStart();
dvander@643
   124
dvander@643
   125
/**
dvander@718
   126
 * Called right before a map ends.
dvander@718
   127
 */
dvander@718
   128
forward OnMapEnd();
dvander@718
   129
dvander@718
   130
/**
dvander@723
   131
 * Called when the map has loaded and the servercfgfile has finished
dvander@723
   132
 * executing.  This is usually 'server.cfg' but most mods allow it to
dvander@723
   133
 * be set via 'servercfgfile'.  
dvander@723
   134
 *
dvander@723
   135
 * @note If server.cfg is executed more than once per map, this forward
dvander@723
   136
 * will only be called the first time (per map).
dvander@849
   137
 * @note It is not guaranteed that this will be called on all mods. If
dvander@849
   138
 * a mod does not appear to support it, please file a SourceMod bug report.
dvander@723
   139
 */
dvander@723
   140
forward OnServerCfg();
dvander@723
   141
dvander@723
   142
/**
dvander@536
   143
 * Returns the calling plugin's Handle.
dvander@536
   144
 *
dvander@536
   145
 * @return				Handle of the calling plugin.
dvander@536
   146
 */
dvander@536
   147
native Handle:GetMyHandle();
dvander@536
   148
dvander@618
   149
/**
dvander@618
   150
 * Returns an iterator that can be used to search through plugins.
dvander@618
   151
 *
dvander@618
   152
 * @return				Handle to iterate with.  Must be closed via 
dvander@618
   153
 * 						CloseHandle().
dvander@618
   154
 * @error				Invalid Handle.
dvander@618
   155
 */
dvander@618
   156
native Handle:GetPluginIterator();
dvander@618
   157
dvander@618
   158
/**
dvander@618
   159
 * Returns whether there are more plugins available in the iterator.
dvander@618
   160
 *
dvander@618
   161
 * @param iter			Handle to the plugin iterator.
dvander@618
   162
 * @return				True on more plugins, false otherwise.
dvander@618
   163
 * @error				Invalid Handle.
dvander@618
   164
 */
dvander@618
   165
native bool:MorePlugins(Handle:iter);
dvander@618
   166
dvander@618
   167
/**
dvander@618
   168
 * Returns the current plugin in the iterator and advances the iterator.
dvander@618
   169
 *
dvander@618
   170
 * @param iter			Handle to the plugin iterator.
dvander@618
   171
 * @return				Current plugin the iterator is at, before
dvander@618
   172
 *						the iterator is advanced.
dvander@618
   173
 * @error				Invalid Handle.
dvander@618
   174
 */
dvander@618
   175
native Handle:ReadPlugin(Handle:iter);
dvander@618
   176
dvander@618
   177
/**
dvander@618
   178
 * Returns a plugin's status.
dvander@618
   179
 *
dvander@618
   180
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   181
 * @return				Status code for the plugin.
dvander@618
   182
 * @error				Invalid Handle.
dvander@618
   183
 */
dvander@618
   184
native PluginStatus:GetPluginStatus(Handle:plugin);
dvander@618
   185
dvander@618
   186
/**
dvander@618
   187
 * Retrieves a plugin's file name relative to the plugins folder.
dvander@618
   188
 *
dvander@618
   189
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   190
 * @param buffer		Buffer to the store the file name.
dvander@618
   191
 * @param maxlength		Maximum length of the name buffer.
dvander@618
   192
 * @noreturn
dvander@618
   193
 * @error				Invalid Handle.
dvander@618
   194
 */
dvander@618
   195
native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
dvander@618
   196
dvander@618
   197
/**
dvander@618
   198
 * Retrieves whether or not a plugin is being debugged.
dvander@618
   199
 *
dvander@618
   200
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   201
 * @return				True if being debugged, false otherwise.
dvander@618
   202
 * @error				Invalid Handle.
dvander@618
   203
 */
dvander@618
   204
native bool:IsPluginDebugging(Handle:hndl);
dvander@618
   205
dvander@618
   206
/**
dvander@618
   207
 * Retrieves a plugin's public info.
dvander@618
   208
 *
dvander@618
   209
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   210
 * @param info			Plugin info property to retrieve.
dvander@618
   211
 * @param buffer		Buffer to store info in.
dvander@618
   212
 * @param maxlength		Maximum length of buffer.
dvander@618
   213
 * @return				True on success, false if property is not available.
dvander@618
   214
 * @error				Invalid Handle.
dvander@618
   215
 */
dvander@618
   216
native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
dvander@560
   217
dvander@560
   218
/**
dvander@837
   219
 * Causes the plugin to enter a failed state.  An error will be thrown and
dvander@837
   220
 * the plugin will be paused until it is unloaded or reloaded.
dvander@837
   221
 *
dvander@837
   222
 * @param string		Message to print.
dvander@837
   223
 * @noreturn
dvander@838
   224
 * @error				Always throws SP_ERROR_ABORT.
dvander@837
   225
 */
dvander@837
   226
native SetFailState(const String:string[]);
dvander@837
   227
dvander@837
   228
/**
dvander@560
   229
 * Aborts the current callback and throws an error.  This function
dvander@560
   230
 * does not return in that no code is executed following it.
dvander@560
   231
 *
dvander@560
   232
 * @param format		String format.
dvander@560
   233
 * @param ...			Format arguments.
dvander@560
   234
 * @noreturn
dvander@560
   235
 * @error				Always!
dvander@560
   236
 */
ds@634
   237
native ThrowError(const String:fmt[], any:...);
dvander@560
   238
dvander@536
   239
/**
dvander@429
   240
 * Logs a generic message to the HL2 logs.
dvander@429
   241
 *
ds@475
   242
 * @param format		String format.
ds@475
   243
 * @param ...			Format arguments.
dvander@429
   244
 * @noreturn
dvander@429
   245
 */
ds@634
   246
native LogToGame(const String:format[], any:...);
dvander@429
   247
dvander@429
   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
/**
dvander@530
   275
 * Sets the seed value for the global Half-Life 2 Random Stream
dvander@530
   276
 *
dvander@530
   277
 * @param seed			Seed value.
dvander@530
   278
 * @noreturn	
dvander@530
   279
 */
dvander@530
   280
native SetRandomSeed(seed);
dvander@530
   281
dvander@530
   282
/**
dvander@530
   283
 * Returns a random floating point number from the Half-Life 2 Random Stream
dvander@530
   284
 *
dvander@530
   285
 * @param fMin			Minimum random bound.
dvander@530
   286
 * @param fMax			Maximum random bound.
dvander@530
   287
 * @return				A random number between (inclusive) fMin and fMax.
dvander@530
   288
 */
dvander@530
   289
native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0);
dvander@530
   290
dvander@530
   291
/**
dvander@530
   292
 * Returns a random number from the Half-Life 2 Random Stream
dvander@530
   293
 *
dvander@530
   294
 * @param nmin			Minimum random bound.
dvander@530
   295
 * @param nmax			Maximum random bound.
dvander@530
   296
 * @return				A random number between (inclusive) nmin and nmax.
dvander@530
   297
 */
dvander@530
   298
native GetRandomInt(nmin, nmax);
dvander@530
   299
dvander@532
   300
/**
dvander@532
   301
 * Returns whether a map is valid or not.
dvander@532
   302
 * 
dvander@532
   303
 * @param 				Map name, excluding .bsp extension.
dvander@532
   304
 * @return				True if valid, false otherwise.
dvander@532
   305
 */
dvander@532
   306
native bool:IsMapValid(const String:map[]);
dvander@532
   307
dvander@532
   308
/**
dvander@532
   309
 * Returns whether the server is dedicated.
dvander@532
   310
 *
dvander@532
   311
 * @return				True if dedicated, false otherwise.
dvander@532
   312
 */
dvander@532
   313
native bool:IsDedicatedServer();
dvander@532
   314
dvander@532
   315
/**
dvander@532
   316
 * Returns a high-precision time value for profiling the engine.
dvander@532
   317
 *
dvander@532
   318
 * @return				A floating point time value.
dvander@532
   319
 */
dvander@532
   320
native Float:GetEngineTime();
dvander@532
   321
dvander@532
   322
/** 
dvander@532
   323
 * Returns the game time based on the game tick.
dvander@532
   324
 *
dvander@532
   325
 * @return				Game tick time.
dvander@532
   326
 */
dvander@532
   327
native Float:GetGameTime();
dvander@532
   328
dvander@532
   329
/**
dvander@532
   330
 * Returns the game description from the mod.
dvander@532
   331
 *
dvander@532
   332
 * @param buffer		Buffer to store the description.
dvander@532
   333
 * @param maxlength		Maximum size of the buffer.
dvander@532
   334
 * @param original		If true, retrieves the original game description,
dvander@532
   335
 *						ignoring any potential hooks from plugins.
dvander@532
   336
 * @return				Number of bytes written to the buffer (UTF-8 safe).
dvander@532
   337
 */
dvander@532
   338
native GetGameDescription(String:buffer[], maxlength, bool:original=false);
dvander@532
   339
dvander@532
   340
/**
ds@721
   341
 * Returns the name of the game's directory.
ds@721
   342
 *
ds@721
   343
 * @param buffer		Buffer to store the directory name.
ds@721
   344
 * @param maxlength		Maximum size of the buffer.
ds@721
   345
 *
ds@721
   346
 * return				Number of bytes written to the buffer (UTF-8 safe).
ds@721
   347
 */
ds@721
   348
native GetGameFolderName(String:buffer[], maxlength);
ds@721
   349
ds@721
   350
/**
dvander@532
   351
 * Returns the current map name.
dvander@532
   352
 *
dvander@532
   353
 * @param buffer		Buffer to store map name.
dvander@532
   354
 * @param maxlength		Maximum length of buffer.
dvander@532
   355
 * @return				Number of bytes written (UTF-8 safe).
dvander@532
   356
 */
dvander@532
   357
native GetCurrentMap(String:buffer[], maxlength);
dvander@530
   358
faluco@656
   359
/**
faluco@656
   360
 * Precaches a given model.
faluco@656
   361
 *
faluco@656
   362
 * @param model			Name of the model to precache.
faluco@656
   363
 * @param preload		If preload is true the file will be precached before level startup.
faluco@656
   364
 * @return			Returns the model index, 0 for error.
faluco@656
   365
 */
faluco@656
   366
native PrecacheModel(const String:model[], bool:preload=false);
faluco@656
   367
faluco@656
   368
/**
faluco@656
   369
 * Precaches a given sentence file.
faluco@656
   370
 *
faluco@656
   371
 * @param file			Name of the sentence file to precache.
faluco@656
   372
 * @param preload		If preload is true the file will be precached before level startup.
faluco@656
   373
 * @return			Returns a sentence file index.
faluco@656
   374
 */
faluco@656
   375
native PrecacheSentenceFile(const String:file[], bool:preload=false);
faluco@656
   376
faluco@656
   377
/**
faluco@656
   378
 * Precaches a given decal.
faluco@656
   379
 *
faluco@656
   380
 * @param decal			Name of the decal to precache.
faluco@656
   381
 * @param preload		If preload is true the file will be precached before level startup.
faluco@656
   382
 * @return			Returns a decal index.
faluco@656
   383
 */
faluco@656
   384
native PrecacheDecal(const String:decal[], bool:preload=false);
faluco@656
   385
faluco@656
   386
/**
faluco@656
   387
 * Precaches a given generic file.
faluco@656
   388
 *
faluco@656
   389
 * @param generic		Name of the generic file to precache.
faluco@656
   390
 * @param preload		If preload is true the file will be precached before level startup.
faluco@656
   391
 * @return			Returns a generic file index.
faluco@656
   392
 */
faluco@656
   393
native PrecacheGeneric(const String:generic[], bool:preload=false);
faluco@656
   394
faluco@656
   395
/**
faluco@656
   396
 * Returns if a given model is precached.
faluco@656
   397
 *
faluco@656
   398
 * @param model			Name of the model to check.
faluco@656
   399
 * @return			True if precached, false otherwise.
faluco@656
   400
 */
faluco@656
   401
native bool:IsModelPrecached(const String:model[]);
faluco@656
   402
faluco@656
   403
/**
faluco@656
   404
 * Returns if a given decal is precached.
faluco@656
   405
 *
faluco@656
   406
 * @param decal			Name of the decal to check.
faluco@656
   407
 * @return			True if precached, false otherwise.
faluco@656
   408
 */
faluco@656
   409
native bool:IsDecalPrecached(const String:decal[]);
faluco@656
   410
faluco@656
   411
/**
faluco@656
   412
 * Returns if a given generic file is precached.
faluco@656
   413
 *
faluco@656
   414
 * @param decal			Name of the generic file to check.
faluco@656
   415
 * @return			True if precached, false otherwise.
faluco@656
   416
 */
faluco@656
   417
native bool:IsGenericPrecached(const String:generic[]);
faluco@656
   418
faluco@656
   419
/**
faluco@656
   420
 * Precaches a given sound.
faluco@656
   421
 *
faluco@656
   422
 * @param sound			Name of the sound to precache.
faluco@656
   423
 * @param preload		If preload is true the file will be precached before level startup.
faluco@656
   424
 * @return			True if successfully precached, false otherwise.
faluco@656
   425
 */
faluco@656
   426
native bool:PrecacheSound(const String:sound[], bool:preload=false);
faluco@656
   427
faluco@656
   428
/**
faluco@656
   429
 * Returns if a given sound is precached.
faluco@656
   430
 *
faluco@656
   431
 * @param sound			Name of the sound to check.
faluco@656
   432
 * @return			True if precached, false otherwise.
faluco@656
   433
 */
faluco@656
   434
native bool:IsSoundPrecached(const String:sound[]);
faluco@656
   435
faluco@659
   436
/**
faluco@682
   437
 * Creates different types of ingame messages.
faluco@659
   438
 *
faluco@659
   439
 * @param client		Index of the client.
faluco@682
   440
 * @param kv			KeyValues handle to set the menu keys and options. (Check iserverplugin.h for more information).
faluco@682
   441
 * @param type			Message type to display ingame.
faluco@659
   442
 * @noreturn
faluco@659
   443
 * @error				Invalid client index, or client not connected.
faluco@659
   444
 */
faluco@682
   445
native CreateDialog(client, Handle:kv, DialogType:type);
faluco@659
   446
faluco@703
   447
/**
faluco@703
   448
 * Loads a game config file.
faluco@703
   449
 *
faluco@703
   450
 * @param file			File to load.  The path must be relative to the 'gamedata' folder under the config folder 
faluco@703
   451
 *					and the extension should be omitted.
faluco@703
   452
 * @return			A handle to the game config file or INVALID_HANDLE in failure.
faluco@703
   453
 */
faluco@703
   454
native Handle:LoadGameConfigFile(const String:file[]);
faluco@703
   455
faluco@703
   456
/**
faluco@703
   457
 * Returns an offset value.
faluco@703
   458
 *
faluco@703
   459
 * @param gc			Game config handle.
faluco@703
   460
 * @param key			Key to retrieve from the offset section.
faluco@703
   461
 * @return			An offset, or -1 on failure.
faluco@703
   462
 */
faluco@703
   463
native GameConfGetOffset(Handle:gc, const String:key[]);
faluco@703
   464
faluco@703
   465
/**
faluco@703
   466
 * Gets the value of a key from the "Keys" section.
faluco@703
   467
 *
faluco@703
   468
 * @param gc			Game config handle.
faluco@703
   469
 * @param key			Key to retrieve from the Keys section.
faluco@703
   470
 * @param buffer		Destination string buffer.
faluco@703
   471
 * @param maxlen		Maximum length of output string buffer.
faluco@703
   472
 * @return			True if key existed, false otherwise.
faluco@703
   473
 */
faluco@703
   474
native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
faluco@703
   475
dvander@460
   476
#include <helpers>
dvander@560
   477
#include <entity>
dvander@811
   478
#include <menus>