AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get distance from ground (https://forums.alliedmods.net/showthread.php?t=215478)

FromTheFuture 05-08-2013 08:42

Get distance from ground
 
How to get distance from ground when player is in the air?

Arkshine 05-08-2013 09:05

Re: Get distance from ground
 
Throws a traceline vertically from player's feet to the ground, retrieve the end position ; and get the distance using for example get_distance_f().

hornet 05-08-2013 09:33

Re: Get distance from ground
 
Try this:
Code:
Float:distance_to_ground( const id ) {     static Float:flOrigin[ 3 ], Float:flEnd[ 3 ], tr;     pev( id, pev_origin, flOrigin );         xs_vec_sub( flOrigin, Float:{ 0.0, 0.0, 9999.0 }, flEnd );         engfunc( EngFunc_TraceLine, flOrigin, flEnd, IGNORE_MONSTERS, 0, tr );         get_tr2( tr, TR_vecEndPos, flEnd );         if( pev( id, pev_button ) & IN_DUCK )         flEnd[ 2 ] += 18.0;     else         flEnd[ 2 ] += 36.0;         return vector_distance( flOrigin, flEnd ); }

jimaway 05-08-2013 12:26

Re: Get distance from ground
 
unfortunately that will fail when the player is on/over an edge of a higher point

ConnorMcLeod 05-08-2013 19:51

Re: Get distance from ground
 
I know that engine doesn't use same hull as dll for crouch players. But i've seen that dll has a way to tell the engine which hulls it is using.
So, finally, don't know if with TraceHull engine uses correct hull when player is crouched.
So, do as if player was not crouched, can be a problem if player is right under a ceil.

PHP Code:

Float:distance_to_groundid )
{
    new 
Float:start[3], Float:end[3], bool:bDucking;
    
entity_get_vector(idEV_VEC_originstart);
    
bDucking = !!(entity_get_int(idEV_INT_flags) & FL_DUCKING);
    if( 
bDucking )
    {
        
start[2] += 18.0;
    }

    
end[0] = start[0];
    
end[1] = start[1];
    
end[2] = start[2] - 9999.0;

    new 
ptr create_tr2();
    
engfunc(EngFunc_TraceHullstartdestIGNORE_MONSTERSHULL_HUMANidptr);
    new 
Float:distance;
    
get_tr2(ptrTR_flFractiondistance);
    
free_tr2(ptr);

    if( 
distance 1.0 )
    {
        
distance *= 9999.0;
        if( 
bDucking )
        {
            
distance -= 18.0;
            return 
distance;
        }
    }
    return -
1.0



hornet 05-09-2013 09:29

Re: Get distance from ground
 
Quote:

Originally Posted by jimaway (Post 1948183)
unfortunately that will fail when the player is on/over an edge of a higher point

Good thinking.

To fix Connor's:
Code:
Float:distance_to_ground( id ) {     new Float:start[3], Float:end[3], bool:bDucking;     entity_get_vector(id, EV_VEC_origin, start);     bDucking = !!(entity_get_int(id, EV_INT_flags) & FL_DUCKING);     if( bDucking )     {         start[2] += 18.0;     }         end[0] = start[0];     end[1] = start[1];     end[2] = start[2] - 9999.0;         new ptr = create_tr2();     engfunc(EngFunc_TraceHull, start, end, IGNORE_MONSTERS, HULL_HUMAN, id, ptr);     new Float:distance;     get_tr2(ptr, TR_flFraction, distance);     free_tr2(ptr);     distance *= 9999.0;             return distance; }

ConnorMcLeod 05-09-2013 10:01

Re: Get distance from ground
 
Yes, my bad, then we can remove useless stuff.
Also, should consider that returning 9999 means there is a problem ;)

PHP Code:

Float:distance_to_groundid )
{
    new 
Float:start[3], Float:end[3];
    
entity_get_vector(idEV_VEC_originstart);
    if( 
entity_get_int(idEV_INT_flags) & FL_DUCKING )
    {
        
start[2] += 18.0;
    }

    
end[0] = start[0];
    
end[1] = start[1];
    
end[2] = start[2] - 9999.0;

    new 
ptr create_tr2();
    
engfunc(EngFunc_TraceHullstartendIGNORE_MONSTERSHULL_HUMANidptr);
    new 
Float:fraction;
    
get_tr2(ptrTR_flFractionfraction);
    
free_tr2(ptr);

    return 
fraction 9999.0;



FromTheFuture 05-09-2013 11:22

Re: Get distance from ground
 
I can remove this? :)
PHP Code:

    if( entity_get_int(idEV_INT_flags) & FL_DUCKING 
    { 
        
start[2] += 18.0
    } 

Because I'm check before this on FL_ONGROUND.
And what is the maximum height of the jump player?
When I check - I'm get no more than 44.0

.Dare Devil. 05-09-2013 12:05

Re: Get distance from ground
 
Quote:

Originally Posted by ConnorMcLeod (Post 1948748)
Yes, my bad, then we can remove useless stuff.
Also, should consider that returning 9999 means there is a problem ;)

PHP Code:

Float:distance_to_groundid )
{
    new 
Float:start[3], Float:end[3];
    
entity_get_vector(idEV_VEC_originstart);
    if( 
entity_get_int(idEV_INT_flags) & FL_DUCKING )
    {
        
start[2] += 18.0;
    }

    
end[0] = start[0];
    
end[1] = start[1];
    
end[2] = start[2] - 9999.0;

    new 
ptr create_tr2();
    
engfunc(EngFunc_TraceHullstartendIGNORE_MONSTERSHULL_HUMANidptr);
    new 
Float:fraction;
    
get_tr2(ptrTR_flFractionfraction);
    
free_tr2(ptr);

    return 
fraction 9999.0;



Is there possible to do this without player entity, without entity just a origin?

jimaway 05-09-2013 15:28

Re: Get distance from ground
 
why wont you just try?


All times are GMT -4. The time now is 10:55.

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