plugins/include/entity.inc
author David Anderson <dvander@alliedmods.net>
Fri Mar 02 08:34:13 2007 +0000 (2007-03-02)
changeset 558 fc0eec032efb
parent 557 467d4af2148b
child 561 49f639ad7d5e
permissions -rw-r--r--
added state change function
     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.  This file may only be used 
     8  * or modified under the Terms and Conditions of its License Agreement, which is found 
     9  * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
    10  * may change at any time.  To view the latest information, see:
    11  *   http://www.sourcemod.net/license.php
    12  *
    13  * Version: $Id$
    14  */
    15  
    16 #if defined _entity_included
    17  #endinput
    18 #endif
    19 #define _entity_included
    20 
    21 
    22 /**
    23  * For more information on these, see the HL2SDK (public/edict.h)
    24  */
    25 #define FL_EDICT_CHANGED	(1<<0)	/**< Game DLL sets this when the entity state changes
    26 										 Mutually exclusive with FL_EDICT_PARTIAL_CHANGE. */
    27 #define FL_EDICT_FREE		(1<<1)	/**< this edict if free for reuse */
    28 #define FL_EDICT_FULL		(1<<2)	/**< this is a full server entity */
    29 #define FL_EDICT_FULLCHECK	(0<<0)  /**< call ShouldTransmit() each time, this is a fake flag */
    30 #define FL_EDICT_ALWAYS		(1<<3)	/**< always transmit this entity */
    31 #define FL_EDICT_DONTSEND	(1<<4)	/**< don't transmit this entity */
    32 #define FL_EDICT_PVSCHECK	(1<<5)	/**< always transmit entity, but cull against PVS */
    33 #define FL_EDICT_PENDING_DORMANT_CHECK	(1<<6)
    34 #define FL_EDICT_DIRTY_PVS_INFORMATION	(1<<7)
    35 #define FL_FULL_EDICT_CHANGED			(1<<8)
    36 
    37 /**
    38  * Returns the maximum number of entities.
    39  *
    40  * @return				Maximum number of entities.
    41  */
    42 native GetMaxEntities();
    43 
    44 /**
    45  * Returns the number of entities in the server.
    46  *
    47  * @return				Number of entities in the server.
    48  */
    49 native GetEntityCount();
    50 
    51 /**
    52  * Returns whether or not an entity is valid.  Returns false
    53  * if there is no matching CBaseEntity for this edict index.
    54  *
    55  * @param edict			Index of the entity/edict.
    56  * @return				True if valid, false otherwise.
    57  */
    58 native bool:IsValidEntity(edict);
    59 
    60 /**
    61  * Returns whether or not an edict index is valid.
    62  *
    63  * @param edict			Index of the edict.
    64  * @return				True if valid, false otherwise.
    65  */
    66 native bool:IsValidEdict(edict);
    67 
    68 /**
    69  * Returns whether or not an entity is a valid networkable edict.
    70  *
    71  * @param edict			Index of the edict.
    72  * @return				True if networkable, false if invalid or not networkable.
    73  */
    74 native bool:IsEntNetworkable(edict);
    75 
    76 /**
    77  * Creates a new edict (the basis of a networkable entity)
    78  *
    79  * @return				Index of the edict, 0 on failure.
    80  */
    81 native CreateEdict();
    82 
    83 /** 
    84  * Removes an edict from the world.
    85  *
    86  * @param edict			Index of the edict.
    87  * @noreturn
    88  * @error				Invalid edict index.
    89  */
    90 native RemoveEdict(edict);
    91 
    92 /**
    93  * Returns the flags on an edict.  These are not the same as entity flags.
    94  *
    95  * @param edict			Index of the entity.
    96  * @return				Edict flags.
    97  * @error				Invalid edict index.
    98  */
    99 native GetEdictFlags(edict);
   100 
   101 /**
   102  * Sets the flags on an edict.  These are not the same as entity flags.
   103  *
   104  * @param edict			Index of the entity.
   105  * @param flags			Flags to set.
   106  * @noreturn
   107  * @error				Invalid edict index.
   108  */
   109 native SetEdictFlags(edict, flags);
   110 
   111 /**
   112  * Retrieves an edict classname.
   113  *
   114  * @param edict			Index of the entity.
   115  * @param clsname		Buffer to store the classname.
   116  * @param maxlength		Maximum length of the buffer.
   117  * @return				True on success, false if there is no classname set.
   118  */
   119 native bool:GetEdictClassname(edict, String:clsname[], maxlength);
   120 
   121 /**
   122  * Retrieves an entity's networkable serverclass name.
   123  * This is not the same as the classname and is used for networkable state changes.
   124  *
   125  * @param edict			Index of the entity.
   126  * @param clsname		Buffer to store the serverclass name.
   127  * @param maxlength		Maximum lnegth of the buffer.
   128  * @return				True on success, false if the edict is not networkable.
   129  * @error				Invalid edict index.
   130  */
   131 native bool:GetEntityNetClass(edict, String:clsname[], maxlength);
   132 
   133 /**
   134  * @section Entity offset functions
   135  *
   136  * Offsets should be specified in byte distance from the CBaseEntity 
   137  * structure, not short (double byte) or integer (four byte) multiples.  
   138  * It is somewhat common practice to use offsets aligned to their final 
   139  * type, and thus make sure you are not falling to this error in SourceMod.
   140  * For example, if your "integer-aligned" offset was 119, your byte-aligned
   141  * offset is 119*4, or 476.
   142  
   143  * Specifying incorrect offsets or the incorrect data type for an offset
   144  * can have fatal consequences.  If you are hardcoding offsets, and the 
   145  * layout of CBaseEntity does not match, you can easily crash the server.
   146  *
   147  * The reasonable bounds for offsets is greater than or equal to 0 and 
   148  * below 32768.  Offsets out of these bounds will throw an error.  However,
   149  * this does not represent any real range, it is simply a sanity check for
   150  * illegal values.  Any range outside of the CBaseEntity structure's private
   151  * size will cause undefined behaviour or even crash.
   152  */
   153  
   154 /**
   155  * Marks an entity as state changed.  This can be useful if you set an offset 
   156  * and wish for it to be immediately changed over the network.  By default this 
   157  * is not done for offset setting functions.  
   158  *
   159  * @param edict			Index to the edict.
   160  * @param offset		Offset to mark as changed.  If 0, 
   161  *						the entire edict is marked as changed.
   162  * @noreturn
   163  * @error				Invalid entity or offset out of bounds.
   164  */
   165 native ChangeEdictState(edict, offset = 0);
   166 
   167 /**
   168  * Peeks into an entity's object data and retrieves the integer value at 
   169  * the given offset.
   170  * 
   171  * @param entity		Edict index.
   172  * @param offset		Offset to use.
   173  * @param size			Number of bytes to read (valid values are 1, 2, or 4).
   174  * @return				Value at the given memory location.
   175  * @error				Invalid entity or offset out of reasonable bounds.
   176  */
   177 native GetEntData(entity, offset, size=4);
   178 
   179 /**
   180  * Peeks into an entity's object data and sets the integer value at 
   181  * the given offset.
   182  *
   183  * @param entity		Edict index.
   184  * @param offset		Offset to use.
   185  * @param size			Number of bytes to write (valid values are 1, 2, or 4).
   186  * @return				Value at the given memory location.
   187  * @error				Invalid entity or offset out of reasonable bounds.
   188  * @noreturn
   189  */
   190 native SetEntData(entity, offset, value, size=4);
   191 
   192 /**
   193  * Peeks into an entity's object data and retrieves the float value at 
   194  * the given offset.
   195  * 
   196  * @param entity		Edict index.
   197  * @param offset		Offset to use.
   198  * @return				Value at the given memory location.
   199  * @error				Invalid entity or offset out of reasonable bounds.
   200  */
   201 native Float:GetEntDataFloat(entity, offset);
   202 
   203 /**
   204  * Peeks into an entity's object data and sets the integer value at 
   205  * the given offset.
   206  *
   207  * @param entity		Edict index.
   208  * @param offset		Offset to use.
   209  * @return				Value at the given memory location.
   210  * @error				Invalid entity or offset out of reasonable bounds.
   211  * @noreturn
   212  */
   213 native SetEntDataFloat(entity, offset, Float:value);
   214 
   215 /**
   216  * Peeks into an entity's object data and retrieves the entity handle
   217  * info at the given offset.
   218  * 
   219  * @param entity		Edict index.
   220  * @param offset		Offset to use.
   221  * @return				Entity index at the given location, or 0 if none.
   222  * @error				Invalid entity or offset out of reasonable bounds.
   223  */
   224 native GetEntDataEnt(entity, offset);
   225 
   226 /**
   227  * Peeks into an entity's object data and sest the entity handle info
   228  * at the given offset.
   229  * 
   230  * @param entity		Edict index.
   231  * @param offset		Offset to use.
   232  * @param other			Entity index to set, or 0 to clear.
   233  * @noreturn
   234  * @error				Invalid entity or offset out of reasonable bounds.
   235  */
   236 native SetEntDataEnt(entity, offset, other);
   237 
   238 /**
   239  * Peeks into an entity's object data and retrieves the vector at the 
   240  * given offset.
   241  * @note Both a Vector and a QAngle are three floats.  This is a 
   242  * convenience function and will work with both types.
   243  * 
   244  * @param entity		Edict index.
   245  * @param offset		Offset to use.
   246  * @param vec			Vector buffer to store data in.
   247  * @noreturn
   248  * @error				Invalid entity or offset out of reasonable bounds.
   249  */
   250 native GetEntDataVector(entity, offset, Float:vec[3]);
   251 
   252 /**
   253  * Peeks into an entity's object data and sets the vector at the given 
   254  * offset.
   255  * @note Both a Vector and a QAngle are three floats.  This is a 
   256  * convenience function and will work with both types.
   257  * 
   258  * @param entity		Edict index.
   259  * @param offset		Offset to use.
   260  * @param vec			Vector to set.
   261  * @noreturn
   262  * @error				Invalid entity or offset out of reasonable bounds.
   263  */
   264 native SetEntDataVector(entity, offset, const Float:vec[3]);