plugins/include/entity.inc
author David Anderson <dvander@alliedmods.net>
Fri Aug 15 05:22:26 2008 +0000 (2008-08-15)
changeset 2226 d10b38524be3
parent 2098 763afb5d7ddf
child 2289 44045ead61cd
permissions -rw-r--r--
Landed sourcepawn-1.2. The big changes:

1) JIT compilation/optimization now occurs per-function, and only when functions are first used. We're now officially a whole-method JIT rather than an AOT compiler (albiet, still a simple JIT). This has two implications: Functions are now much better abstracted internally, and loading a plugin is now much less expensive. If a function contains calls to other functions, THOSE functions are only compiled when they're invoked as well.

2) I've removed debug mode. We always show full backtraces now, as there was a very cheap way to implement this which really cleaned up everything. This is great for a number of reasons -- there's less code, the JIT is better designed, we don't need to relocate debug tables, and best of all we no longer have to tell users to enable debug mode at their own expense.
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     5
 * =============================================================================
ds@1952
     6
 *
ds@1952
     7
 * This file is part of the SourceMod/SourcePawn SDK.
ds@1952
     8
 *
ds@1952
     9
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    11
 * Free Software Foundation.
ds@1952
    12
 * 
ds@1952
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    16
 * details.
ds@1952
    17
 *
ds@1952
    18
 * You should have received a copy of the GNU General Public License along with
ds@1952
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    20
 *
ds@1952
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    28
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    29
 *
ds@1952
    30
 * Version: $Id$
ds@1952
    31
 */
ds@1952
    32
 
ds@1952
    33
#if defined _entity_included
ds@1952
    34
 #endinput
ds@1952
    35
#endif
ds@1952
    36
#define _entity_included
ds@1952
    37
ds@1952
    38
/**
ds@1952
    39
 * Property types for entities.
ds@1952
    40
 */
ds@1952
    41
enum PropType
ds@1952
    42
{
ds@1952
    43
	Prop_Send = 0,	/**< This property is networked. */
ds@1952
    44
	Prop_Data = 1,	/**< This property is for save game data fields. */
ds@1952
    45
};
ds@1952
    46
ds@1952
    47
/**
ds@1952
    48
 * @section For more information on these, see the HL2SDK (public/edict.h)
ds@1952
    49
 */
ds@1952
    50
#define FL_EDICT_CHANGED		(1<<0)	/**< Game DLL sets this when the entity state changes
ds@1952
    51
										 Mutually exclusive with FL_EDICT_PARTIAL_CHANGE. */
ds@1952
    52
#define FL_EDICT_FREE			(1<<1)	/**< this edict if free for reuse */
ds@1952
    53
#define FL_EDICT_FULL			(1<<2)	/**< this is a full server entity */
ds@1952
    54
#define FL_EDICT_FULLCHECK		(0<<0)  /**< call ShouldTransmit() each time, this is a fake flag */
ds@1952
    55
#define FL_EDICT_ALWAYS			(1<<3)	/**< always transmit this entity */
ds@1952
    56
#define FL_EDICT_DONTSEND		(1<<4)	/**< don't transmit this entity */
ds@1952
    57
#define FL_EDICT_PVSCHECK		(1<<5)	/**< always transmit entity, but cull against PVS */
ds@1952
    58
#define FL_EDICT_PENDING_DORMANT_CHECK	(1<<6)
ds@1952
    59
#define FL_EDICT_DIRTY_PVS_INFORMATION	(1<<7)
ds@1952
    60
#define FL_FULL_EDICT_CHANGED		(1<<8)
ds@1952
    61
ds@1952
    62
enum PropFieldType
ds@1952
    63
{
ds@1952
    64
	PropField_Unsupported,		/**< The type is unsupported. */
ds@1952
    65
	PropField_Integer,			/**< Valid for SendProp and Data fields */
ds@1952
    66
	PropField_Float,			/**< Valid for SendProp and Data fields */
ds@1952
    67
	PropField_Entity,			/**< Valid for Data fields only (SendProp shows as int) */
ds@1952
    68
	PropField_Vector,			/**< Valid for SendProp and Data fields */
ds@1952
    69
	PropField_String,			/**< Valid for SendProp and Data fields */
ds@1952
    70
	PropField_String_T,			/**< Valid for Data fields.  Read only.  
ds@1952
    71
									 Note that the size of a string_t is dynamic, and 
ds@1952
    72
									 thus FindDataMapOffs() will return the constant size 
ds@1952
    73
									 of the string_t container (which is 32 bits right now).
ds@1952
    74
								 */
ds@1952
    75
};
ds@1952
    76
