plugins/include/sourcemod.inc
author Borja Ferrer <faluco@alliedmods.net>
Thu Mar 29 19:48:54 2007 +0000 (2007-03-29)
changeset 659 edd2ead1f13e
parent 656 351fca8ce6a5
child 682 a70055d6d3b3
permissions -rw-r--r--
oh one native for the hat man teame
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@429
    47
dvander@429
    48
/**
dvander@429
    49
 * Declare this as a struct in your plugin to expose its information.
dvander@429
    50
 * Example:
dvander@429
    51
 *
dvander@429
    52
 * public Plugin:myinfo =
dvander@429
    53
 * {
dvander@429
    54
 *    name = "My Plugin",
dvander@429
    55
 *    //etc
dvander@429
    56
 * };
dvander@429
    57
 */
dvander@429
    58
public Plugin:myinfo;
dvander@429
    59
 
dvander@429
    60
/**
dvander@429
    61
 * Called when the plugin is fully initialized and all known external references are resolved.
dvander@429
    62
 * This is called even if the plugin type is "private."
dvander@619
    63
 * @note Errors in this function will cause the plugin to stop running.
dvander@429
    64
 *
dvander@429
    65
 * @noreturn
dvander@429
    66
 */
dvander@536
    67
forward OnPluginStart();
dvander@429
    68
 
dvander@429
    69
/**
dvander@429
    70
 *   Called before OnPluginStart, in case the plugin wants to check for load failure.
dvander@429
    71
 * This is called even if the plugin type is "private."  Any natives from modules are 
dvander@429
    72
 * not available at this point.  Thus, this forward should only be used for explicit 
dvander@429
    73
 * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
dvander@429
    74
 * 
dvander@619
    75
 * @note It is not safe to call externally resolved natives until OnPluginStart().
dvander@619
    76
 * @note Any sort of RTE in this function will cause the plugin to fail loading.
dvander@429
    77
 *
dvander@429
    78
 * @param myself	Handle to the plugin.
dvander@429
    79
 * @param late		Whether or not the plugin was loaded "late" (after map load).
dvander@429
    80
 * @param error		Error message buffer in case load failed.
dvander@429
    81
 * @param err_max	Maximum number of characters for error message buffer.
dvander@429
    82
 * @return			True if load success, false otherwise.
dvander@429
    83
 */
dvander@429
    84
forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
dvander@429
    85
dvander@429
    86
/**
dvander@429
    87
 * Called when the plugin is about to be unloaded.
dvander@429
    88
 *
dvander@429
    89
 * @noreturn
dvander@429
    90
 */
dvander@429
    91
forward OnPluginEnd();
dvander@429
    92
dvander@429
    93
/**
dvander@429
    94
 * Called when the plugin's pause status is changing.
dvander@429
    95
 *
ds@475
    96
 * @param pause			True if the plugin is being paused, false otherwise.
dvander@429
    97
 * @noreturn
dvander@429
    98
 */
dvander@429
    99
forward OnPluginPauseChange(bool:pause);
dvander@429
   100
dvander@429
   101
/**
dvander@531
   102
 * Called before every server frame.  Note that you should avoid
dvander@531
   103
 * doing expensive computations here, and you should declare large
dvander@531
   104
 * local arrays using 'decl' instead of 'new'.
dvander@531
   105
 */
dvander@531
   106
forward OnGameFrame();
dvander@531
   107
dvander@531
   108
/**
dvander@643
   109
 * Called when the map is loaded and configs have been parsed.
dvander@643
   110
 * Note that commands are processed per-frame, and thus config
dvander@643
   111
 * files may not be fully loaded until a few seconds later.
faluco@651
   112
 * This function will be called on each mapchange.
dvander@643
   113
 */
dvander@643
   114
forward OnServerLoad();
dvander@643
   115
dvander@643
   116
/**
dvander@536
   117
 * Returns the calling plugin's Handle.
dvander@536
   118
 *
dvander@536
   119
 * @return				Handle of the calling plugin.
dvander@536
   120
 */
dvander@536
   121
native Handle:GetMyHandle();
dvander@536
   122
dvander@618
   123
/**
dvander@618
   124
 * Returns an iterator that can be used to search through plugins.
dvander@618
   125
 *
dvander@618
   126
 * @return				Handle to iterate with.  Must be closed via 
dvander@618
   127
 * 						CloseHandle().
dvander@618
   128
 * @error				Invalid Handle.
dvander@618
   129
 */
