Raised This Month: $138 Target: $400
 34% 

TraceHull can't build some rays


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine
Old 09-03-2019 , 13:31   TraceHull can't build some rays
Reply With Quote #1

Hi!

Can you help me please, find out why TraceHull can't find end position for some (identical) places on the map?

(see screenshot)

PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdktools>

int g_sprite;

#define PRINT_LASER 1

#define RED     {255, 0, 0, 255}
#define GREEN     {0, 255, 0, 255}

public void OnPluginStart()
{
    
RegAdminCmd("sm_distdir"CmdDistanceDirADMFLAG_ROOT"Get distance between you and end point of direction you are looking at (considering collision)");
}

public 
void OnMapStart()
{
    
g_sprite PrecacheModel("materials/sprites/laser.vmt"true);
}

public 
Action CmdDistanceDir(int clientint args)
{
    
float vOrigin[3], vEnd[3], vEndNonCol[3];
    
float dist;
    
    
GetClientAbsOrigin(clientvOrigin);
    
    if (
GetDirectionEndPoint(clientvEnd))
    {
        
dist GetVectorDistance(vOriginvEnd);
        
PrintToChat(client"Directional end point: %f %f %f. Distance: %f"vEnd[0], vEnd[1], vEnd[2], dist);
        
        if (
GetNonCollideEndPoint(clientvEndvEndNonCol))
        {
            
dist GetVectorDistance(vOriginvEndNonCol);
            
PrintToChat(client"Non-collide end point: %f %f %f. Distance: %f"vEndNonCol[0], vEndNonCol[1], vEndNonCol[2], dist);
        }
        else {
            
PrintToChat(client"Non-collide end point doesn't found.");
        }
    }
    else {
        
PrintToChat(client"Directional end point doesn't found.");
    }
    
    return 
Plugin_Handled;
}


stock bool GetDirectionEndPoint(int clientfloat vEndPos[3])
{
    
float vDir[3], vPos[3];
    
GetClientEyePosition(clientvPos);
    
GetClientEyeAngles(clientvDir);
    
    
Handle hTrace TR_TraceRayFilterEx(vPosvDirMASK_PLAYERSOLIDRayType_InfiniteTraceRayNoPlayersclient);
    if (
hTrace != INVALID_HANDLE) {
        if(
TR_DidHit(hTrace)) {
            
TR_GetEndPosition(vEndPoshTrace);
            
CloseHandle(hTrace);
            
#if PRINT_LASER
                
LaserP(vPosvEndPosRED);
            
#endif
            
return true;
        }
        
CloseHandle(hTrace);
    }
    return 
false;
}

stock bool GetNonCollideEndPoint(int clientfloat vEnd[3], float vEndNonCol[3])
{
    
float vMin[3], vMax[3], vStart[3];
    
GetClientAbsOrigin(clientvStart);
    
GetClientMins(clientvMin);
    
GetClientMaxs(clientvMax);
    
vStart[2] += 20.0// if nearby area is irregular
    
Handle hTrace TR_TraceHullFilterEx(vStartvEndvMinvMaxMASK_PLAYERSOLIDTraceRayNoPlayersclient);
    if (
hTrace != INVALID_HANDLE) {
        if(
TR_DidHit(hTrace))
        {
            
TR_GetEndPosition(vEndNonColhTrace);
            
CloseHandle(hTrace);
            
#if PRINT_LASER
                
LaserP(vStartvEndNonColGREEN5.0);
            
#endif
            
return true;
        }
        
CloseHandle(hTrace);
    }
    return 
false;
}

public 
bool TraceRayNoPlayers(int entityint maskany data)
{
    if(
entity == data || (entity >= && entity <= MaxClients))
    {
        return 
false;
    }
    return 
true;
}

stock void LaserP(float start[3], float end[3], int color[4], float width 3.0)
{
    
TE_SetupBeamPoints(startendg_sprite00010.0widthwidth70.0color5);
    
TE_SendToAll();

P.S. Red laser is - TR_TraceRayFilterEx, Green - is TR_TraceHullFilterEx.

__________________
Expert of CMD/VBS/VB6. Malware analyst.
[My plugins] [My tools] [GitHub]
Dragokas is offline
Reply


Thread Tools
Display Modes

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 03:38.


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