plugins/include/sourcemod.inc
author Scott Ehlert <ds@alliedmods.net>
Wed Jun 06 20:42:46 2007 +0000 (2007-06-06)
changeset 891 30343d215489
parent 886 649c859c2272
child 898 f8ff0a7cd037
permissions -rw-r--r--
Changed a few natives/stocks that should have used IsClientInGame() rather than IsClientConnected()
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>
ds@873
    35
#include <string>
dvander@429
    36
#include <handles>
dvander@601
    37
#include <functions>
ds@873
    38
#include <files>
dvander@643
    39
#include <timers>
ds@873
    40
#include <admin>
dvander@868
    41
#include <dbi>
ds@873
    42
#include <sorting>
ds@873
    43
#include <halflife>
ds@873
    44
#include <clients>
ds@873
    45
#include <console>
ds@873
    46
#include <events>
ds@873
    47
#include <bitbuffer>
ds@873
    48
#include <usermessages>
ds@873
    49
#include <menus>
faluco@682
    50
dvander@429
    51
/**
dvander@429
    52
 * Declare this as a struct in your plugin to expose its information.
dvander@429
    53
 * Example:
dvander@429
    54
 *
dvander@429
    55
 * public Plugin:myinfo =
dvander@429
    56
 * {
dvander@429
    57
 *    name = "My Plugin",
dvander@429
    58
 *    //etc
dvander@429
    59
 * };
dvander@429
    60
 */
dvander@429
    61
public Plugin:myinfo;
dvander@429
    62
 
dvander@429
    63
/**
dvander@429
    64
 * Called when the plugin is fully initialized and all known external references are resolved.
dvander@429
    65
 * This is called even if the plugin type is "private."
dvander@619
    66
 * @note Errors in this function will cause the plugin to stop running.
dvander@429
    67
 *
dvander@429
    68
 * @noreturn
dvander@429
    69
 */
dvander@536
    70
forward OnPluginStart();
dvander@429
    71
 
dvander@429
    72
/**
dvander@429
    73
 *   Called before OnPluginStart, in case the plugin wants to check for load failure.
dvander@429
    74
 * This is called even if the plugin type is "private."  Any natives from modules are 
dvander@429
    75
 * not available at this point.  Thus, this forward should only be used for explicit 
dvander@429
    76
 * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
dvander@429
    77
 * 
dvander@619
    78
 * @note It is not safe to call externally resolved natives until OnPluginStart().
dvander@619
    79
 * @note Any sort of RTE in this function will cause the plugin to fail loading.
dvander@429
    80
 *
dvander@429
    81
 * @param myself	Handle to the plugin.
dvander@429
    82
 * @param late		Whether or not the plugin was loaded "late" (after map load).
dvander@429
    83
 * @param error		Error message buffer in case load failed.
dvander@429
    84
 * @param err_max	Maximum number of characters for error message buffer.
dvander@429
    85
 * @return			True if load success, false otherwise.
dvander@429
    86
 */
dvander@429
    87
forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
dvander@429
    88
dvander@429
    89
/**
dvander@429
    90
 * Called when the plugin is about to be unloaded.
dvander@429
    91
 *
dvander@429
    92
 * @noreturn
dvander@429
    93
 */
dvander@429
    94
forward OnPluginEnd();
dvander@429
    95
dvander@429
    96
/**
dvander@429
    97
 * Called when the plugin's pause status is changing.
dvander@429
    98
 *
ds@475
    99
 * @param pause			True if the plugin is being paused, false otherwise.
dvander@429
   100
 * @noreturn
dvander@429
   101
 */
dvander@429
   102
forward OnPluginPauseChange(bool:pause);
dvander@429
   103
dvander@429
   104
/**
dvander@531
   105
 * Called before every server frame.  Note that you should avoid
dvander@531
   106
 * doing expensive computations here, and you should declare large
dvander@531
   107
 * local arrays using 'decl' instead of 'new'.
dvander@531
   108
 */
dvander@531
   109
forward OnGameFrame();
dvander@531
   110
dvander@531
   111
/**
dvander@717
   112
 * Called when the map is loaded.
dvander@717
   113
 *
dvander@723
   114
 * @note This used to be OnServerLoad(), which is now deprecated.
dvander@717
   115
 * Plugins still using the old forward will work.
dvander@643
   116
 */
