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

Detect clients a player can see


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
popey456963
Member
Join Date: Mar 2016
Old 09-25-2017 , 23:39   Detect clients a player can see
Reply With Quote #1

Is there a way to get all clients visible to a player? At the moment I'm doing this somewhat awful trace ray:

Code:
bool TraceHeadToHead(int client, int target, float clientLoc[3], float targetLoc[3])
{
	clientLoc[2] += g_Shadow_OffsetHead;
	targetLoc[2] += g_Shadow_OffsetFeet;
	int color[4] =  { 0, 255, 0, 255 };
	TR_TraceRayFilter(clientLoc, targetLoc, MASK_SHOT, RayType_EndPoint, TraceRayDontHitSelf, client);
	TE_SetupBeamPoints(clientLoc, targetLoc, g_iSprite, 0, 0, 0, 5.0, 3.0, 3.0, 10, 0.0, color, 0);
	TE_SendToAll();
	
	return (!TR_DidHit() || TR_GetEntityIndex() == target);
}
(With other functions for arms, legs, body, etc.) Then working out whether the angle of this beam is within the FOV (which we can retrieve from the client). Yet it just feels to me like there should be a better way that doesn't involve setting up half a dozen trace rays and calculating angles.

(This is in relation to the CS:GO gamemode)

Last edited by popey456963; 09-25-2017 at 23:42.
popey456963 is offline
Despirator
Senior Member
Join Date: Jun 2011
Location: Kazakhstan ->Shymkent
Old 09-29-2017 , 02:05   Re: Detect clients a player can see
Reply With Quote #2

I use the code from SMAC

PHP Code:
bool:IsAbleToSee(entityclient)
{
    
// Skip all traces if the player isn't within the field of view.
    // - Temporarily disabled until eye angle prediction is added.
    // if (IsInFieldOfView(g_vEyePos[client], g_vEyeAngles[client], g_vAbsCentre[entity]))
    
    
decl Float:vecOrigin[3], Float:vecEyePos[3];
    
GetClientAbsOrigin(entityvecOrigin);
    
GetClientEyePosition(clientvecEyePos);
    
    
// Check if centre is visible.
    
if (IsPointVisible(vecEyePosvecOrigin))
    {
        return 
true;
    }
    
    
decl Float:vecEyePos_ent[3], Float:vecEyeAng[3];
    
GetClientEyeAngles(entityvecEyeAng);
    
GetClientEyePosition(entityvecEyePos_ent);
    
// Check if weapon tip is visible.
    
if (IsFwdVecVisible(vecEyePosvecEyeAngvecEyePos_ent))
    {
        return 
true;
    }
    
    
decl Float:mins[3], Float:maxs[3];
    
GetClientMins(clientmins);
    
GetClientMaxs(clientmaxs);
    
// Check outer 4 corners of player.
    
if (IsRectangleVisible(vecEyePosvecOriginminsmaxs1.30))
    {
        return 
true;
    }

    
// Check inner 4 corners of player.
    
if (IsRectangleVisible(vecEyePosvecOriginminsmaxs0.65))
    {
        return 
true;
    }
    
    return 
false;
}

stock bool:IsInFieldOfView(client, const Float:start[3], const Float:angles[3], Float:fov 90.0)
{
    
decl Float:normal[3], Float:plane[3];
    
    
decl Float:end[3];
    
GetClientAbsOrigin(clientend);
    
    
GetAngleVectors(anglesnormalNULL_VECTORNULL_VECTOR);
    
SubtractVectors(endstartplane);
    
NormalizeVector(planeplane);
    
    return 
GetVectorDotProduct(planenormal) > Cosine(DegToRad(fov/2.0));
}

public 
bool:Filter_NoPlayers(entitymask)
{
    return (
entity MaxClients && !(GetEntPropEnt(entityProp_Data"m_hOwnerEntity") <= MaxClients));
}

bool:IsPointVisible(const Float:start[3], const Float:end[3])
{
    
TR_TraceRayFilter(startendMASK_VISIBLERayType_EndPointFilter_NoPlayers);

    return 
TR_GetFraction() == 1.0;
}

bool:IsFwdVecVisible(const Float:start[3], const Float:angles[3], const Float:end[3])
{
    
decl Float:fwd[3];
    
    
GetAngleVectors(anglesfwdNULL_VECTORNULL_VECTOR);
    
ScaleVector(fwd50.0);
    
AddVectors(endfwdfwd);

    return 
IsPointVisible(startfwd);
}

