original code is from the HLSDK (UTIL_EntitiesInBox). you can use these functions to determine if two entities are touching each other. i'm not going to explain what you can use this for.
functions are as follows:
find_ent_in_box ( StartEntity, Float:mins[3], Float:maxs[3] )
Code:
// PARAMETERS
// -
// StartEntity: which entity to start searching from
// mins: the absmin of your collision box
// maxs: the absmax of your collision box
//
//
// RETURN VALUES
// -
// returns the index of the first entity found.
// if no entities were found this returns 0.
find_box_list ( Float:mins[3], Float:maxs[3], entlist[], maxents, param[] = "", type = 0 )
Code:
// PARAMETERS
// -
// mins: the absmin of your collision box
// maxs: the absmax of your collision box
// entlist: array to store entities found in
// maxents: maximum amount of entities to store
// param: (optional, default "") the string to compare collisions with (see below). if blank, ignored.
// type: (optional, default 0) 0: find by classname, 1: find by target, 2: find by targetname
//
//
// RETURN VALUES
// -
// returns the amount of entities saved into entlist
check_collision ( entity1, entity2 )
Code:
// PARAMETERS
// -
// entity1: the first entity to compare
// entity2: the second entity to compare
//
//
// RETURN VALUES
// -
// returns 1 if the two entities collide, otherwise 0.
check_collision_ext ( StartEntity, entity, param[], type = 0 )
Code:
// PARAMETERS
// -
// StartEntity: which entity to start searching from
// entity: the entity of which to check collisions for
// param: the string to compare collisions with (see below)
// type: (optional, default 0) 0: find by classname, 1: find by target, 2: find by targetname
//
//
// RETURN VALUES
// -
// returns the index of the first colliding entity found with the matching field.
// if no valid entities were found this returns 0.
Float:
get_box_distance ( Float:mins1[3], Float:maxs1[3], Float:mins2[3], Float:maxs2[3] )
Code:
* PARAMETERS:
* mins1 - mins of the first box, Float:{min_x1, min_y1, min_z1}
* maxs1 - maxs of the first box, Float:{max_x1, max_y1, max_z1}
* mins2 - mins of the second box, Float:{min_x2, min_y2, min_z2}
* maxs2 - maxs of the second box, Float:{max_x2, max_y2, max_z2}
*
* RETURN RESULT:
* Float value of distance between first and second box.
* If result is 0.0 then boxes are colliding/touching.
requires engine. find_ent_in_box as well as find_box_list is not tested (sorry) but i see no reason why they shouldn't work. check_collision_ext (and thus check_collision) works marvelously. this
does work if two entities are touching (ie: if you walk up to a hostage), aka they do
not have to be actually overlapping.
feel free to make suggestions. you don't have to use the include, you can just copy out the functions. check_collision_ext requires check_collision to work.
get_box_distance written by VEN.
"You can not restrain a fool from speaking, but nothing obliges you to listen."