ds@1952
    77
/**
ds@1952
    78
 * @endsection
ds@1952
    79
 */
ds@1952
    80
ds@1952
    81
/**
ds@1952
    82
 * Returns the maximum number of entities.
ds@1952
    83
 *
ds@1952
    84
 * @return				Maximum number of entities.
ds@1952
    85
 */
ds@1952
    86
native GetMaxEntities();
ds@1952
    87
ds@1952
    88
/**
ds@1952
    89
 * Returns the number of entities in the server.
ds@1952
    90
 *
ds@1952
    91
 * @return				Number of entities in the server.
ds@1952
    92
 */
ds@1952
    93
native GetEntityCount();
ds@1952
    94
ds@1952
    95
/**
ds@1952
    96
 * Returns whether or not an entity is valid.  Returns false
ds@1952
    97
 * if there is no matching CBaseEntity for this edict index.
ds@1952
    98
 *
ds@1952
    99
 * @param edict			Index of the entity/edict.
ds@1952
   100
 * @return				True if valid, false otherwise.
ds@1952
   101
 */
ds@1952
   102
native bool:IsValidEntity(edict);
ds@1952
   103
ds@1952
   104
/**
ds@1952
   105
 * Returns whether or not an edict index is valid.
ds@1952
   106
 *
ds@1952
   107
 * @param edict			Index of the edict.
ds@1952
   108
 * @return				True if valid, false otherwise.
ds@1952
   109
 */
ds@1952
   110
native bool:IsValidEdict(edict);
ds@1952
   111
ds@1952
   112
/**
ds@1952
   113
 * Returns whether or not an entity is a valid networkable edict.
ds@1952
   114
 *
ds@1952
   115
 * @param edict			Index of the edict.
ds@1952
   116
 * @return				True if networkable, false if invalid or not networkable.
ds@1952
   117
 */
ds@1952
   118
native bool:IsEntNetworkable(edict);
ds@1952
   119
ds@1952
   120
/**
ds@1952
   121
 * Creates a new edict (the basis of a networkable entity)
ds@1952
   122
 *
ds@1952
   123
 * @return				Index of the edict, 0 on failure.
ds@1952
   124
 */
ds@1952
   125
native CreateEdict();
ds@1952
   126
ds@1952
   127
/** 
ds@1952
   128
 * Removes an edict from the world.
ds@1952
   129
 *
ds@1952
   130
 * @param edict			Index of the edict.
ds@1952
   131
 * @noreturn
ds@1952
   132
 * @error				Invalid edict index.
ds@1952
   133
 */
ds@1952
   134
native RemoveEdict(edict);
ds@1952
   135
ds@1952
   136
/**
ds@1952
   137
 * Returns the flags on an edict.  These are not the same as entity flags.
ds@1952
   138
 *
ds@1952
   139
 * @param edict			Index of the entity.
ds@1952
   140
 * @return				Edict flags.
ds@1952
   141
 * @error				Invalid edict index.
ds@1952
   142
 */
ds@1952
   143
native GetEdictFlags(edict);
ds@1952
   144
ds@1952
   145
/**
ds@1952
   146
 * Sets the flags on an edict.  These are not the same as entity flags.
ds@1952
   147
 *
ds@1952
   148
 * @param edict			Index of the entity.
ds@1952
   149
 * @param flags			Flags to set.
ds@1952
   150
 * @noreturn
ds@1952
   151
 * @error				Invalid edict index.
ds@1952
   152
 */
ds@1952
   153
native SetEdictFlags(edict, flags);
ds@1952
   154
ds@1952
   155
/**
ds@1952
   156
 * Retrieves an edict classname.
ds@1952
   157
 *
ds@1952
   158
 * @param edict			Index of the entity.
ds@1952
   159
 * @param clsname		Buffer to store the classname.
ds@1952
   160
 * @param maxlength		Maximum length of the buffer.
ds@1952
   161
 * @return				True on success, false if there is no classname set.
ds@1952
   162
 */
ds@1952
   163
native bool:GetEdictClassname(edict, String:clsname[], maxlength);
ds@1952
   164
ds@1952
   165
/**
ds@1952
   166
 * Retrieves an entity's networkable serverclass name.
ds@1952
   167
 * This is not the same as the classname and is used for networkable state changes.
ds@1952
   168
 *
ds@1952
   169
 * @param edict			Index of the entity.
ds@1952
   170
 * @param clsname		Buffer to store the serverclass name.
ds@1952
   171
 * @param maxlength		Maximum lnegth of the buffer.
ds@1952
   172
 * @return				True on success, false if the edict is not networkable.
ds@1952
   173
 * @error				Invalid edict index.
ds@1952
   174
 */
