AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_distance_f problem [ solved ] (https://forums.alliedmods.net/showthread.php?t=250055)

red_bull2oo6 10-17-2014 15:37

get_distance_f problem [ solved ]
 
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 ) ?

fysiks 10-17-2014 15:51

Re: get_distance_f problem
 
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).

claudiuhks 10-19-2014 12:33

Re: get_distance_f problem
 
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.

avril-lavigne 10-20-2014 14:53

Re: get_distance_f problem
 
today I used entity_range

it works 100%

fysiks 10-20-2014 23:25

Re: get_distance_f problem
 
Quote:

Originally Posted by avril-lavigne (Post 2213619)
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.

red_bull2oo6 10-22-2014 07:22

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

i'll edit later. ty for your answers.

claudiuhks 10-22-2014 09:51

Re: get_distance_f problem
 
Quote:

Originally Posted by red_bull2oo6 (Post 2214377)
@fysiks i'll try your idea tonight when i reach home.
@claudiuhsk i suk at c++ :D 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);



red_bull2oo6 10-24-2014 15:07

Re: get_distance_f problem
 
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


All times are GMT -4. The time now is 17:35.

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