dvander@618
   130
native Handle:GetPluginIterator();
dvander@618
   131
dvander@618
   132
/**
dvander@618
   133
 * Returns whether there are more plugins available in the iterator.
dvander@618
   134
 *
dvander@618
   135
 * @param iter			Handle to the plugin iterator.
dvander@618
   136
 * @return				True on more plugins, false otherwise.
dvander@618
   137
 * @error				Invalid Handle.
dvander@618
   138
 */
dvander@618
   139
native bool:MorePlugins(Handle:iter);
dvander@618
   140
dvander@618
   141
/**
dvander@618
   142
 * Returns the current plugin in the iterator and advances the iterator.
dvander@618
   143
 *
dvander@618
   144
 * @param iter			Handle to the plugin iterator.
dvander@618
   145
 * @return				Current plugin the iterator is at, before
dvander@618
   146
 *						the iterator is advanced.
dvander@618
   147
 * @error				Invalid Handle.
dvander@618
   148
 */
dvander@618
   149
native Handle:ReadPlugin(Handle:iter);
dvander@618
   150
dvander@618
   151
/**
dvander@618
   152
 * Returns a plugin's status.
dvander@618
   153
 *
dvander@618
   154
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   155
 * @return				Status code for the plugin.
dvander@618
   156
 * @error				Invalid Handle.
dvander@618
   157
 */
dvander@618
   158
native PluginStatus:GetPluginStatus(Handle:plugin);
dvander@618
   159
dvander@618
   160
/**
dvander@618
   161
 * Retrieves a plugin's file name relative to the plugins folder.
dvander@618
   162
 *
dvander@618
   163
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   164
 * @param buffer		Buffer to the store the file name.
dvander@618
   165
 * @param maxlength		Maximum length of the name buffer.
dvander@618
   166
 * @noreturn
dvander@618
   167
 * @error				Invalid Handle.
dvander@618
   168
 */
dvander@618
   169
native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
dvander@618
   170
dvander@618
   171
/**
dvander@618
   172
 * Retrieves whether or not a plugin is being debugged.
dvander@618
   173
 *
dvander@618
   174
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   175
 * @return				True if being debugged, false otherwise.
dvander@618
   176
 * @error				Invalid Handle.
dvander@618
   177
 */
dvander@618
   178
native bool:IsPluginDebugging(Handle:hndl);
dvander@618
   179
dvander@618
   180
/**
dvander@618
   181
 * Retrieves a plugin's public info.
dvander@618
   182
 *
dvander@618
   183
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   184
 * @param info			Plugin info property to retrieve.
dvander@618
   185
 * @param buffer		Buffer to store info in.
dvander@618
   186
 * @param maxlength		Maximum length of buffer.
dvander@618
   187
 * @return				True on success, false if property is not available.
dvander@618
   188
 * @error				Invalid Handle.
dvander@618
   189
 */
dvander@618
   190
native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
dvander@560
   191
dvander@560
   192
/**
dvander@560
   193
 * Aborts the current callback and throws an error.  This function
dvander@560
   194
 * does not return in that no code is executed following it.
dvander@560
   195
 *
dvander@560
   196
 * @param format		String format.
dvander@560
   197
 * @param ...			Format arguments.
dvander@560
   198
 * @noreturn
dvander@560
   199
 * @error				Always!
dvander@560
   200
 */
ds@634
   201
native ThrowError(const String:fmt[], any:...);
dvander@560
   202
dvander@536
   203
/**
dvander@429
   204
 * Logs a generic message to the HL2 logs.
dvander@429
   205
 *
ds@475
   206
 * @param format		String format.
ds@475
   207
 * @param ...			Format arguments.
dvander@429
   208
 * @noreturn
dvander@429
   209
 */
ds@634
   210
native LogToGame(const String:format[], any:...);
dvander@429
   211
dvander@429
   212
/**
dvander@429
   213
 * Logs a plugin message to the SourceMod logs.
dvander@429
   214
 *
ds@475
   215
 * @param format		String format.
ds@475
   216
 * @param ...			Format arguments.
dvander@429
   217
 * @noreturn
dvander@429
   218
 */
ds@634
   219
native LogMessage(const String:format[], any:...);
dvander@429
   220
dvander@429
   221
/**
dvander@429
   222
 * Logs a plugin error message to the SourceMod logs.
dvander@429
   223
 *
ds@475
   224
 * @param format		String format.
ds@475
   225
 * @param ...			Format arguments.
dvander@429
   226
 * @noreturn
dvander@429
   227
 */