ds@1952
   175
native bool:GetEntityNetClass(edict, String:clsname[], maxlength);
ds@1952
   176
ds@1952
   177
/**
ds@1952
   178
 * @section Entity offset functions
ds@1952
   179
 *
ds@1952
   180
 * Offsets should be specified in byte distance from the CBaseEntity 
ds@1952
   181
 * structure, not short (double byte) or integer (four byte) multiples.  
ds@1952
   182
 * It is somewhat common practice to use offsets aligned to their final 
ds@1952
   183
 * type, and thus make sure you are not falling to this error in SourceMod.
ds@1952
   184
 * For example, if your "integer-aligned" offset was 119, your byte-aligned
ds@1952
   185
 * offset is 119*4, or 476.
ds@1952
   186
 
ds@1952
   187
 * Specifying incorrect offsets or the incorrect data type for an offset
ds@1952
   188
 * can have fatal consequences.  If you are hardcoding offsets, and the 
ds@1952
   189
 * layout of CBaseEntity does not match, you can easily crash the server.
ds@1952
   190
 *
ds@1952
   191
 * The reasonable bounds for offsets is greater than or equal to 0 and 
ds@1952
   192
 * below 32768.  Offsets out of these bounds will throw an error.  However,
ds@1952
   193
 * this does not represent any real range, it is simply a sanity check for
ds@1952
   194
 * illegal values.  Any range outside of the CBaseEntity structure's private
ds@1952
   195
 * size will cause undefined behaviour or even crash.
ds@1952
   196
 */
ds@1952
   197
 
ds@1952
   198
/**
ds@1952
   199
 * Marks an entity as state changed.  This can be useful if you set an offset 
ds@1952
   200
 * and wish for it to be immediately changed over the network.  By default this 
ds@1952
   201
 * is not done for offset setting functions.  
ds@1952
   202
 *
ds@1952
   203
 * @param edict			Index to the edict.
ds@1952
   204
 * @param offset		Offset to mark as changed.  If 0, 
ds@1952
   205
 *						the entire edict is marked as changed.
ds@1952
   206
 * @noreturn
ds@1952
   207
 * @error				Invalid entity or offset out of bounds.
ds@1952
   208
 */
ds@1952
   209
native ChangeEdictState(edict, offset = 0);
ds@1952
   210
ds@1952
   211
/**
ds@1952
   212
 * Peeks into an entity's object data and retrieves the integer value at 
ds@1952
   213
 * the given offset.
ds@1952
   214
 * 
ds@1952
   215
 * @param entity		Edict index.
ds@1952
   216
 * @param offset		Offset to use.
ds@1952
   217
 * @param size			Number of bytes to read (valid values are 1, 2, or 4).
ds@1952
   218
 * @return				Value at the given memory location.
ds@1952
   219
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   220
 */
ds@1952
   221
native GetEntData(entity, offset, size=4);
ds@1952
   222
ds@1952
   223
/**
ds@1952
   224
 * Peeks into an entity's object data and sets the integer value at 
ds@1952
   225
 * the given offset.
ds@1952
   226
 *
ds@1952
   227
 * @param entity		Edict index.
ds@1952
   228
 * @param offset		Offset to use.
ds@1952
   229
 * @param size			Number of bytes to write (valid values are 1, 2, or 4).
ds@1952
   230
 * @param changeState	If true, change will be sent over the network.
ds@1952
   231
 * @return				Value at the given memory location.
ds@1952
   232
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   233
 * @noreturn
ds@1952
   234
 */
ds@1952
   235
native SetEntData(entity, offset, any:value, size=4, bool:changeState=false);
ds@1952
   236
ds@1952
   237
/**
ds@1952
   238
 * Peeks into an entity's object data and retrieves the float value at 
ds@1952
   239
 * the given offset.
ds@1952
   240
 * 
ds@1952
   241
 * @param entity		Edict index.
ds@1952
   242
 * @param offset		Offset to use.
ds@1952
   243
 * @return				Value at the given memory location.
ds@1952
   244
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   245
 */
ds@1952
   246
native Float:GetEntDataFloat(entity, offset);
ds@1952
   247
ds@1952
   248
/**
ds@1952
   249
 * Peeks into an entity's object data and sets the integer value at 
ds@1952
   250
 * the given offset.
ds@1952
   251
 *
ds@1952
   252
 * @param entity		Edict index.
ds@1952
   253
 * @param offset		Offset to use.
ds@1952
   254
 * @param changeState	If true, change will be sent over the network.
ds@1952
   255
 * @return				Value at the given memory location.
ds@1952
   256
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   257
 * @noreturn
ds@1952
   258
 */
