plugins/include/entity.inc
author David Anderson <dvander@alliedmods.net>
Sun Apr 13 06:06:27 2008 +0000 (2008-04-13)
changeset 1999 63aafc6ff212
parent 1952 b7aa2b626807
child 2098 763afb5d7ddf
permissions -rw-r--r--
added amb1538 - adt_stack
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@1952
   276
native GetEntDataEnt(entity, offset);
ds@1952
   277
ds@1952
   278
/**
ds@1952
   279
 * This function is deprecated.   Use GetEntDataEnt2 instead, for 
ds@1952
   280
 * reasons explained in the notes.
ds@1952
   281
 *
ds@1952
   282
 * Note: This function uses 0 as an indicator to unset data, but 
ds@1952
   283
 * 0 is also the world entity index.  Thus, the a property cannot 
ds@1952
   284
 * be set to the world entity using this native.
ds@1952
   285
 * 
ds@1952
   286
 * @param entity		Edict index.
ds@1952
   287
 * @param offset		Offset to use.
ds@1952
   288
 * @param other			Entity index to set, or 0 to clear.
ds@1952
   289
 * @param changeState	If true, change will be sent over the network.
ds@1952
   290
 * @noreturn
ds@1952
   291
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   292
 */
ds@1952
   293
native SetEntDataEnt(entity, offset, other, bool:changeState=false);
ds@1952
   294
ds@1952
   295
/**
ds@1952
   296
 * Peeks into an entity's object data and retrieves the entity index 
ds@1952
   297
 * at the given offset.
ds@1952
   298
 *
ds@1952
   299
 * Note: This will only work on offsets that are stored as "entity 
ds@1952
   300
 * handles" (which usually looks like m_h* in properties).  These 
ds@1952
   301
 * are not SourceMod Handles, but internal Source structures.
ds@1952
   302
 * 
ds@1952
   303
 * @param entity		Edict index.
ds@1952
   304
 * @param offset		Offset to use.
ds@1952
   305
 * @return				Entity index at the given location.  If there is no entity, 
ds@1952
   306
 *						or the stored entity is invalid, then -1 is returned.
ds@1952
   307
 * @error				Invalid input entity, or offset out of reasonable bounds.
ds@1952
   308
 */
ds@1952
   309
native GetEntDataEnt2(entity, offset);
ds@1952
   310
ds@1952
   311
/**
ds@1952
   312
 * Peeks into an entity's object data and sets the entity index at the 
ds@1952
   313
 * given offset.
ds@1952
   314
 *
ds@1952
   315
 * Note: This will only work on offsets that are stored as "entity 
ds@1952
   316
 * handles" (which usually looks like m_h* in properties).  These 
ds@1952
   317
 * are not SourceMod Handles, but internal Source structures.
ds@1952
   318
 * 
ds@1952
   319
 * @param entity		Edict index.
ds@1952
   320
 * @param offset		Offset to use.
ds@1952
   321
 * @param other			Entity index to set, or -1 to clear.
ds@1952
   322
 * @param changeState	If true, change will be sent over the network.
ds@1952
   323
 * @noreturn
ds@1952
   324
 * @error				Invalid input entity, or offset out of reasonable bounds.
ds@1952
   325
 */
ds@1952
   326
native SetEntDataEnt2(entity, offset, other, bool:changeState=false);
ds@1952
   327
ds@1952
   328
/**
ds@1952
   329
 * Peeks into an entity's object data and retrieves the vector at the 
ds@1952
   330
 * given offset.
ds@1952
   331
 * @note Both a Vector and a QAngle are three floats.  This is a 
ds@1952
   332
 * convenience function and will work with both types.
ds@1952
   333
 * 
ds@1952
   334
 * @param entity		Edict index.
ds@1952
   335
 * @param offset		Offset to use.
ds@1952
   336
 * @param vec			Vector buffer to store data in.
ds@1952
   337
 * @noreturn
ds@1952
   338
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   339
 */
ds@1952
   340
native GetEntDataVector(entity, offset, Float:vec[3]);
ds@1952
   341
ds@1952
   342
/**
ds@1952
   343
 * Peeks into an entity's object data and sets the vector at the given 
ds@1952
   344
 * offset.
ds@1952
   345
 * @note Both a Vector and a QAngle are three floats.  This is a 
ds@1952
   346
 * convenience function and will work with both types.
ds@1952
   347
 * 
ds@1952
   348
 * @param entity		Edict index.
ds@1952
   349
 * @param offset		Offset to use.
ds@1952
   350
 * @param vec			Vector to set.
ds@1952
   351
 * @param changeState	If true, change will be sent over the network.
ds@1952
   352
 * @noreturn
ds@1952
   353
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   354
 */
