Raised This Month: $ Target: $400
 0% 

Get distance from ground


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
FromTheFuture
Senior Member
Join Date: Jan 2013
Old 05-08-2013 , 08:42   Get distance from ground
Reply With Quote #1

How to get distance from ground when player is in the air?
FromTheFuture is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-08-2013 , 09:05   Re: Get distance from ground
Reply With Quote #2

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().
__________________
Arkshine is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 05-08-2013 , 09:33   Re: Get distance from ground
Reply With Quote #3

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 ); }
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 05-08-2013 , 12:26   Re: Get distance from ground
Reply With Quote #4

unfortunately that will fail when the player is on/over an edge of a higher point
jimaway is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-08-2013 , 19:51   Re: Get distance from ground
Reply With Quote #5

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

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 05-09-2013 , 09:29   Re: Get distance from ground
Reply With Quote #6

Quote:
Originally Posted by jimaway View Post
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; }
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.

Last edited by hornet; 05-09-2013 at 09:31.
hornet is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-09-2013 , 10:01   Re: Get distance from ground
Reply With Quote #7

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;

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 05-09-2013 , 12:05   Re: Get distance from ground
Reply With Quote #8

Quote:
Originally Posted by ConnorMcLeod View Post
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?
.Dare Devil. is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-09-2013 , 19:31   Re: Get distance from ground
Reply With Quote #9

Quote:
Originally Posted by .Dare Devil. View Post
Is there possible to do this without player entity, without entity just a origin?
You already tried such code with trace_HULL ?
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
FromTheFuture
Senior Member
Join Date: Jan 2013
Old 05-09-2013 , 11:22   Re: Get distance from ground
Reply With Quote #10

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
FromTheFuture 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 10:55.


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