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

get_distance_f problem [ solved ]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
red_bull2oo6
Senior Member
Join Date: Mar 2012
Location: Braila, Romania
Old 10-17-2014 , 15:37   get_distance_f problem [ solved ]
Reply With Quote #1

Hi, we meet again.
I have this little problem.

This is my code

PHP Code:
/* Plugin generated by AMXX-Studio */

    #include < amxmodx >
    #include < engine >
    #include < fun >
    
    #pragma semicolon 1
    
    
new const
        
PLUGIN_NAME[ ]         = "Blank Spawns",
        
PLUGIN_VERSION[ ]     = "1.0";
    
    new const
        
PLUGIN_TAG[ ]        = "|Plugin Tag:";
        
    
enum _:iSpawns
    
{
        
NULL,
        
TERO,
        
CT
    
}
    
    new 
Float:g_fOriginsiSpawns ][ 64 ][ ];
    new 
g_iSpawnsiSpawns ];
    
    
    new 
bool:g_bUserIsBlanked33 ];
            
public 
plugin_init( )
{
    
register_plugin
    
(
        
PLUGIN_NAME,
        
PLUGIN_VERSION,
        
"Askhanar"
    
);
    
    
GetSpawnsOrigins( );
    
// Add your code here...
    
}

public 
client_PreThinkid )
{
    if( !
is_user_aliveid ) )
        return;
        
    static 
Float:fOrigin];
    
    
    
    
entity_get_vectoridEV_VEC_originfOrigin );
    
    static 
Float:fDistanceFloat:fClosest;
    
    
fClosest 9999.0;
    switch( 
get_user_teamid ) )
    {
        case 
1:
        {
            for( new 
0g_iSpawnsCT ]; i++ )
            {
                
fDistance get_distance_ffOriging_fOriginsCT ][ ] );
                if( 
fDistance fClosest )
                    
fClosest fDistance;
            }
            
        }
        case 
2:
        {
            for( new 
0g_iSpawnsTERO ]; i++ )
            {
                
fDistance get_distance_ffOriging_fOriginsTERO ][ ] );
                if( 
fDistance fClosest )
                    
fClosest fDistance;
            }
            
        }
    }
    
    if( 
fClosest <= 255.0 && !g_bUserIsBlankedid ] )
    {
        
        
g_bUserIsBlankedid ] = true;
        
set_user_hitzonesid0);
        
client_printidprint_chat"%s You are now fireing blanks!"PLUGIN_TAG );
        
client_printidprint_chat"%s %.3f"PLUGIN_TAGfClosest );
        
    }
    else if( 
fClosest 255.0 && g_bUserIsBlankedid ] )
    {
        
g_bUserIsBlankedid ] = false;
        
set_user_hitzonesid0255 );
        
client_printidprint_chat"%s You're not fireing blanks anymore!"PLUGIN_TAG );
        
client_printidprint_chat"%s %.3f"PLUGIN_TAGfClosest );
    }
}

stock Float:get_distance_float( const Float:fOrigin], const Float:flOrigin] )
{
    return ( ( 
fOrigin] - flOrigin] ) + ( fOrigin] - flOrigin] ) );
}

GetSpawnsOrigins( )
{
    new 
iEnt;
    while( ( 
iEnt find_ent_by_classiEnt"info_player_deathmatch") ) )
    {
        if( 
iEnt && ++g_iSpawnsTERO ] < 64 )
        {
            
entity_get_vectoriEntEV_VEC_origing_fOriginsTERO ][ g_iSpawnsTERO ] ] );
            
g_iSpawnsTERO ]++;
        }
    }
    
    
iEnt = -1;
    while( ( 
iEnt find_ent_by_classiEnt"info_player_start") ) )
    {
        if( 
iEnt && ++g_iSpawnsCT ] < 64 )
        {
            
entity_get_vectoriEntEV_VEC_origing_fOriginsCT ][ g_iSpawnsCT ] ] );
            
g_iSpawnsCT ]++;
        }
    }
    
    