ds@1952
   355
native SetEntDataVector(entity, offset, const Float:vec[3], bool:changeState=false);
ds@1952
   356
ds@1952
   357
/**
ds@1952
   358
 * Peeks into an entity's object data and retrieves the string at 
ds@1952
   359
 * the given offset.
ds@1952
   360
 * 
ds@1952
   361
 * @param entity		Edict index.
ds@1952
   362
 * @param offset		Offset to use.
ds@1952
   363
 * @param buffer		Destination string buffer.
ds@1952
   364
 * @param maxlen		Maximum length of output string buffer.
ds@1952
   365
 * @return			Number of non-null bytes written.
ds@1952
   366
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   367
 */
ds@1952
   368
native GetEntDataString(entity, offset, String:buffer[], maxlen);
ds@1952
   369
ds@1952
   370
/**
ds@1952
   371
 * Peeks into an entity's object data and sets the string at 
ds@1952
   372
 * the given offset.
ds@1952
   373
 * 
ds@1952
   374
 * @param entity		Edict index.
ds@1952
   375
 * @param offset		Offset to use.
ds@1952
   376
 * @param buffer		String to set.
ds@1952
   377
 * @param maxlen		Maximum length of bytes to write.
ds@1952
   378
 * @param changeState	If true, change will be sent over the network.
ds@1952
   379
 * @return			Number of non-null bytes written.
ds@1952
   380
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   381
 */
ds@1952
   382
native SetEntDataString(entity, offset, const String:buffer[], maxlen, bool:changeState=false);
ds@1952
   383
ds@1952
   384
/**
ds@1952
   385
 * @endsection
ds@1952
   386
 */
ds@1952
   387
ds@1952
   388
/**
ds@1952
   389
 * Given a ServerClass name, finds a networkable send property offset.
ds@1952
   390
 * This information is cached for future calls.
ds@1952
   391
 *
ds@1952
   392
 * Note, this function may return offsets that do not work!
ds@1952
   393
 * If a property is nested beneath a parent object, the resulting offset 
ds@1952
   394
 * will be invalid for direct use with data functions.  Therefore, you 
ds@1952
   395
 * should use FindSendPropInfo() instead.  An example of such a property is 
ds@1952
   396
 * CTFPlayer::DT_LocalPlayer.m_nDisguiseClass on Team Fortress.
ds@1952
   397
 *
ds@1952
   398
 * @param cls			Classname.
ds@1952
   399
 * @param prop			Property name.
ds@1952
   400
 * @return				An offset, or -1 on failure.
ds@1952
   401
 */
ds@1952
   402
native FindSendPropOffs(const String:cls[], const String:prop[]);
ds@1952
   403
ds@1952
   404
/**
ds@1952
   405
 * Given a ServerClass name, finds a networkable send property offset.
ds@1952
   406
 * This information is cached for future calls.
ds@1952
   407
 * 
ds@1952
   408
 * Note: This function will correctly compute nested offsets, unlike 
ds@1952
   409
 * FindSendPropOffs().  YOU SHOULD NOT use this function to self-compute 
ds@1952
   410
 * nested offsets.  For example, it is okay to add indexes for arrays, 
ds@1952
   411
 * but not to add DT_LocalPlayer to m_nDisguiseClass.
ds@1952
   412
 *
ds@1952
   413
 * @param cls			Classname.
ds@1952
   414
 * @param prop			Property name.
ds@1952
   415
 * @param type			Optional parameter to store the type.
ds@1952
   416
 * @param num_bits		Optional parameter to store the number of bits the field 
ds@1952
   417
 *						uses, if applicable (otherwise 0 is stored).  The number 
ds@1952
   418
 *						of bits varies for integers and floats, and is always 0 
ds@1952
   419
 * 						for strings.
ds@1952
   420
 * @param local_offset	Optional parameter to store the local offset, as 
ds@1952
   421
 *						FindSendPropOffs() would return.
ds@1952
   422
 * @return				On success, returns an absolutely computed offset.
ds@1952
   423
 *						If no offset is available, 0 is returned.
ds@1952
   424
 *						If the property is not found, -1 is returned.
ds@1952
   425
 */
