/addons/sourcemod/scripting/include/entity.inc

https://bitbucket.org/kimoto/sushi · Pascal · 716 lines · 683 code · 17 blank · 16 comment · 16 complexity · 8df436c19cb8df0e2f8d092e65cdf5e6 MD5 · raw file

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