dvander@717
   117
forward OnMapStart();
dvander@643
   118
dvander@643
   119
/**
dvander@718
   120
 * Called right before a map ends.
dvander@718
   121
 */
dvander@718
   122
forward OnMapEnd();
dvander@718
   123
dvander@718
   124
/**
dvander@723
   125
 * Called when the map has loaded and the servercfgfile has finished
dvander@723
   126
 * executing.  This is usually 'server.cfg' but most mods allow it to
dvander@723
   127
 * be set via 'servercfgfile'.  
dvander@723
   128
 *
dvander@723
   129
 * @note If server.cfg is executed more than once per map, this forward
dvander@723
   130
 * will only be called the first time (per map).
dvander@849
   131
 * @note It is not guaranteed that this will be called on all mods. If
dvander@849
   132
 * a mod does not appear to support it, please file a SourceMod bug report.
dvander@723
   133
 */
dvander@723
   134
forward OnServerCfg();
dvander@723
   135
dvander@723
   136
/**
dvander@536
   137
 * Returns the calling plugin's Handle.
dvander@536
   138
 *
dvander@536
   139
 * @return				Handle of the calling plugin.
dvander@536
   140
 */
dvander@536
   141
native Handle:GetMyHandle();
dvander@536
   142
dvander@618
   143
/**
dvander@618
   144
 * Returns an iterator that can be used to search through plugins.
dvander@618
   145
 *
dvander@618
   146
 * @return				Handle to iterate with.  Must be closed via 
dvander@618
   147
 * 						CloseHandle().
dvander@618
   148
 * @error				Invalid Handle.
dvander@618
   149
 */
dvander@618
   150
native Handle:GetPluginIterator();
dvander@618
   151
dvander@618
   152
/**
dvander@618
   153
 * Returns whether there are more plugins available in the iterator.
dvander@618
   154
 *
dvander@618
   155
 * @param iter			Handle to the plugin iterator.
dvander@618
   156
 * @return				True on more plugins, false otherwise.
dvander@618
   157
 * @error				Invalid Handle.
dvander@618
   158
 */
dvander@618
   159
native bool:MorePlugins(Handle:iter);
dvander@618
   160
dvander@618
   161
/**
dvander@618
   162
 * Returns the current plugin in the iterator and advances the iterator.
dvander@618
   163
 *
dvander@618
   164
 * @param iter			Handle to the plugin iterator.
dvander@618
   165
 * @return				Current plugin the iterator is at, before
dvander@618
   166
 *						the iterator is advanced.
dvander@618
   167
 * @error				Invalid Handle.
dvander@618
   168
 */
dvander@618
   169
native Handle:ReadPlugin(Handle:iter);
dvander@618
   170
dvander@618
   171
/**
dvander@618
   172
 * Returns a plugin's status.
dvander@618
   173
 *
dvander@618
   174
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   175
 * @return				Status code for the plugin.
dvander@618
   176
 * @error				Invalid Handle.
dvander@618
   177
 */
dvander@618
   178
native PluginStatus:GetPluginStatus(Handle:plugin);
dvander@618
   179
dvander@618
   180
/**
dvander@618
   181
 * Retrieves a plugin's file name relative to the plugins folder.
dvander@618
   182
 *
dvander@618
   183
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   184
 * @param buffer		Buffer to the store the file name.
dvander@618
   185
 * @param maxlength		Maximum length of the name buffer.
dvander@618
   186
 * @noreturn
dvander@618
   187
 * @error				Invalid Handle.
dvander@618
   188
 */
dvander@618
   189
native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
dvander@618
   190
dvander@618
   191
/**
dvander@618
   192
 * Retrieves whether or not a plugin is being debugged.
dvander@618
   193
 *
dvander@618
   194
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   195
 * @return				True if being debugged, false otherwise.
dvander@618
   196
 * @error				Invalid Handle.
dvander@618
   197
 */
dvander@618
   198
native bool:IsPluginDebugging(Handle:hndl);
dvander@618
   199
dvander@618
   200
/**
dvander@618
   201
 * Retrieves a plugin's public info.
dvander@618
   202
 *
dvander@618
   203
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
dvander@618
   204
 * @param info			Plugin info property to retrieve.
dvander@618
   205
 * @param buffer		Buffer to store info in.
dvander@618
   206
 * @param maxlength		Maximum length of buffer.
dvander@618
   207
 * @return				True on success, false if property is not available.
dvander@618
   208
 * @error				Invalid Handle.
dvander@618
   209
 */