ds@1952
   426
native FindSendPropInfo(const String:cls[], 
ds@1952
   427
						const String:prop[], 
ds@1952
   428
						&PropFieldType:type=PropFieldType:0,
ds@1952
   429
						&num_bits=0,
ds@1952
   430
						&local_offset=0);
ds@1952
   431
ds@1952
   432
/**
ds@1952
   433
 * Given an entity, finds a datamap property offset.
ds@1952
   434
 * This information is cached for future calls.
ds@1952
   435
 *
ds@1952
   436
 * @param entity		Entity index.
ds@1952
   437
 * @param prop			Property name.
ds@1952
   438
 * @param type			Optional parameter to store the type.
ds@1952
   439
 * @param num_bits		Optional parameter to store the number of bits the field 
ds@1952
   440
 *						uses.  The bit count will either be 1 (for boolean) or 
ds@1952
   441
 *						divisible by 8 (including 0 if unknown).
ds@1952
   442
 * @return				An offset, or -1 on failure.
ds@1952
   443
 */
ds@1952
   444
native FindDataMapOffs(entity, 
ds@1952
   445
					   const String:prop[],
ds@1952
   446
					   &PropFieldType:type=PropFieldType:0,
ds@1952
   447
					   &num_bits=0);
ds@1952
   448
ds@1952
   449
/**
ds@1952
   450
 * Wrapper function for finding a send property for a particular entity.
ds@1952
   451
 *
ds@1952
   452
 * @param ent			Entity index.
ds@1952
   453
 * @param prop			Property name.
ds@1952
   454
 * @param actual		Defaults to false for backwards compatibility.
ds@1952
   455
 *						If true, the newer FindSendPropInfo() function 
ds@1952
   456
 *						is used instead.
ds@1952
   457
 * @return				An offset, or -1 on failure.
ds@1952
   458
 */
ds@1952
   459
stock GetEntSendPropOffs(ent, const String:prop[], bool:actual=false)
ds@1952
   460
{
ds@1952
   461
	decl String:cls[64];
ds@1952
   462
	
ds@1952
   463
	if (!GetEntityNetClass(ent, cls, sizeof(cls)))
ds@1952
   464
	{
ds@1952
   465
		return -1;
ds@1952
   466
	}
ds@1952
   467
	
ds@1952
   468
	if (actual)
ds@1952
   469
	{
ds@1952
   470
		return FindSendPropInfo(cls, prop);
ds@1952
   471
	}
ds@1952
   472
	else
ds@1952
   473
	{
ds@1952
   474
		return FindSendPropOffs(cls, prop);
ds@1952
   475
	}
ds@1952
   476
}
ds@1952
   477
ds@1952
   478
/**
ds@1952
   479
 * Retrieves an integer value from an entity's property.
ds@1952
   480
 *
ds@1952
   481
 * This function is considered safer and more robust over GetEntData, 
ds@1952
   482
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   483
 * very minor performance hit from this.
ds@1952
   484
 * 
ds@1952
   485
 * @param entity		Entity/edict index.
ds@1952
   486
 * @param type			Property type.
ds@1952
   487
 * @param prop			Property name.
ds@1952
   488
 * @param size			Number of bytes to write (valid values are 1, 2, or 4).
ds@1952
   489
 *						This value is auto-detected, and the size parameter is 
ds@1952
   490
 *						only used as a fallback in case detection fails.
ds@1952
   491
 * @return				Value at the given property offset.
ds@1952
   492
 * @error				Invalid entity or property not found.
ds@1952
   493
 */
ds@1952
   494
native GetEntProp(entity, PropType:type, const String:prop[], size=4);
ds@1952
   495
ds@1952
   496
/**
ds@1952
   497
 * Sets an integer value in an entity's property.
ds@1952
   498
 *
ds@1952
   499
 * This function is considered safer and more robust over SetEntData, 
ds@1952
   500
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   501
 * very minor performance hit from this.
ds@1952
   502
 * 
ds@1952
   503
 * @param entity		Entity/edict index.
ds@1952
   504
 * @param type			Property type.
ds@1952
   505
 * @param prop			Property name.
ds@1952
   506
 * @param size			Number of bytes to write (valid values are 1, 2, or 4).
ds@1952
   507
 *						This value is auto-detected, and the size parameter is 
ds@1952
   508
 *						only used as a fallback in case detection fails.
ds@1952
   509
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   510
 * @noreturn
ds@1952
   511
 */