ds@1952
   259
native SetEntDataFloat(entity, offset, Float:value, bool:changeState=false);
ds@1952
   260
ds@1952
   261
/**
ds@1952
   262
 * This function is deprecated.  Use GetEntDataEnt2 instead, for 
ds@1952
   263
 * reasons explained in the notes.
ds@1952
   264
 *
ds@1952
   265
 * Note: This function returns 0 on failure, which may be misleading, 
ds@1952
   266
 * as the number 0 is also used for the world entity index.
ds@1952
   267
 *
ds@1952
   268
 * Note: This function makes no attempt to validate the returned 
ds@1952
   269
 * entity, and in fact, it could be garbage or completely unexpected.
ds@1952
   270
 * 
ds@1952
   271
 * @param entity		Edict index.
ds@1952
   272
 * @param offset		Offset to use.
ds@1952
   273
 * @return				Entity index at the given location, or 0 if none.
ds@1952
   274
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   275
 */
ds@2098
   276
#pragma deprecated Use GetEntDataEnt2() instead.
ds@1952
   277
native GetEntDataEnt(entity, offset);
ds@1952
   278
ds@1952
   279
/**
ds@2098
   280
 * This function is deprecated.   Use SetEntDataEnt2 instead, for 
ds@1952
   281
 * reasons explained in the notes.
ds@1952
   282
 *
ds@1952
   283
 * Note: This function uses 0 as an indicator to unset data, but 
ds@1952
   284
 * 0 is also the world entity index.  Thus, the a property cannot 
ds@1952
   285
 * be set to the world entity using this native.
ds@1952
   286
 * 
ds@1952
   287
 * @param entity		Edict index.
ds@1952
   288
 * @param offset		Offset to use.
ds@1952
   289
 * @param other			Entity index to set, or 0 to clear.
ds@1952
   290
 * @param changeState	If true, change will be sent over the network.
ds@1952
   291
 * @noreturn
ds@1952
   292
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   293
 */
ds@2098
   294
#pragma deprecated Use SetEntDataEnt2() instead.
ds@1952
   295
native SetEntDataEnt(entity, offset, other, bool:changeState=false);
ds@1952
   296
ds@1952
   297
/**
ds@1952
   298
 * Peeks into an entity's object data and retrieves the entity index 
ds@1952
   299
 * at the given offset.
ds@1952
   300
 *
ds@1952
   301
 * Note: This will only work on offsets that are stored as "entity 
ds@1952
   302
 * handles" (which usually looks like m_h* in properties).  These 
ds@1952
   303
 * are not SourceMod Handles, but internal Source structures.
ds@1952
   304
 * 
ds@1952
   305
 * @param entity		Edict index.
ds@1952
   306
 * @param offset		Offset to use.
ds@1952
   307
 * @return				Entity index at the given location.  If there is no entity, 
ds@1952
   308
 *						or the stored entity is invalid, then -1 is returned.
ds@1952
   309
 * @error				Invalid input entity, or offset out of reasonable bounds.
ds@1952
   310
 */
ds@1952
   311
native GetEntDataEnt2(entity, offset);
ds@1952
   312
ds@1952
   313
/**
ds@1952
   314
 * Peeks into an entity's object data and sets the entity index at the 
ds@1952
   315
 * given offset.
ds@1952
   316
 *
ds@1952
   317
 * Note: This will only work on offsets that are stored as "entity 
ds@1952
   318
 * handles" (which usually looks like m_h* in properties).  These 
ds@1952
   319
 * are not SourceMod Handles, but internal Source structures.
ds@1952
   320
 * 
ds@1952
   321
 * @param entity		Edict index.
ds@1952
   322
 * @param offset		Offset to use.
ds@1952
   323
 * @param other			Entity index to set, or -1 to clear.
ds@1952
   324
 * @param changeState	If true, change will be sent over the network.
ds@1952
   325
 * @noreturn
ds@1952
   326
 * @error				Invalid input entity, or offset out of reasonable bounds.
ds@1952
   327
 */
ds@1952
   328
native SetEntDataEnt2(entity, offset, other, bool:changeState=false);
ds@1952
   329
ds@1952
   330
