Raised This Month: $32 Target: $400
 8% 

[ H3LP ] Distance to floor


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DarthMan
Veteran Member
Join Date: Aug 2011
Old 01-27-2019 , 07:19   [ H3LP ] Distance to floor
Reply With Quote #1

Hello. I am trying to retrive the distance to floor.
Can anyone help me a bit here?
Thanks !

PHP Code:
bool TraceRayNoPlayers(const int iEnt, const int iMaskany iData)
{
    if(
iEnt == iData || IsPlayer(iEnt))
        return 
false;
    
    return 
true;
}

float GetDistanceToFloor(const int iID)
{
    
float fStart[3], fEnd[3];
    
bool bDucking;
    
    
GetEntPropVector(iIDProp_Send"m_vecOrigin"fStart);
    
    
bDucking = !!(GetEntityFlags(iID) & FL_DUCKING);
    
    if(
bDucking)
        
fStart[2] += 18.00;
    
    
fEnd[0] = fStart[0];
    
fEnd[1] = fStart[1];
    
fEnd[2] = fStart[2] - 8192.0;
    
    
Handle hTrace TR_TraceRayFilterEx(fStartfEndMASK_PLAYERSOLIDRayType_EndPointTraceRayNoPlayersiID);
    
    if(
TR_DidHit())
    {
        
float fDistance TR_GetFraction(hTrace);
        
        
CloseHandle(hTrace);
        
        
fDistance *= 8192.0;
        
        return 
fDistance;
    }
    
    
CloseHandle(hTrace);
    
    return -
1.0;


Last edited by DarthMan; 01-27-2019 at 07:23.
DarthMan is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 01-27-2019 , 08:00   Re: [ H3LP ] Distance to floor
Reply With Quote #2

PHP Code:
float GetDistanceToFloor(const int iID)
{
    
float fStart[3], fEnd[3];
    
//bool bDucking;
    
    
GetEntPropVector(iIDProp_Send"m_vecOrigin"fStart);
    
    
//bDucking = !!(GetEntityFlags(iID) & FL_DUCKING);
    
    //why? ducking wont change the base pos, unless the pos is the eye position...
    //if(bDucking)
    //    fStart[2] += 18.00;
    
    
fEnd[0] = fStart[0];
    
fEnd[1] = fStart[1];
    
fEnd[2] = fStart[2] - 8192.0;
    
    
Handle hTrace TR_TraceRayFilterEx(fStartfEndMASK_PLAYERSOLIDRayType_EndPointTraceRayNoPlayersiID);
    
    if(
TR_DidHit())
    {
        
float fEndPos[3];
        
TR_GetEndPosition(fEndPoshTrace);
        
float fDistance GetVectorDistance(fStartfEndPosfalse);
        
        
CloseHandle(hTrace);
        
        return 
fDistance;
    }
    
    
CloseHandle(hTrace);
    
    return -
1.0;

__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 01-27-2019 , 10:44   Re: [ H3LP ] Distance to floor
Reply With Quote #3

Quote:
Originally Posted by 1337norway View Post
PHP Code:
float GetDistanceToFloor(const int iID)
{
    
float fStart[3], fEnd[3];
    
//bool bDucking;
    
    
GetEntPropVector(iIDProp_Send"m_vecOrigin"fStart);
    
    
//bDucking = !!(GetEntityFlags(iID) & FL_DUCKING);
    
    //why? ducking wont change the base pos, unless the pos is the eye position...
    //if(bDucking)
    //    fStart[2] += 18.00;
    
    
fEnd[0] = fStart[0];
    
fEnd[1] = fStart[1];
    
fEnd[2] = fStart[2] - 8192.0;
    
    
Handle hTrace TR_TraceRayFilterEx(fStartfEndMASK_PLAYERSOLIDRayType_EndPointTraceRayNoPlayersiID);
    
    if(
TR_DidHit())
    {
        
float fEndPos[3];
        
TR_GetEndPosition(fEndPoshTrace);
        
float fDistance GetVectorDistance(fStartfEndPosfalse);
        
        
CloseHandle(hTrace);
        
        return 
fDistance;
    }
    
    
CloseHandle(hTrace);
    
    return -
1.0;

Thanks, I thought that ducking would make a difference but you are right, origin doesn't change if player is ducking.

Last edited by DarthMan; 01-27-2019 at 10:57.
DarthMan is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 01-27-2019 , 11:43   Re: [ H3LP ] Distance to floor
Reply With Quote #4

Quote:
Originally Posted by 1337norway View Post
PHP Code:
float GetDistanceToFloor(const int iID)
{
    
float fStart[3], fEnd[3];
    
//bool bDucking;
    
    
GetEntPropVector(iIDProp_Send"m_vecOrigin"fStart);
    
    
//bDucking = !!(GetEntityFlags(iID) & FL_DUCKING);
    
    //why? ducking wont change the base pos, unless the pos is the eye position...
    //if(bDucking)
    //    fStart[2] += 18.00;
    
    
fEnd[0] = fStart[0];
    
fEnd[1] = fStart[1];
    
fEnd[2] = fStart[2] - 8192.0;
    
    
Handle hTrace TR_TraceRayFilterEx(fStartfEndMASK_PLAYERSOLIDRayType_EndPointTraceRayNoPlayersiID);
    
    if(
TR_DidHit())
    {
        
float fEndPos[3];
        
TR_GetEndPosition(fEndPoshTrace);
        
float fDistance GetVectorDistance(fStartfEndPosfalse);
        
        
CloseHandle(hTrace);
        
        return 
fDistance;
    }
    
    
CloseHandle(hTrace);
    
    return -
1.0;

I tested and it doesn't seem to work, I did a print to server before returning fDistance and it didn't print anything in the console. Before I tried some other way using Trace too and it printed but the values were so high, smth like 800 or whatever.
DarthMan is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 01-27-2019 , 12:44   Re: [ H3LP ] Distance to floor
Reply With Quote #5

I made this to test out the function and it appears to be working fine on my end. Post some of your code where you call the function and print it.

PHP Code:
#include <sourcemod>
#include <sdktools>

bool:IsValidClient(clientbool:bAllowBots true)
{
    if(!(
<= client <= MaxClients) || !IsClientConnected(client) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots))
        return 
false;

    return 
true;
}

public 
bool:TraceRayNoPlayers(entitymaskany:data)
{
    if(
entity == data || (entity >= && entity <= MaxClients))
        return 
false;

    return 
true;
}

float GetDistanceToFloor(const int iID

    
float fStart[3], fEnd[3]; 
     
    
GetEntPropVector(iIDProp_Send"m_vecOrigin"fStart); 
   
    
fEnd[0] = fStart[0]; 
    
fEnd[1] = fStart[1]; 
    
fEnd[2] = fStart[2] - 8192.0
     
    
Handle hTrace TR_TraceRayFilterEx(fStartfEndMASK_PLAYERSOLIDRayType_EndPointTraceRayNoPlayersiID); 
     
    if(
TR_DidHit()) 
    { 
        
float fEndPos[3]; 
        
TR_GetEndPosition(fEndPoshTrace); 
        
float fDistance GetVectorDistance(fStartfEndPosfalse); 
         
        
CloseHandle(hTrace); 
         
        return 
fDistance
    } 
     
    
CloseHandle(hTrace); 
     
    return -
1.0
}  

public 
void OnGameFrame() 
{
    static 
int slow 0;
    
slow++;
    if(
slow == 100)
    {
        
slow 0;

        for(new 
client 1client <= MaxClientsclient++) 
        { 
            if(!
IsValidClient(client) || IsFakeClient(client))
                continue;

            
PrintToChat(client"Distance: %f"GetDistanceToFloor(client));
        }
    }

It could be your TraceRayNoPlayers filter. Also the last argument of GetVectorDistance is true or false to square, resulting in a bigger or smaller number.
__________________
I highly recommend joining the SourceMod Discord Server for real time support.

Last edited by backwards; 01-27-2019 at 12:47.
backwards is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 01-27-2019 , 12:57   Re: [ H3LP ] Distance to floor
Reply With Quote #6

Quote:
Originally Posted by 1337norway View Post
I made this to test out the function and it appears to be working fine on my end. Post some of your code where you call the function and print it.

PHP Code:
#include <sourcemod>
#include <sdktools>

bool:IsValidClient(clientbool:bAllowBots true)
{
    if(!(
<= client <= MaxClients) || !IsClientConnected(client) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots))
        return 
false;

    return 
true;
}

public 
bool:TraceRayNoPlayers(entitymaskany:data)
{
    if(
entity == data || (entity >= && entity <= MaxClients))
        return 
false;

    return 
true;
}

float GetDistanceToFloor(const int iID

    
float fStart[3], fEnd[3]; 
     
    
GetEntPropVector(iIDProp_Send"m_vecOrigin"fStart); 
   
    
fEnd[0] = fStart[0]; 
    
fEnd[1] = fStart[1]; 
    
fEnd[2] = fStart[2] - 8192.0
     
    
Handle hTrace TR_TraceRayFilterEx(fStartfEndMASK_PLAYERSOLIDRayType_EndPointTraceRayNoPlayersiID); 
     
    if(
TR_DidHit()) 
    { 
        
float fEndPos[3]; 
        
TR_GetEndPosition(fEndPoshTrace); 
        
float fDistance GetVectorDistance(fStartfEndPosfalse); 
         
        
CloseHandle(hTrace); 
         
        return 
fDistance
    } 
     
    
CloseHandle(hTrace); 
     
    return -
1.0
}  

public 
void OnGameFrame() 
{
    static 
int slow 0;
    
slow++;
    if(
slow == 100)
    {
        
slow 0;

        for(new 
client 1client <= MaxClientsclient++) 
        { 
            if(!
IsValidClient(client) || IsFakeClient(client))
                continue;

            
PrintToChat(client"Distance: %f"GetDistanceToFloor(client));
        }
    }

It could be your TraceRayNoPlayers filter. Also the last argument of GetVectorDistance is true or false to square, resulting in a bigger or smaller number.
PHP Code:
stock bool TraceRayNoPlayers(const int iEnt, const int iMaskany iData)
{
    if(
iEnt == iData || IsPlayer(iEnt))
        return 
false;
    
    return 
true;
}

stock int IsPlayer(int iEnt)
{
    return 
<= iEnt <= MaxClients;

On the OnPlayerRunCmd Action, I checked if it is valid and is not a bot, then checked if the player was pressing the use key and inside if(GetDistanceToFloor(iID) <= 100.0 && !g_bHasParachute[iID - 1] && !IsValidEntity(g_szParaEnt[iID - 1])) return Plugin_Continue;

I did a server print and it didn't print anything unfortunately.
DarthMan is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 01-27-2019 , 13:02   Re: [ H3LP ] Distance to floor
Reply With Quote #7

I belive it's an issue somewhere else in your code as the snippet i posted works.
possibly this part:
PHP Code:
!g_bHasParachute[iID 1] && !IsValidEntity(g_szParaEnt[iID 1])) 
just comment out these checks and try running it without anything else preventing the GetDistance function from being called
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 01-27-2019 , 16:22   Re: [ H3LP ] Distance to floor
Reply With Quote #8

Quote:
Originally Posted by 1337norway View Post
I belive it's an issue somewhere else in your code as the snippet i posted works.
possibly this part:
PHP Code:
!g_bHasParachute[iID 1] && !IsValidEntity(g_szParaEnt[iID 1])) 
just comment out these checks and try running it without anything else preventing the GetDistance function from being called
Sure. I will check tomorrow night, since I am dealing with another more important issue right now.
DarthMan is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 02-04-2019 , 14:40   Re: [ H3LP ] Distance to floor
Reply With Quote #9

A little bit simplier version: https://forums.alliedmods.net/showthread.php?t=161305
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 02-05-2019 , 05:45   Re: [ H3LP ] Distance to floor
Reply With Quote #10

I personally prefer using TraceHull, whose result origin is an origin you can teleport into without getting stuck inside the ground ( hull takes your size into account, not assuming you're an entity that is 0 sized )
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 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 19:59.


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