Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
01-30-2017
, 12:04
Re: find_sphere_class, how speccialy does it work?
#5
They are in order of entity index.
Generally that is how entity finding functions works.
They loop through indexes, comparing distance and if it's within range, return it.
Spoiler
Code:
#include <amxmodx>
#include <engine>
public plugin_init( ) {
register_plugin ( "Test Plugin 1" , "1.0" , "[ --{-@ ]" ) ;
register_clcmd ( "say /test" , "test" ) ;
}
public test( id) {
new entlist[ 128 ] ;
find_sphere_class( id, "info_player_deathmatch" , 99999.9 , entlist, sizeof entlist) ;
for ( new i ; i < sizeof entlist && entlist[ i] ; i++ )
server_print ( "Ent: %d, Distance: %d" , entlist[ i] , get_entity_distance( id, entlist[ i] ) ) ;
}
Code:
Ent: 95, Distance: 8
Ent: 96, Distance: 160
Ent: 97, Distance: 681
Ent: 98, Distance: 511
Ent: 99, Distance: 669
Ent: 100, Distance: 482
Ent: 101, Distance: 873
Ent: 102, Distance: 1001
Ent: 115, Distance: 201
Ent: 116, Distance: 276
Usually sorting is not important and therefor a waste of resources. However, you can always sort them using SortCustom1D
Spoiler
Code:
#include <amxmodx>
#include <engine>
public plugin_init( ) {
register_plugin ( "Test Plugin 1" , "1.0" , "[ --{-@ ]" ) ;
register_clcmd ( "say /test" , "test" ) ;
}
public test( id) {
new entlist[ 128 ] ;
find_sphere_class( id, "info_player_deathmatch" , 99999.9 , entlist, sizeof entlist) ;
new any: data[ 3 ] ;
entity_get_vector( id, EV_VEC_origin, data) ;
SortCustom1D( entlist, sizeof entlist, "funcComparison" , data, sizeof data) ;
for ( new i ; i < sizeof entlist && entlist[ i] ; i++ )
server_print ( "Ent: %d, Distance: %d" , entlist[ i] , get_entity_distance( id, entlist[ i] ) ) ;
}
public funcComparison( elem1, elem2, const array[ ] , const any: data[ 3 ] , data_size) {
new Float : elem1Vec[ 3 ] , Float : elem2Vec[ 3 ] ;
entity_get_vector( elem1, EV_VEC_origin, elem1Vec) ;
entity_get_vector( elem2, EV_VEC_origin, elem2Vec) ;
new Float : elem1Dist = get_distance_f ( data, elem1Vec) ;
new Float : elem2Dist = get_distance_f ( data, elem2Vec) ;
if ( elem1Dist < elem2Dist )
return - 1 ;
if ( elem1Dist > elem2Dist )
return 1 ;
return 0 ;
}
Code:
Ent: 95, Distance: 8
Ent: 96, Distance: 160
Ent: 115, Distance: 201
Ent: 116, Distance: 276
Ent: 100, Distance: 482
Ent: 98, Distance: 511
Ent: 99, Distance: 669
Ent: 97, Distance: 681
Ent: 101, Distance: 873
Ent: 102, Distance: 1001
__________________
Last edited by Black Rose; 01-30-2017 at 12:09 .