Raised This Month: $ Target: $400
 0% 

Find entity in Sphere


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 02-23-2022 , 08:40   Find entity in Sphere
Reply With Quote #1

Hi , I saw some posts about this to try to do it by myself, but I can't get it to work, I don't know what I'm doing wrong

What I want to do is that if someone is near the entity, they "activate" and apply what I put


PHP Code:
public doggy_create(idaimvec[3])
{     
    new 
entity
    
while ((entity find_ent_by_class(entity"Doggy")) > 0) {
        
entity_set_int(entityEV_INT_flagsFL_KILLME)
        
entity_set_int(entityEV_INT_effectsEF_NODRAW)
        
entity_set_int(entityEV_INT_solidSOLID_NOT)
    }
    
    new 
Float:vOrigin[3]
    
vOrigin[0] += aimvec[0]
    
vOrigin[1] += aimvec[1
    
vOrigin[2] += aimvec[2] + 7
    
    
new Doggy create_entity("info_target")
    
entity_set_string(DoggyEV_SZ_classname"Doggy")
    
entity_set_model(Doggy"models/shmod/shacobox.mdl")    
    
entity_set_size(DoggyFloat:{-2.5, -2.5, -1.5}, Float:{2.52.51.5})
    
entity_set_edict(DoggyEV_ENT_ownerid)
    
entity_set_int(DoggyEV_INT_solidSOLID_TRIGGER)
    
entity_set_int(DoggyEV_INT_movetypeMOVETYPE_FLY)
    
entity_set_vector(DoggyEV_VEC_originvOrigin)

    
set_task(1.0"find_target"Doggy__"b"
I tried these two ways, and neither worked for me, where "Doggy" is the entity above, and target would be an enemy player
PHP Code:
public find_target(Doggy)
{
    static 
id;
    new 
Float:rOrigin[3]
    
id entity_get_edict(DoggyEV_ENT_owner);
    
entity_get_vector(DoggyEV_VEC_originrOrigin);
     
    new 
target find_ent_in_sphere(DoggyrOriginget_pcvar_float(gPcvarRadius) ) 
    
    if(
is_user_alive(target) && cs_get_user_team(target) != cs_get_user_team(id) ) {
        
sh_set_stun(targetget_pcvar_float(gPcvarStun), 1.0);    //its only a stun
        
doggy_teleport(id); 
        
remove_entity(Doggy);  
    }  

PHP Code:
public find_target(Doggy)
{    
    new 
Float:origin[3] = { 0.00.00.0 // Origin to search from, could be a player origin or something
    
new Float:radius get_pcvar_float(gPcvarRadius// Size of the sphere to search in
    
    
while((Doggy find_ent_in_sphere(Doggyoriginradius)) > 0) {
        
        static 
id;
        
id entity_get_edict(DoggyEV_ENT_owner);
        
        new 
classname[32], target
        entity_get_string
(targetEV_SZ_classnameclassname31)
        if ( 
equal(classname"Player") ) {
            new 
Float:entityOrigin[3]
            
entity_set_vector(targetEV_VEC_originentityOrigin)
            
            new 
Float:distance vector_distanceoriginentityOrigin )
            
            if(
is_user_alive(id) && cs_get_user_team(id) != cs_get_user_team(target) ) {
                if( 
distance get_pcvar_float(gPcvarRadius) ) {
                    
sh_set_stun(targetget_pcvar_float(gPcvarStun), 1.0);    //its only a stun
                    
doggy_teleport(id); 
                    
remove_entity(Doggy);  
                }
            }
        }
    }

Arje is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 02-23-2022 , 10:37   Re: Find entity in Sphere
Reply With Quote #2

Code:
find_ent_in_sphere(Doggy, origin, radius)

The problem is that you are starting the search from the "doggy" entity which probably has an index greater than 32, so all players are skipped.

Code:
new entity while ((entity = find_ent_in_sphere(entity, origin, radius)) > 0) {     if (is_user_alive(entity))     {         // entity is a player         // do something     } }
__________________








CrazY. is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-23-2022 , 11:31   Re: Find entity in Sphere
Reply With Quote #3

Can you explain properly what are you trying to do?

nobody can understand what is "activate"
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 02-23-2022 , 12:25   Re: Find entity in Sphere
Reply With Quote #4

well what I want is that if an enemy player is in the spherical radius of "Doggy", this part of the code is activated, which are calls of other functions

PHP Code:
if( distance get_pcvar_float(gPcvarRadius) ) {
                    
sh_set_stun(targetget_pcvar_float(gPcvarStun), 1.0);    //its only a stun
                    
doggy_teleport(id); 
                    
remove_entity(Doggy);  
                } 
I mean, as the owner, I place the entity, and if an enemy player from the other team passes inside the radius, the previous written code is activated

I hope the image helps to explain better in case you don't understand what I want to do
Arje is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 02-23-2022 , 23:40   Re: Find entity in Sphere
Reply With Quote #5

I'm not good with this but i will try to help, check this:

PHP Code:
public Function( )
{
    new 
Float:fOrigin], iEntszPlayersMAX_PLAYERS ], iCountiDoggy find_ent_by_class( -"Doggy" );
    new 
Float:fRadius 100.0;
    
    
// Credits to naven/bugsy
    
if ( iDoggy && !( <= ( iEnt peviDoggy pev_owner ) ) <= MAX_PLAYERS ) && pev_validiEnt ) )
    {
        
peviEnt pev_origin fOrigin );

        
iCount find_sphere_class0"player"fRadiusszPlayerssizeofszPlayers ), fOrigin );
        
        for ( new 
idiiCounti++ )
        {
            
id szPlayers];
            
            if( 
is_user_aliveid ) )
            {
                
// ...
            
}
        }
    }
    

__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 02-23-2022 at 23:44.
Supremache is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:41.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode