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