Raised This Month: $12 Target: $400
 3% 

How can Detect distance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 02-26-2018 , 08:12   How can Detect distance
Reply With Quote #1

Hy guys

I want to detect distance between player and entity!

Can help me someone?

Code:
CreateEntity()
{     
    Entity = create_entity( "info_target" );

    new Float:PlayerOrigin[3]
    new Float:fDistance    
    
    for(new i = 1 ; i <= maxplayers; i++)
    {
        pev(i, pev_origin, PlayerOrigin)
        fDistance = get_distance_f( Entity , PlayerOrigin )
        
        if( fDistance <= 500.0)
        {
            client_print(i , print_center, "Distance to entity: %.2f", fDistance )
        }
    }

    if( is_valid_ent(Entity) )
    {
        entity_set_string( Entity , EV_SZ_classname, "fox_wall");
        entity_set_int( Entity , EV_INT_solid, SOLID_BBOX);
        entity_set_model( Entity , DATE );
        entity_set_size( Entity , Float:{ -350.0, -10.0, 0.0 }, Float:{ 350.0, 10.0, 10.0 } );      
        entity_set_origin( Entity, Float:{ 1066.52, -1025.00, -551.00 } );
    }
        
    return;
}

Last edited by Saint Sinner; 02-26-2018 at 08:13.
Saint Sinner is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 02-26-2018 , 08:35   Re: How can Detect distance
Reply With Quote #2

This?
Code:
        pev(i, pev_origin, PlayerOrigin)
        fDistance = get_distance_f( Entity , PlayerOrigin )
        
        if( fDistance <= 500.0)
        {
            client_print(i , print_center, "Distance to entity: %.2f", fDistance )
        }
zmd94 is offline
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 02-26-2018 , 08:43   Re: How can Detect distance
Reply With Quote #3

not working

Code:
include\fakemeta_const.inc(551) : warning 201: redefinition of constant/macro (symbol "TraceResult")
a63a8d660650ba68a5337b620d20056c.sma(47) : error 035: argument type mismatch (argument 1)
Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>

new Entity

new const DATE[] = "models/TEST.mdl"

new maxplayers
public plugin_init() 
{
    register_clcmd("say /x", "remove")
    register_clcmd("say /z", "create")
    maxplayers = get_maxplayers()
}

public remove() 
{
    new ent = -1;
    while ((ent = find_ent_by_class(ent, "fox_wall")))
    {
	remove_entity(ent); 
    }
}

public create() 
{
    CreateEntity()
}

public plugin_precache() 
{
    precache_model(DATE)
    CreateEntity()
}

CreateEntity()
{     
    Entity = create_entity( "info_target" );

    new Float:PlayerOrigin[3]
    new Float:fDistance    
    
    for(new i = 1 ; i <= maxplayers; i++)
    {
        pev(i, pev_origin, PlayerOrigin)
        fDistance = get_distance_f( Entity , PlayerOrigin )
        
        if( fDistance <= 500.0)
        {
            client_print(i , print_center, "Distance to entity: %.2f", fDistance )
        }
    }

    if( is_valid_ent(Entity) )
    {
        entity_set_string( Entity , EV_SZ_classname, "fox_wall");
        entity_set_int( Entity , EV_INT_solid, SOLID_BBOX);
        entity_set_model( Entity , DATE );
        entity_set_size( Entity , Float:{ -350.0, -10.0, 0.0 }, Float:{ 350.0, 10.0, 10.0 } );      
        entity_set_origin( Entity, Float:{ 1066.52, -1025.00, -551.00 } );
    }
        
    return;
}

Last edited by Saint Sinner; 02-26-2018 at 08:45.
Saint Sinner is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-26-2018 , 10:13   Re: How can Detect distance
Reply With Quote #4

You need to input the origin of both entities in get_distance_f().
__________________
Bugsy is offline
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 02-26-2018 , 10:22   Re: How can Detect distance
Reply With Quote #5

How can do that?

Becouse the entity origin is here : entity_set_origin( Entity, Float:{ 1066.52, -1025.00, -551.00 } );

I tried this but not working

Code:
new const Float:Origin[][2] = 
{
    { 1066.52, -1025.00, -551.00 }
}

fDistance = get_distance_f( Origin , PlayerOrigin )
entity_set_origin( Entity, Origin );