bool:IsRectangleVisible(const Float:start[3], const Float:end[3], const Float:mins[3], const Float:maxs[3], Float:scale=1.0)
{
    new 
Float:ZpozOffset maxs[2];
    new 
Float:ZnegOffset mins[2];
    new 
Float:WideOffset = ((maxs[0] - mins[0]) + (maxs[1] - mins[1])) / 4.0;

    
// This rectangle is just a point!
    
if (ZpozOffset == 0.0 && ZnegOffset == 0.0 && WideOffset == 0.0)
    {
        return 
IsPointVisible(startend);
    }

    
// Adjust to scale.
    
ZpozOffset *= scale;
    
ZnegOffset *= scale;
    
WideOffset *= scale;
    
    
// Prepare rotation matrix.
    
decl Float:angles[3], Float:fwd[3], Float:right[3];

    
SubtractVectors(startendfwd);
    
NormalizeVector(fwdfwd);

    
GetVectorAngles(fwdangles);
    
GetAngleVectors(anglesfwdrightNULL_VECTOR);

    
decl Float:vRectangle[4][3], Float:vTemp[3];

    
// If the player is on the same level as us, we can optimize by only rotating on the z-axis.
    
if (FloatAbs(fwd[2]) <= 0.7071)
    {
        
ScaleVector(rightWideOffset);
        
        
// Corner 1, 2
        
vTemp end;
        
vTemp[2] += ZpozOffset;
        
AddVectors(vTemprightvRectangle[0]);
        
SubtractVectors(vTemprightvRectangle[1]);
        
        
// Corner 3, 4
        
vTemp end;
        
vTemp[2] += ZnegOffset;
        
AddVectors(vTemprightvRectangle[2]);
        
SubtractVectors(vTemprightvRectangle[3]);
        
    }
    else if (
fwd[2] > 0.0// Player is below us.
    
{
        
fwd[2] = 0.0;
        
NormalizeVector(fwdfwd);
        
        
ScaleVector(fwdscale);
        
ScaleVector(fwdWideOffset);
        
ScaleVector(rightWideOffset);
        
        
// Corner 1
        
vTemp end;
        
vTemp[2] += ZpozOffset;
        
AddVectors(vTemprightvTemp);
        
SubtractVectors(vTempfwdvRectangle[0]);
        
        
// Corner 2
        
vTemp end;
        
vTemp[2] += ZpozOffset;
        
SubtractVectors(vTemprightvTemp);
        
SubtractVectors(vTempfwdvRectangle[1]);
        
        
// Corner 3
        
vTemp end;
        
vTemp[2] += ZnegOffset;
        
AddVectors(vTemprightvTemp);
        
AddVectors(vTempfwdvRectangle[2]);
        
        
// Corner 4
        
vTemp end;
        
vTemp[2] += ZnegOffset;
        
SubtractVectors(vTemprightvTemp);
        
AddVectors(vTempfwdvRectangle[3]);
    }
    else 
// Player is above us.
    
{
        
fwd[2] = 0.0;
        
NormalizeVector(fwdfwd);
        
        
ScaleVector(fwdscale);
        
ScaleVector(fwdWideOffset);
        
ScaleVector(rightWideOffset);

        
// Corner 1
        
vTemp end;
        
vTemp[2] += ZpozOffset;
        
AddVectors(vTemprightvTemp);
        
AddVectors(vTempfwdvRectangle[0]);
        
        
// Corner 2
        
vTemp end;
        
vTemp[2] += ZpozOffset;
        
SubtractVectors(vTemprightvTemp);
        
AddVectors(vTempfwdvRectangle[1]);
        
        
// Corner 3
        
vTemp end;
        
vTemp[2] += ZnegOffset;
        
AddVectors(vTemprightvTemp);
        
SubtractVectors(vTempfwdvRectangle[2]);
        
        
// Corner 4
        
vTemp end;
        
vTemp[2] += ZnegOffset;
        
SubtractVectors(vTemprightvTemp);
        
SubtractVectors(vTempfwdvRectangle[3]);
    }

    
// Run traces on all corners.
    
for (new 04i++)
    {
        if (
IsPointVisible(startvRectangle[i]))
        {
            return 
true;
        }
    }

    return 
false;

Despirator is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 09-29-2017 , 08:36   Re: Detect clients a player can see
Reply With Quote #3

Try this:
https://github.com/shanapu/MyJailbre....inc#L471-L507
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!
Papero 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 04:36.


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