/*log_amx( "Loaded %i T and %i CT", g_iSpawns[ TERO ], g_iSpawns[ CT ] );
    
    for( new i = 0; i < g_iSpawns[ TERO ]; i++ )
        log_amx( "[T %i] %f %f %f", i +1, g_fOrigins[ TERO ][ i ][ 0 ], g_fOrigins[ TERO ][ 1 ], g_fOrigins[ TERO ][ 2 ] );
        
    for( new i = 0; i < g_iSpawns[ CT ]; i++ )
        log_amx( "[CT %i] %f %f %f", i +1, g_fOrigins[ CT ][ i ][ 0 ], g_fOrigins[ CT ][ 1 ], g_fOrigins[ CT ][ 2 ] );
    
    */

On de_dust2, when i walk around upside CT spawn ( see screenshot ) i get blanks ..
Click for ScreenShot ( imgur )

what can i do to check only horizontal distance ( x & y.. i mean forward/backward & right/left ) ?
__________________

My PC Themes . .

Last edited by red_bull2oo6; 10-26-2014 at 06:57. Reason: added [solved] tag.
red_bull2oo6 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-17-2014 , 15:51   Re: get_distance_f problem
Reply With Quote #2

get_distance_f() gives the straight-line distance between two points (in 3 dimensions). If you need to get the x and y distances then you should do it manually using the to points (simple subtraction of the corresponding values).
__________________
fysiks is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 10-19-2014 , 12:33   Re: get_distance_f problem
Reply With Quote #3

PHP Code:
/***
*
*    Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*    
*    This product contains software technology licensed from Id 
*    Software, Inc. ("Id Technology").  Id Technology (c) 1996 Id Software, Inc. 
*    All Rights Reserved.
*
*   Use, distribution, and modification of this source code and/or resulting
*   object code is restricted to non-commercial enhancements to products from
*   Valve LLC.  All other use, distribution, or modification is prohibited
*   without written permission from Valve LLC.
*
****/
#ifndef VECTOR_H
#define VECTOR_H

//=========================================================
// 2DVector - used for many pathfinding and many other 
// operations that are treated as planar rather than 3d.
//=========================================================
class Vector2D
{
public:
    
inline Vector2D(void): x(0.0), y(0.0)                            { }
    
inline Vector2D(float Xfloat Y): x(0.0), y(0.0)                { XY; }
    
inline Vector2D operator+(const Vector2Dv)    const    { return Vector2D(x+v.xy+v.y);    }
    
inline Vector2D operator-(const Vector2Dv)    const    { return Vector2D(x-v.xy-v.y);    }
    
inline Vector2D operator*(float fl)                const    { return Vector2D(x*fly*fl);    }
    
inline Vector2D operator/(float fl)                const    { return Vector2D(x/fly/fl);    }
    
    
inline float Length(void)                        const    { return sqrt(x*y*);        }

    
inline Vector2D Normalize void ) const
    {
        
// Vector2D vec2;

        
float flLen Length();
        if ( 
flLen == )
        {
            return 
Vector2D0);
        }
        else
        {
            
flLen flLen;
            return 
Vector2DflLenflLen );
        }
    }

    
vec_t    xy;
};

inline float DotProduct(const Vector2Da, const Vector2Db) { return( a.x*b.a.y*b.); }
inline Vector2D operator*(float fl, const Vector2Dv)    { return fl; }

//=========================================================
// 3D Vector
//=========================================================
class Vector                        // same data-layout as engine's vec3_t,
{                                //        which is a vec_t[3]
public:
    
// Construction/destruction
    
inline Vector(void): x(0.0), y(0.0), z(0.0)                    { }
    
inline Vector(float Xfloat Yfloat Z): x(0.0), y(0.0), z(0.0)    { XYZ;                }
    
//inline Vector(double X, double Y, double Z)        { x = (float)X; y = (float)Y; z = (float)Z;    }
    //inline Vector(int X, int Y, int Z)                { x = (float)X; y = (float)Y; z = (float)Z;    }
    
inline Vector(const Vectorv): x(0.0), y(0.0), z(0.0)        { v.xv.yv.z;                } 
    
inline Vector(float rgfl[3]): x(0.0), y(0.0), z(0.0)        { rgfl[0]; rgfl[1]; rgfl[2];    }

    
// Operators
    
inline Vector operator-(void) const                { return Vector(-x,-y,-z);                }
    
inline int operator==(const Vectorv) const    { return x==v.&& y==v.&& z==v.z;    }
    
inline int operator!=(const Vectorv) const    { return !(*this==v);                    }
    
inline Vector operator+(const Vectorv) const    { return Vector(x+v.xy+v.yz+v.z);    }
    
inline Vector operator-(const Vectorv) const    { return Vector(x-v.xy-v.yz-v.z);    }
    
inline Vector operator*(float fl) const            { return Vector(x*fly*flz*fl);        }
    
inline Vector operator/(float fl) const            { return Vector(x/fly/flz/fl);        }
    
    
// Methods
    
inline void CopyToArray(floatrgfl) const        { rgfl[0] = xrgfl[1] = yrgfl[2] = z; }
    
inline float Length(void) const                    { return sqrt(x*y*z*z); }
    
operator float *()                                { return &x; } // Vectors will now automatically convert to float * when needed
    
operator const float *() const                    { return &x; } // Vectors will now automatically convert to float * when needed
    
inline Vector Normalize(void) const
    {
        
float flLen Length();
        if (
flLen == 0) return Vector(0,0,1); // ????
        
flLen flLen;
        return 
Vector(flLenflLenflLen);
    }

    
inline Vector2D Make2D void ) const
    {
        
Vector2D    Vec2;

        
Vec2.x;
        
Vec2.y;

        return 
Vec2;
    }
    