/**
ds@1952
   331
 * Peeks into an entity's object data and retrieves the vector at the 
ds@1952
   332
 * given offset.
ds@1952
   333
 * @note Both a Vector and a QAngle are three floats.  This is a 
ds@1952
   334
 * convenience function and will work with both types.
ds@1952
   335
 * 
ds@1952
   336
 * @param entity		Edict index.
ds@1952
   337
 * @param offset		Offset to use.
ds@1952
   338
 * @param vec			Vector buffer to store data in.
ds@1952
   339
 * @noreturn
ds@1952
   340
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   341
 */
ds@1952
   342
native GetEntDataVector(entity, offset, Float:vec[3]);
ds@1952
   343
ds@1952
   344
/**
ds@1952
   345
 * Peeks into an entity's object data and sets the vector at the given 
ds@1952
   346
 * offset.
ds@1952
   347
 * @note Both a Vector and a QAngle are three floats.  This is a 
ds@1952
   348
 * convenience function and will work with both types.
ds@1952
   349
 * 
ds@1952
   350
 * @param entity		Edict index.
ds@1952
   351
 * @param offset		Offset to use.
ds@1952
   352
 * @param vec			Vector to set.
ds@1952
   353
 * @param changeState	If true, change will be sent over the network.
ds@1952
   354
 * @noreturn
ds@1952
   355
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   356
 */
ds@1952
   357
native SetEntDataVector(entity, offset, const Float:vec[3], bool:changeState=false);
ds@1952
   358
ds@1952
   359
/**
ds@1952
   360
 * Peeks into an entity's object data and retrieves the string at 
ds@1952
   361
 * the given offset.
ds@1952
   362
 * 
ds@1952
   363
 * @param entity		Edict index.
ds@1952
   364
 * @param offset		Offset to use.
ds@1952
   365
 * @param buffer		Destination string buffer.
ds@1952
   366
 * @param maxlen		Maximum length of output string buffer.
ds@1952
   367
 * @return			Number of non-null bytes written.
ds@1952
   368
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   369
 */
ds@1952
   370
native GetEntDataString(entity, offset, String:buffer[], maxlen);
ds@1952
   371
ds@1952
   372
/**
ds@1952
   373
 * Peeks into an entity's object data and sets the string at 
ds@1952
   374
 * the given offset.
ds@1952
   375
 * 
ds@1952
   376
 * @param entity		Edict index.
ds@1952
   377
 * @param offset		Offset to use.
ds@1952
   378
 * @param buffer		String to set.
ds@1952
   379
 * @param maxlen		Maximum length of bytes to write.
ds@1952
   380
 * @param changeState	If true, change will be sent over the network.
ds@1952
   381
 * @return			Number of non-null bytes written.
ds@1952
   382
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   383
 */
ds@1952
   384
native SetEntDataString(entity, offset, const String:buffer[], maxlen, bool:changeState=false);
ds@1952
   385
ds@1952
   386
/**
ds@1952
   387
 * @endsection
ds@1952
   388
 */
ds@1952
   389
ds@1952
   390
/**
ds@1952
   391
 * Given a ServerClass name, finds a networkable send property offset.
ds@1952
   392
 * This information is cached for future calls.
ds@1952
   393
 *
ds@1952
   394
 * Note, this function may return offsets that do not work!
ds@1952
   395
 * If a property is nested beneath a parent object, the resulting offset 
ds@1952
   396
 * will be invalid for direct use with data functions.  Therefore, you 
ds@1952
   397
 * should use FindSendPropInfo() instead.  An example of such a property is 
ds@1952
   398
 * CTFPlayer::DT_LocalPlayer.m_nDisguiseClass on Team Fortress.
ds@1952
   399
 *
ds@1952
   400
 * @param cls			Classname.
ds@1952
   401
 * @param prop			Property name.
ds@1952
   402
 * @return				An offset, or -1 on failure.
ds@1952
   403
 */
ds@1952
   404
native FindSendPropOffs(const String:cls[], const String:prop[]);
ds@1952
   405
ds@1952
   406
/**
ds@1952
   407
 * Given a ServerClass name, finds a networkable send property offset.
ds@1952
   408
 * This information is cached for future calls.
ds@1952
   409
 * 
ds@1952
   410
 * Note: This function will correctly compute nested offsets, unlike 
ds@1952
   411
 * FindSendPropOffs().  YOU SHOULD NOT use this function to self-compute 
ds@1952
   412
 * nested offsets.  For example, it is okay to add indexes for arrays, 
ds@1952
   413
 * but not to add DT_LocalPlayer to m_nDisguiseClass.
ds@1952
   414
 *
ds@1952
   415
 * @param cls			Classname.
ds@1952
   416
 * @param prop			Property name.
ds@1952
   417
 * @param type			Optional parameter to store the type.
ds@1952
   418
 * @param num_bits		Optional parameter to store the number of bits the field 
ds@1952
   419
 *						uses, if applicable (otherwise 0 is stored).  The number 
ds@1952
   420
 *						of bits varies for integers and floats, and is always 0 
ds@1952
   421
 * 						for strings.
ds@1952
   422
 * @param local_offset	Optional parameter to store the local offset, as 
ds@1952
   423
 *						FindSendPropOffs() would return.
ds@1952
   424
 * @return				On success, returns an absolutely computed offset.
ds@1952
   425
 *						If no offset is available, 0 is returned.
ds@1952
   426
 *						If the property is not found, -1 is returned.
ds@1952
   427
 */