ds@1952
   512
native SetEntProp(entity, PropType:type, const String:prop[], any:value, size=4);
ds@1952
   513
ds@1952
   514
/**
ds@1952
   515
 * Retrieves a float value from an entity's property.
ds@1952
   516
 *
ds@1952
   517
 * This function is considered safer and more robust over GetEntDataFloat, 
ds@1952
   518
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   519
 * very minor performance hit from this.
ds@1952
   520
 * 
ds@1952
   521
 * @param entity		Entity/edict index.
ds@1952
   522
 * @param type			Property type.
ds@1952
   523
 * @param prop			Property name.
ds@1952
   524
 * @return				Value at the given property offset.
ds@1952
   525
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   526
 */
ds@1952
   527
native Float:GetEntPropFloat(entity, PropType:type, const String:prop[]);
ds@1952
   528
ds@1952
   529
/**
ds@1952
   530
 * Sets a float value in an entity's property.
ds@1952
   531
 *
ds@1952
   532
 * This function is considered safer and more robust over SetEntDataFloat, 
ds@1952
   533
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   534
 * very minor performance hit from this.
ds@1952
   535
 * 
ds@1952
   536
 * @param entity		Entity/edict index.
ds@1952
   537
 * @param type			Property type.
ds@1952
   538
 * @param prop			Property name.
ds@1952
   539
 * @param value			Value to set.
ds@1952
   540
 * @noreturn
ds@1952
   541
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   542
 */
ds@1952
   543
native SetEntPropFloat(entity, PropType:type, const String:prop[], Float:value);
ds@1952
   544
ds@1952
   545
/**
ds@1952
   546
 * Retrieves an entity index from an entity's property.
ds@1952
   547
 *
ds@1952
   548
 * This function is considered safer and more robust over GetEntDataEnt*, 
ds@1952
   549
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   550
 * very minor performance hit from this.
ds@1952
   551
 * 
ds@1952
   552
 * @param entity		Entity/edict index.
ds@1952
   553
 * @param type			Property type.
ds@1952
   554
 * @param prop			Property name.
ds@1952
   555
 * @return				Entity index at the given property.
ds@1952
   556
 *						If there is no entity, or the entity is not valid, 
ds@1952
   557
 *						then -1 is returned.
ds@1952
   558
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   559
 */
ds@1952
   560
native GetEntPropEnt(entity, PropType:type, const String:prop[]);
ds@1952
   561
ds@1952
   562
/**
ds@1952
   563
 * Sets an entity index in an entity's property.
ds@1952
   564
 *
ds@1952
   565
 * This function is considered safer and more robust over SetEntDataEnt*, 
ds@1952
   566
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   567
 * very minor performance hit from this.
ds@1952
   568
 * 
ds@1952
   569
 * @param entity		Entity/edict index.
ds@1952
   570
 * @param type			Property type.
ds@1952
   571
 * @param prop			Property name.
ds@1952
   572
 * @param other			Entity index to set, or -1 to unset.
ds@1952
   573
 * @noreturn
ds@1952
   574
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   575
 */
ds@1952
   576
native SetEntPropEnt(entity, PropType:type, const String:prop[], other);
ds@1952
   577
ds@1952
   578
/**
ds@1952
   579
 * Retrieves a vector of floats from an entity, given a named network property.
ds@1952
   580
 *
ds@1952
   581
 * This function is considered safer and more robust over GetEntDataVector, 
ds@1952
   582
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   583
 * very minor performance hit from this.
ds@1952
   584
 * 
ds@1952
   585
 * @param entity		Entity/edict index.
ds@1952
   586
 * @param type			Property type.
ds@1952
   587
 * @param prop			Property name.
ds@1952
   588
 * @param vec			Vector buffer to store data in.
ds@1952
   589
 * @noreturn
ds@1952
   590
 * @error				Invalid entity, property not found, or property not 
ds@1952
   591
 *						actually a vector data type.
ds@1952
   592
 */
ds@1952
   593
native GetEntPropVector(entity, PropType:type, const String:prop[], Float:vec[3]);
ds@1952
   594
ds@1952
   595