Last edited by Saint Sinner; 02-26-2018 at 10:40.
Saint Sinner is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-26-2018 , 11:04   Re: How can Detect distance
Reply With Quote #6

PHP Code:
new Float:fEntOrigin]
peviEntity pev_origin fEntOrigin )

new 
Float:fOrigin]
pevid pev_origin fOrigin )

fDistance get_distance_ffEntOrigin fOrigin 
You get the origin of both entities and input that into get_distance_f(). It's not rocket science.
__________________

Last edited by Bugsy; 02-26-2018 at 11:05.
Bugsy is offline
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 02-26-2018 , 11:29   Re: How can Detect distance
Reply With Quote #7

I did as you said and still not work

Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>

new Entity

new const DATE[] = "models/TEST.mdl"

new maxplayers
public plugin_init() 
{
    register_clcmd("say /x", "remove")
    register_clcmd("say /z", "create")
    maxplayers = get_maxplayers()
}

public remove() 
{
    new ent = -1;
    while ((ent = find_ent_by_class(ent, "fox_wall")))
    {
	remove_entity(ent); 
    }
}

public create() 
{
    CreateEntity()
}

public plugin_precache() 
{
    precache_model(DATE)
    CreateEntity()
}

CreateEntity()
{     
    Entity = create_entity( "info_target" );

    new Float:PlayerOrigin[3]
    new Float:fDistance
    new Float:fEntOrigin[ 3 ]
       
    for(new i = 1 ; i <= maxplayers; i++)
    {
        pev(i, pev_origin, PlayerOrigin)
        pev( Entity , pev_origin , fEntOrigin )
        fDistance = get_distance_f( fEntOrigin , PlayerOrigin )
        
        if( fDistance >= 500.0)
        {
            client_print(i , print_center, "Distance to entity: %.2f", fDistance )
        }
    }

    if( is_valid_ent(Entity) )
    {
        entity_set_string( Entity , EV_SZ_classname, "fox_wall");
        entity_set_int( Entity , EV_INT_solid, SOLID_BBOX);
        entity_set_model( Entity , DATE );
        entity_set_size( Entity , Float:{ -350.0, -10.0, 0.0 }, Float:{ 350.0, 10.0, 10.0 } );      
        entity_set_origin( Entity, Float:{ 1066.52, -1025.00, -551.00 } );
    }
        
    return;
}
Saint Sinner is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 02-26-2018 , 14:46   Re: How can Detect distance
Reply With Quote #8

First you need to set properties, then perform a comparison.
__________________
My English is A0
E1_531G is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-26-2018 , 17:31   Re: How can Detect distance
Reply With Quote #9

You are looping from 1 to max players which will error if your server is not 100% full. Instead, use get_players() with flags to get the specific players that you want, or no flags to get all.
PHP Code:
CreateEntity()
{     
    new 
Float:PlayerOrigin] , Float:fDistance Float:fEntOrigin]
    new 
iPlayers32 ] , iNum id szName32 ];
        
    
Entity create_entity"info_target" );
    
    if( 
is_valid_ent(Entity) )
    {
        
entity_set_stringEntity EV_SZ_classname"fox_wall");
        
entity_set_intEntity EV_INT_solidSOLID_BBOX);
        
entity_set_modelEntity DATE );
        
entity_set_sizeEntity Float:{ -350.0, -10.00.0 }, Float:{ 350.010.010.0 } );      
        
entity_set_originEntityFloat:{ 1066.52, -1025.00, -551.00 } );

        
        
get_playersiPlayers iNum );
        
        for ( new 
iNumi++ )
        {
            
id iPlayers];
            
get_user_nameid szName charsmaxszName ) );
            
            
pevid pev_originPlayerOrigin )
            
pevEntity pev_origin fEntOrigin )
            
            
fDistance get_distance_ffEntOrigin PlayerOrigin )
            
            
client_printprint_center"%s distance to entity is %.2f" szName fDistance )
        }
    }    


__________________

Last edited by Bugsy; 02-26-2018 at 17:34.
Bugsy is offline
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 02-26-2018 , 17:46   Re: How can Detect distance
Reply With Quote #10

Thanks
Saint Sinner is offline
Reply


Thread Tools
Display Modes

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 10:21.


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