ds@1952
   428
native FindSendPropInfo(const String:cls[], 
ds@1952
   429
						const String:prop[], 
ds@1952
   430
						&PropFieldType:type=PropFieldType:0,
ds@1952
   431
						&num_bits=0,
ds@1952
   432
						&local_offset=0);
ds@1952
   433
ds@1952
   434
/**
ds@1952
   435
 * Given an entity, finds a datamap property offset.
ds@1952
   436
 * This information is cached for future calls.
ds@1952
   437
 *
ds@1952
   438
 * @param entity		Entity index.
ds@1952
   439
 * @param prop			Property name.
ds@1952
   440
 * @param type			Optional parameter to store the type.
ds@1952
   441
 * @param num_bits		Optional parameter to store the number of bits the field 
ds@1952
   442
 *						uses.  The bit count will either be 1 (for boolean) or 
ds@1952
   443
 *						divisible by 8 (including 0 if unknown).
ds@1952
   444
 * @return				An offset, or -1 on failure.
ds@1952
   445
 */
ds@1952
   446
native FindDataMapOffs(entity, 
ds@1952
   447
					   const String:prop[],
ds@1952
   448
					   &PropFieldType:type=PropFieldType:0,
ds@1952
   449
					   &num_bits=0);
ds@1952
   450
ds@1952
   451
/**
ds@1952
   452
 * Wrapper function for finding a send property for a particular entity.
ds@1952
   453
 *
ds@1952
   454
 * @param ent			Entity index.
ds@1952
   455
 * @param prop			Property name.
ds@1952
   456
 * @param actual		Defaults to false for backwards compatibility.
ds@1952
   457
 *						If true, the newer FindSendPropInfo() function 
ds@1952
   458
 *						is used instead.
ds@1952
   459
 * @return				An offset, or -1 on failure.
ds@1952
   460
 */
ds@1952
   461
stock GetEntSendPropOffs(ent, const String:prop[], bool:actual=false)
ds@1952
   462
{
ds@1952
   463
	decl String:cls[64];
ds@1952
   464
	
ds@1952
   465
	if (!GetEntityNetClass(ent, cls, sizeof(cls)))
ds@1952
   466
	{
ds@1952
   467
		return -1;
ds@1952
   468
	}
ds@1952
   469
	
ds@1952
   470
	if (actual)
ds@1952
   471
	{
ds@1952
   472
		return FindSendPropInfo(cls, prop);
ds@1952
   473
	}
ds@1952
   474
	else
ds@1952
   475
	{
ds@1952
   476
		return FindSendPropOffs(cls, prop);
ds@1952
   477
	}
ds@1952
   478
}
ds@1952
   479
ds@1952
   480
/**
ds@1952
   481
 * Retrieves an integer value from an entity's property.
ds@1952
   482
 *
ds@1952
   483
 * This function is considered safer and more robust over GetEntData, 
ds@1952
   484
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   485
 * very minor performance hit from this.
ds@1952
   486
 * 
ds@1952
   487
 * @param entity		Entity/edict index.
ds@1952
   488
 * @param type			Property type.
ds@1952
   489
 * @param prop			Property name.
ds@1952
   490
 * @param size			Number of bytes to write (valid values are 1, 2, or 4).
ds@1952
   491
 *						This value is auto-detected, and the size parameter is 
ds@1952
   492
 *						only used as a fallback in case detection fails.
ds@1952
   493
 * @return				Value at the given property offset.
ds@1952
   494
 * @error				Invalid entity or property not found.
ds@1952
   495
 */
ds@1952
   496
native GetEntProp(entity, PropType:type, const String:prop[], size=4);
ds@1952
   497
ds@1952
   498