/**
ds@1952
   596
 * Sets a vector of floats in an entity, given a named network property.
ds@1952
   597
 *
ds@1952
   598
 * This function is considered safer and more robust over SetEntDataVector, 
ds@1952
   599
 * because it performs strict offset checking and typing rules.  There is a 
ds@1952
   600
 * very minor performance hit from this.
ds@1952
   601
 * 
ds@1952
   602
 * @param entity		Entity/edict index.
ds@1952
   603
 * @param type			Property type.
ds@1952
   604
 * @param prop			Property name.
ds@1952
   605
 * @param vec			Vector to set.
ds@1952
   606
 * @noreturn
ds@1952
   607
 * @error				Invalid entity, property not found, or property not 
ds@1952
   608
 *						actually a vector data type.
ds@1952
   609
 */
ds@1952
   610
native SetEntPropVector(entity, PropType:type, const String:prop[], const Float:vec[3]);
ds@1952
   611
ds@1952
   612
/**
ds@1952
   613
 * Gets a network property as a string.
ds@1952
   614
 * 
ds@1952
   615
 * @param entity		Edict index.
ds@1952
   616
 * @param type			Property type.
ds@1952
   617
 * @param prop			Property to use.
ds@1952
   618
 * @param buffer		Destination string buffer.
ds@1952
   619
 * @param maxlen		Maximum length of output string buffer.		
ds@1952
   620
 * @return				Number of non-null bytes written.
ds@1952
   621
 * @error				Invalid entity, offset out of reasonable bounds, or property is not a valid string.
ds@1952
   622
 */
ds@1952
   623
native GetEntPropString(entity, PropType:type, const String:prop[], String:buffer[], maxlen);
ds@1952
   624
ds@1952
   625
/**
ds@1952
   626
 * Sets a network property as a string.
ds@1952
   627
 *
ds@1952
   628
 * This cannot set property fields of type PropField_String_T (such as "m_target").
ds@1952
   629
 * To set such fields, you should use DispatchKeyValue() from SDKTools.
ds@1952
   630
 * 
ds@1952
   631
 * @param entity		Edict index.
ds@1952
   632
 * @param type			Property type.
ds@1952
   633
 * @param prop			Property to use.
ds@1952
   634
 * @param buffer		String to set.		
ds@1952
   635
 * @return				Number of non-null bytes written.
ds@1952
   636
 * @error				Invalid entity, offset out of reasonable bounds, or property is not a valid string.
ds@1952
   637
 */
ds@1952
   638
native SetEntPropString(entity, PropType:type, const String:prop[], const String:buffer[]);
ds@1952
   639
ds@1952
   640
/**
ds@1952
   641
 * Copies an array of cells from an entity at a given offset.
ds@1952
   642
 *
ds@1952
   643
 * @param entity		Entity index.
ds@1952
   644
 * @param offset		Offset to use.
ds@1952
   645
 * @param array			Array to read into.
ds@1952
   646
 * @param arraySize		Number of values to read.
ds@1952
   647
 * @param dataSize		Size of each value in bytes (1, 2, or 4).
ds@1952
   648
 * @noreturn
ds@1952
   649
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   650
 */
ds@1952
   651
stock GetEntDataArray(entity, offset, array[], arraySize, dataSize=4)
ds@1952
   652
{
ds@1952
   653
	for (new i=0; i<arraySize; i++)
ds@1952
   654
	{
ds@1952
   655
		array[i] = GetEntData(entity, offset + i*dataSize, dataSize)
ds@1952
   656
	}
ds@1952
   657
}
ds@1952
   658
ds@1952
   659
/**
ds@1952
   660
 * Copies an array of cells to an entity at a given offset.
ds@1952
   661
 *
ds@1952
   662
 * @param entity		Entity index.
ds@1952
   663
 * @param offset		Offset to use.
ds@1952
   664
 * @param array			Array of values to copy.
ds@1952
   665
 * @param arraySize		Number of values to copy.
ds@1952
   666
 * @param dataSize		Size of each value in bytes (1, 2, or 4).
ds@1952
   667
 * @param changeState	True to set the network state as changed; false otherwise.
ds@1952
   668
 * @noreturn
ds@1952
   669
 * @error				Invalid entity or offset out of reasonable bounds.
ds@1952
   670
 */
ds@1952
   671
stock SetEntDataArray(entity, offset, const array[], arraySize, dataSize=4, bool:changeState=false)
ds@1952
   672
{
ds@1952
   673
	for (new i=0; i<arraySize; i++)
ds@1952
   674
	{
ds@1952
   675
		SetEntData(entity, offset + i*dataSize, array[i], dataSize, changeState);
ds@1952
   676
	}
ds@1952
   677
}