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