dvander@618
   210
native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
dvander@560
   211
dvander@560
   212
/**
dvander@837
   213
 * Causes the plugin to enter a failed state.  An error will be thrown and
dvander@837
   214
 * the plugin will be paused until it is unloaded or reloaded.
dvander@837
   215
 *
dvander@837
   216
 * @param string		Message to print.
dvander@837
   217
 * @noreturn
dvander@838
   218
 * @error				Always throws SP_ERROR_ABORT.
dvander@837
   219
 */
dvander@837
   220
native SetFailState(const String:string[]);
dvander@837
   221
dvander@837
   222
/**
dvander@560
   223
 * Aborts the current callback and throws an error.  This function
dvander@560
   224
 * does not return in that no code is executed following it.
dvander@560
   225
 *
dvander@560
   226
 * @param format		String format.
dvander@560
   227
 * @param ...			Format arguments.
dvander@560
   228
 * @noreturn
dvander@560
   229
 * @error				Always!
dvander@560
   230
 */
ds@634
   231
native ThrowError(const String:fmt[], any:...);
dvander@560
   232
dvander@536
   233
/**
dvander@429
   234
 * Logs a plugin message to the SourceMod logs.
dvander@429
   235
 *
ds@475
   236
 * @param format		String format.
ds@475
   237
 * @param ...			Format arguments.
dvander@429
   238
 * @noreturn
dvander@429
   239
 */
ds@634
   240
native LogMessage(const String:format[], any:...);
dvander@429
   241
dvander@429
   242
/**
dvander@429
   243
 * Logs a plugin error 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 LogError(const String:format[], any:...);
dvander@460
   250
dvander@530
   251
/**
dvander@595
   252
 * Gets the system time as a unix timestamp.
dvander@595
   253
 *
dvander@595
   254
 * @param bigStamp		Optional array to store the 64bit timestamp in.
dvander@595
   255
 * @return				32bit timestamp (number of seconds since unix epoch).
dvander@595
   256
 */
dvander@595
   257
native GetTime(bigStamp[2]={0,0});
dvander@595
   258
dvander@595
   259
/**
faluco@703
   260
 * Loads a game config file.
faluco@703
   261
 *
faluco@703
   262
 * @param file			File to load.  The path must be relative to the 'gamedata' folder under the config folder 
faluco@703
   263
 *					and the extension should be omitted.
faluco@703
   264
 * @return			A handle to the game config file or INVALID_HANDLE in failure.
faluco@703
   265
 */
faluco@703
   266
native Handle:LoadGameConfigFile(const String:file[]);
faluco@703
   267
faluco@703
   268
/**
faluco@703
   269
 * Returns an offset value.
faluco@703
   270
 *
faluco@703
   271
 * @param gc			Game config handle.
faluco@703
   272
 * @param key			Key to retrieve from the offset section.
faluco@703
   273
 * @return			An offset, or -1 on failure.
faluco@703
   274
 */
faluco@703
   275
native GameConfGetOffset(Handle:gc, const String:key[]);
faluco@703
   276
faluco@703
   277
/**
faluco@703
   278
 * Gets the value of a key from the "Keys" section.
faluco@703
   279
 *
faluco@703
   280
 * @param gc			Game config handle.
faluco@703
   281
 * @param key			Key to retrieve from the Keys section.
faluco@703
   282
 * @param buffer		Destination string buffer.
faluco@703
   283
 * @param maxlen		Maximum length of output string buffer.
dvander@886
   284
 * @return				True if key existed, false otherwise.
faluco@703
   285
 */
faluco@703
   286
native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
faluco@703
   287
dvander@886
   288
/**
dvander@886
   289
 * Returns the operating system's "tick count," which is a number of 
dvander@886
   290
 * milliseconds since the operating system loaded.  This can be used
dvander@886
   291
 * for basic benchmarks.
dvander@886
   292
 *
dvander@886
   293
 * @return				Tick count in milliseconds.
dvander@886
   294
 */
dvander@886
   295
native GetSysTickCount();
dvander@886
   296
dvander@460
   297
#include <helpers>
dvander@560
   298
#include <entity>