ds@634
   228
native LogError(const String:format[], any:...);
dvander@460
   229
dvander@530
   230
/**
dvander@595
   231
 * Gets the system time as a unix timestamp.
dvander@595
   232
 *
dvander@595
   233
 * @param bigStamp		Optional array to store the 64bit timestamp in.
dvander@595
   234
 * @return				32bit timestamp (number of seconds since unix epoch).
dvander@595
   235
 */
dvander@595
   236
native GetTime(bigStamp[2]={0,0});
dvander@595
   237
dvander@595
   238
/**
dvander@530
   239
 * Sets the seed value for the global Half-Life 2 Random Stream
dvander@530
   240
 *
dvander@530
   241
 * @param seed			Seed value.
dvander@530
   242
 * @noreturn	
dvander@530
   243
 */
dvander@530
   244
native SetRandomSeed(seed);
dvander@530
   245
dvander@530
   246
/**
dvander@530
   247
 * Returns a random floating point number from the Half-Life 2 Random Stream
dvander@530
   248
 *
dvander@530
   249
 * @param fMin			Minimum random bound.
dvander@530
   250
 * @param fMax			Maximum random bound.
dvander@530
   251
 * @return				A random number between (inclusive) fMin and fMax.
dvander@530
   252
 */
dvander@530
   253
native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0);
dvander@530
   254
dvander@530
   255
/**
dvander@530
   256
 * Returns a random number from the Half-Life 2 Random Stream
dvander@530
   257
 *
dvander@530
   258
 * @param nmin			Minimum random bound.
dvander@530
   259
 * @param nmax			Maximum random bound.
dvander@530
   260
 * @return				A random number between (inclusive) nmin and nmax.
dvander@530
   261
 */
dvander@530
   262
native GetRandomInt(nmin, nmax);
dvander@530
   263
dvander@532
   264
/**
dvander@532
   265
 * Returns whether a map is valid or not.
dvander@532
   266
 * 
dvander@532
   267
 * @param 				Map name, excluding .bsp extension.
dvander@532
   268
 * @return				True if valid, false otherwise.
dvander@532
   269
 */
dvander@532
   270
native bool:IsMapValid(const String:map[]);
dvander@532
   271
dvander@532
   272
/**
dvander@532
   273
 * Returns whether the server is dedicated.
dvander@532
   274
 *
dvander@532
   275
 * @return				True if dedicated, false otherwise.
dvander@532
   276
 */
dvander@532
   277
native bool:IsDedicatedServer();
dvander@532
   278
dvander@532
   279
/**
dvander@532
   280
 * Returns a high-precision time value for profiling the engine.
dvander@532
   281
 *
dvander@532
   282
 * @return				A floating point time value.
dvander@532
   283
 */
dvander@532
   284
native Float:GetEngineTime();
dvander@532
   285
dvander@532
   286
/** 
dvander@532
   287
 * Returns the game time based on the game tick.
dvander@532
   288
 *
dvander@532
   289
 * @return				Game tick time.
dvander@532
   290
 */
dvander@532
   291
native Float:GetGameTime();
dvander@532
   292
dvander@532
   293
/**
dvander@532
   294
 * Returns the game description from the mod.
dvander@532
   295
 *
dvander@532
   296
 * @param buffer		Buffer to store the description.
dvander@532
   297
 * @param maxlength		Maximum size of the buffer.
dvander@532
   298
 * @param original		If true, retrieves the original game description,
dvander@532
   299
 *						ignoring any potential hooks from plugins.
dvander@532
   300
 * @return				Number of bytes written to the buffer (UTF-8 safe).
dvander@532
   301
 */
dvander@532
   302
native GetGameDescription(String:buffer[], maxlength, bool:original=false);
dvander@532
   303
dvander@532
   304
/**
dvander@532
   305
 * Returns the current map name.
dvander@532
   306
 *
dvander@532
   307
 * @param buffer		Buffer to store map name.
dvander@532
   308
 * @param maxlength		Maximum length of buffer.
dvander@532
   309
 * @return				Number of bytes written (UTF-8 safe).
dvander@532
   310
 */
dvander@532
   311
native GetCurrentMap(String:buffer[], maxlength);
dvander@530
   312
faluco@656
   313