inline float Length2D(void) const                    { return sqrt(x*y*y); }

    
// Members
    
vec_t xyz;
};
inline Vector operator*(float fl, const Vectorv)    { return fl; }
inline float DotProduct(const Vectora, const Vectorb) { return(a.x*b.x+a.y*b.y+a.z*b.z); }
inline Vector CrossProduct(const Vectora, const Vectorb) { return Vectora.y*b.a.z*b.ya.z*b.a.x*b.za.x*b.a.y*b.); }



#endif 
PHP Code:
void Function(void) {
  
Vector2D mn;
  
float len = (n).Length();

Vector.h content, hope it helps.
Length2d request was made for AMX Mod X development build.
__________________

Last edited by claudiuhks; 10-21-2014 at 09:43.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
avril-lavigne
Banned
Join Date: Apr 2009
Old 10-20-2014 , 14:53   Re: get_distance_f problem
Reply With Quote #4

today I used entity_range

it works 100%
__________________
VDS in Europe 1 gb/s unmetered.Any configurations.
I accept Paypal, Moneybookers,etc
avril-lavigne is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-20-2014 , 23:25   Re: get_distance_f problem
Reply With Quote #5

Quote:
Originally Posted by avril-lavigne View Post
today I used entity_range

it works 100%
Based on the documentation, that give a distance in 3D and is not what the OP is asking for.
__________________
fysiks is offline
red_bull2oo6
Senior Member
Join Date: Mar 2012
Location: Braila, Romania
Old 10-22-2014 , 07:22   Re: get_distance_f problem
Reply With Quote #6

@fysiks i'll try your idea tonight when i reach home.
@claudiuhsk i suk at c++ and i don't really understand.
@avril-lavighe i think i tried it..

i'll edit later. ty for your answers.
__________________

My PC Themes . .
red_bull2oo6 is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 10-22-2014 , 09:51   Re: get_distance_f problem
Reply With Quote #7

Quote:
Originally Posted by red_bull2oo6 View Post
@fysiks i'll try your idea tonight when i reach home.
@claudiuhsk i suk at c++ and i don't really understand.
@avril-lavighe i think i tried it..

i'll edit later. ty for your answers.
PHP Code:
stock math_CancelApplicate(Vector[3])
{
  
Vector[2] = 0;
}

stock math_CancelApplicateF(Float:Vector[3])
{
  
Vector[2] = 0.0;
}

stock math_Distance2D(VectorA[3], VectorB[3])
{
  
math_CancelApplicate(VectorA);
  
math_CancelApplicate(VectorB);

  return 
get_distance(VectorAVectorB);
}

stock Float:math_DistanceF2D(Float:VectorA[3], Float:VectorB[3])
{
  
math_CancelApplicateF(VectorA);
  
math_CancelApplicateF(VectorB);

  return 
get_distance_f(VectorAVectorB);

__________________
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
red_bull2oo6
Senior Member
Join Date: Mar 2012
Location: Braila, Romania
Old 10-24-2014 , 15:07   Re: get_distance_f problem
Reply With Quote #8

thanks a lot
works flawlessly now.

i tried to set the z axe to 9999.0 and nothing happened, never tried to set it to NULL
__________________

My PC Themes . .
red_bull2oo6 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 11:02.


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