/**
ds@1952
   499
 * Sets an integer value in an entity's property.
ds@1952
   500
 *
ds@1952
   501
 * This function is considered safer and more robust over SetEntData, 
ds@1952
   502
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   503
 * very minor performance hit from this.
ds@1952
   504
 * 
ds@1952
   505
 * @param entity		Entity/edict index.
ds@1952
   506
 * @param type			Property type.
ds@1952
   507
 * @param prop			Property name.
ds@1952
   508
 * @param size			Number of bytes to write (valid values are 1, 2, or 4).
ds@1952
   509
 *						This value is auto-detected, and the size parameter is 
ds@1952
   510
 *						only used as a fallback in case detection fails.
ds@1952
   511
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   512
 * @noreturn
ds@1952
   513
 */
ds@1952
   514
native SetEntProp(entity, PropType:type, const String:prop[], any:value, size=4);
ds@1952
   515
ds@1952
   516
/**
ds@1952
   517
 * Retrieves a float value from an entity's property.
ds@1952
   518
 *
ds@1952
   519
 * This function is considered safer and more robust over GetEntDataFloat, 
ds@1952
   520
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   521
 * very minor performance hit from this.
ds@1952
   522
 * 
ds@1952
   523
 * @param entity		Entity/edict index.
ds@1952
   524
 * @param type			Property type.
ds@1952
   525
 * @param prop			Property name.
ds@1952
   526
 * @return				Value at the given property offset.
ds@1952
   527
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   528
 */
ds@1952
   529
native Float:GetEntPropFloat(entity, PropType:type, const String:prop[]);
ds@1952
   530
ds@1952
   531
/**
ds@1952
   532
 * Sets a float value in an entity's property.
ds@1952
   533
 *
ds@1952
   534
 * This function is considered safer and more robust over SetEntDataFloat, 
ds@1952
   535
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   536
 * very minor performance hit from this.
ds@1952
   537
 * 
ds@1952
   538
 * @param entity		Entity/edict index.
ds@1952
   539
 * @param type			Property type.
ds@1952
   540
 * @param prop			Property name.
ds@1952
   541
 * @param value			Value to set.
ds@1952
   542
 * @noreturn
ds@1952
   543
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   544
 */
ds@1952
   545
native SetEntPropFloat(entity, PropType:type, const String:prop[], Float:value);
ds@1952
   546
ds@1952
   547
/**
ds@1952
   548
 * Retrieves an entity index from an entity's property.
ds@1952
   549
 *
ds@1952
   550
 * This function is considered safer and more robust over GetEntDataEnt*, 
ds@1952
   551
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   552
 * very minor performance hit from this.
ds@1952
   553
 * 
ds@1952
   554
 * @param entity		Entity/edict index.
ds@1952
   555
 * @param type			Property type.
ds@1952
   556
 * @param prop			Property name.
ds@1952
   557
 * @return				Entity index at the given property.
ds@1952
   558
 *						If there is no entity, or the entity is not valid, 
ds@1952
   559
 *						then -1 is returned.
ds@1952
   560
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   561
 */
ds@1952
   562
native GetEntPropEnt(entity, PropType:type, const String:prop[]);
ds@1952
   563
ds@1952
   564
/**
ds@1952
   565
 * Sets an entity index in an entity's property.
ds@1952
   566
 *
ds@1952
   567
 * This function is considered safer and more robust over SetEntDataEnt*, 
ds@1952
   568
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   569
 * very minor performance hit from this.
ds@1952
   570
 * 
ds@1952
   571
 * @param entity		Entity/edict index.
ds@1952
   572
 * @param type			Property type.
ds@1952
   573
 * @param prop			Property name.
ds@1952
   574
 * @param other			Entity index to set, or -1 to unset.
ds@1952
   575
 * @noreturn
ds@1952
   576
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   577
 */
ds@1952
   578
native SetEntPropEnt(entity, PropType:type, const String:prop[], other);
ds@1952
   579
ds@1952
   580
/**
ds@1952
   581
 * Retrieves a vector of floats from an entity, given a named network property.
ds@1952
   582
 *
ds@1952
   583
 * This function is considered safer and more robust over GetEntDataVector, 
ds@1952
   584
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   585
 * very minor performance hit from this.
ds@1952
   586
 * 
ds@1952
   587
 * @param entity		Entity/edict index.
ds@1952
   588
 * @param type			Property type.
ds@1952
   589
 * @param prop			Property name.
ds@1952
   590
 * @param vec			Vector buffer to store data in.
ds@1952
   591
 * @noreturn
ds@1952
   592
 * @error				Invalid entity, property not found, or property not 
ds@1952
   593
 *						actually a vector data type.
ds@1952
   594
 */
ds@1952
   595
native GetEntPropVector(entity, PropType:type, const String:prop[], Float:vec[3]);
ds@1952
   596