/**
faluco@656
   314
 * Precaches a given model.
faluco@656
   315
 *
faluco@656
   316
 * @param model			Name of the model to precache.
faluco@656
   317
 * @param preload		If preload is true the file will be precached before level startup.
faluco@656
   318
 * @return			Returns the model index, 0 for error.
faluco@656
   319
 */
faluco@656
   320
native PrecacheModel(const String:model[], bool:preload=false);
faluco@656
   321
faluco@656
   322
/**
faluco@656
   323
 * Precaches a given sentence file.
faluco@656
   324
 *
faluco@656
   325
 * @param file			Name of the sentence file to precache.
faluco@656
   326
 * @param preload		If preload is true the file will be precached before level startup.
faluco@656
   327
 * @return			Returns a sentence file index.
faluco@656
   328
 */
faluco@656
   329
native PrecacheSentenceFile(const String:file[], bool:preload=false);
faluco@656
   330
faluco@656
   331
/**
faluco@656
   332
 * Precaches a given decal.
faluco@656
   333
 *
faluco@656
   334
 * @param decal			Name of the decal to precache.
faluco@656
   335
 * @param preload		If preload is true the file will be precached before level startup.
faluco@656
   336
 * @return			Returns a decal index.
faluco@656
   337
 */
faluco@656
   338
native PrecacheDecal(const String:decal[], bool:preload=false);
faluco@656
   339
faluco@656
   340
/**
faluco@656
   341
 * Precaches a given generic file.
faluco@656
   342
 *
faluco@656
   343
 * @param generic		Name of the generic file to precache.
faluco@656
   344
 * @param preload		If preload is true the file will be precached before level startup.
faluco@656
   345
 * @return			Returns a generic file index.
faluco@656
   346
 */
faluco@656
   347
native PrecacheGeneric(const String:generic[], bool:preload=false);
faluco@656
   348
faluco@656
   349
/**
faluco@656
   350
 * Returns if a given model is precached.
faluco@656
   351
 *
faluco@656
   352
 * @param model			Name of the model to check.
faluco@656
   353
 * @return			True if precached, false otherwise.
faluco@656
   354
 */
faluco@656
   355
native bool:IsModelPrecached(const String:model[]);
faluco@656
   356
faluco@656
   357
/**
faluco@656
   358
 * Returns if a given decal is precached.
faluco@656
   359
 *
faluco@656
   360
 * @param decal			Name of the decal to check.
faluco@656
   361
 * @return			True if precached, false otherwise.
faluco@656
   362
 */
faluco@656
   363
native bool:IsDecalPrecached(const String:decal[]);
faluco@656
   364
faluco@656
   365
/**
faluco@656
   366
 * Returns if a given generic file is precached.
faluco@656
   367
 *
faluco@656
   368
 * @param decal			Name of the generic file to check.
faluco@656
   369
 * @return			True if precached, false otherwise.
faluco@656
   370
 */
faluco@656
   371
native bool:IsGenericPrecached(const String:generic[]);
faluco@656
   372
faluco@656
   373
/**
faluco@656
   374
 * Precaches a given sound.
faluco@656
   375
 *
faluco@656
   376
 * @param sound			Name of the sound to precache.
faluco@656
   377
 * @param preload		If preload is true the file will be precached before level startup.
faluco@656
   378
 * @return			True if successfully precached, false otherwise.
faluco@656
   379
 */
faluco@656
   380
native bool:PrecacheSound(const String:sound[], bool:preload=false);
faluco@656
   381
faluco@656
   382
/**
faluco@656
   383
 * Returns if a given sound is precached.
faluco@656
   384
 *
faluco@656
   385
 * @param sound			Name of the sound to check.
faluco@656
   386
 * @return			True if precached, false otherwise.
faluco@656
   387
 */
faluco@656
   388
native bool:IsSoundPrecached(const String:sound[]);
faluco@656
   389
faluco@659
   390
/**
faluco@659
   391
 * Executes a client command on the server without being networked.
faluco@659
   392
 *
faluco@659
   393
 * @param client		Index of the client.
faluco@659
   394
 * @param fmt			Format of the client command.
faluco@659
   395
 * @param ...			Format parameters
faluco@659
   396
 * @noreturn
faluco@659
   397
 * @error				Invalid client index, or client not connected.
faluco@659
   398
 */
faluco@659
   399
native FakeClientCommand(client, const String:fmt[], any:...);
faluco@659
   400
dvander@460
   401
#include <helpers>
dvander@560
   402
#include <entity>