Add cs_find_ent_by_class and fix documentation

This commit is contained in:
Arkshine
2015-01-30 15:53:25 +01:00
parent 2446ff49f2
commit c87d46ad5b
8 changed files with 254 additions and 26 deletions

View File

@ -351,14 +351,20 @@ native bool:cs_get_c4_defusing(c4index);
native cs_set_c4_defusing(c4index, bool:defusing);
/**
* Creates an entity.
* Creates an entity using Counter-Strike's custom CreateNamedEntity wrapper.
*
* @note Similar as create_entity() native from engine module, with the difference that in Counter-Strike
* to improve lookup performance on entities, the classname is hashed and saved in a global list.
* This means for classname, game uses a custom function which checks that list instead of calling pfnFindEntityByString.
* You would want to use this native if you want having custom entities to be known by the game.
* E.g. By creating a "weaponbox" entity, this will be automatically deleted by game on map restart.
* With engine version, you would have to remove it manually.
* @note Unlike other mods CS keeps track of entities using a custom hashtable.
* This function will add entities to this hashtable, providing benefits
* over the default engine functions (used by create_entity() for example):
* - Storing entities in a hashtable allows CS to improve classname lookup
* performance compared to functions like FindEntityByString that usually
* have to loop incrementally through all entities.
* - As CS exclusively uses the hashtable for classname lookup, entities
* created using the default engine functions will not be found by the
* game. For example "weaponbox" entities are supposed to be
* automatically cleaned up on round restart but are not considered if
* they have not been added to the hashtable.
* @note CS's faster hashtable lookup can be utilized with cs_find_ent_by_class()
*
* @param classname Entity class name
*
@ -366,6 +372,25 @@ native cs_set_c4_defusing(c4index, bool:defusing);
*/
native cs_create_entity(const classname[]);
/**
* Finds an entity in the world using Counter-Strike's custom FindEntityByString
* wrapper.
*
* @note Unlike other mods CS keeps track of entities using a custom hashtable.
* This function utilizes the custom hasthable and allows for considerably
* faster classname lookup compared to the default engine functions (used
* by find_ent_by_class() for example).
* @note This exclusively considers entities in the hashtable, created by the
* game itself or using cs_create_entity().
*
* @param start_index Entity index to start searching from. -1 to start from
* the first entity
* @param classname Classname to search for
*
* @return Entity index > 0 if found, 0 otherwise
*/
native cs_find_ent_by_class(start_index, const classname[]);
/**
* Called when CS internally fires a command to a player. It does this for a few
* functions, most notably rebuy/autobuy functionality. This is also used to pass