ds@1952
   597
/**
ds@1952
   598
 * Sets a vector of floats in an entity, given a named network property.
ds@1952
   599
 *
ds@1952
   600
 * This function is considered safer and more robust over SetEntDataVector, 
ds@1952
   601
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   602
 * very minor performance hit from this.
ds@1952
   603
 * 
ds@1952
   604
 * @param entity		Entity/edict index.
ds@1952
   605
 * @param type			Property type.
ds@1952
   606
 * @param prop			Property name.
ds@1952
   607
 * @param vec			Vector to set.
ds@1952
   608
 * @noreturn
ds@1952
   609
 * @error				Invalid entity, property not found, or property not 
ds@1952
   610
 *						actually a vector data type.
ds@1952
   611
 */
ds@1952
   612
native SetEntPropVector(entity, PropType:type, const String:prop[], const Float:vec[3]);
ds@1952
   613
ds@1952
   614
/**
ds@1952
   615
 * Gets a network property as a string.
ds@1952
   616
 * 
ds@1952
   617
 * @param entity		Edict index.
ds@1952
   618
 * @param type			Property type.
ds@1952
   619
 * @param prop			Property to use.
ds@1952
   620
 * @param buffer		Destination string buffer.
ds@1952
   621
 * @param maxlen		Maximum length of output string buffer.		
ds@1952
   622
 * @return				Number of non-null bytes written.
ds@1952
   623
 * @error				Invalid entity, offset out of reasonable bounds, or property is not a valid string.
ds@1952
   624
 */
ds@1952
   625
native GetEntPropString(entity, PropType:type, const String:prop[], String:buffer[], maxlen);
ds@1952
   626
ds@1952
   627
/**
ds@1952
   628
 * Sets a network property as a string.
ds@1952
   629
 *
ds@1952
   630
 * This cannot set property fields of type PropField_String_T (such as "m_target").
ds@1952
   631
 * To set such fields, you should use DispatchKeyValue() from SDKTools.
ds@1952
   632
 * 
ds@1952
   633
 * @param entity		Edict index.
ds@1952
   634
 * @param type			Property type.
ds@1952
   635
 * @param prop			Property to use.
ds@1952
   636
 * @param buffer		String to set.		
ds@1952
   637
 * @return				Number of non-null bytes written.
ds@1952
   638
 * @error				Invalid entity, offset out of reasonable bounds, or property is not a valid string.
ds@1952
   639
 */
ds@1952
   640
native SetEntPropString(entity, PropType:type, const String:prop[], const String:buffer[]);
ds@1952
   641
ds@1952
   642
/**
ds@1952
   643
 * Copies an array of cells from an entity at a given offset.
ds@1952
   644
 *
ds@1952
   645
 * @param entity		Entity index.
ds@1952
   646
 * @param offset		Offset to use.
ds@1952
   647
 * @param array			Array to read into.
ds@1952
   648
 * @param arraySize		Number of values to read.
ds@1952
   649
 * @param dataSize		Size of each value in bytes (1, 2, or 4).
ds@1952
   650
 * @noreturn
ds@1952
   651
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   652
 */
ds@1952
   653
stock GetEntDataArray(entity, offset, array[], arraySize, dataSize=4)
ds@1952
   654
{
ds@1952
   655
	for (new i=0; i<arraySize; i++)
ds@1952
   656
	{
ds@1952
   657
		array[i] = GetEntData(entity, offset + i*dataSize, dataSize)
ds@1952
   658
	}
ds@1952
   659
}
ds@1952
   660
ds@1952
   661
/**
ds@1952
   662
 * Copies an array of cells to an entity at a given offset.
ds@1952
   663
 *
ds@1952
   664
 * @param entity		Entity index.
ds@1952
   665
 * @param offset		Offset to use.
ds@1952
   666
 * @param array			Array of values to copy.
ds@1952
   667
 * @param arraySize		Number of values to copy.
ds@1952
   668
 * @param dataSize		Size of each value in bytes (1, 2, or 4).
ds@1952
   669
 * @param changeState	True to set the network state as changed; false otherwise.
ds@1952
   670
 * @noreturn
ds@1952
   671
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   672
 */
ds@1952
   673
stock SetEntDataArray(entity, offset, const array[], arraySize, dataSize=4, bool:changeState=false)
ds@1952
   674
{
ds@1952
   675
	for (new i=0; i<arraySize; i++)
ds@1952
   676
	{
ds@1952
   677
		SetEntData(entity, offset + i*dataSize, array[i], dataSize, changeState);
ds@1952
   678
	}
ds@1952
   679
}