Raised This Month: $12 Target: $400
 3% 

Check if player is looking at FSOLID_NOT_SOLID entity?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Trsak
Junior Member
Join Date: Jul 2018
Old 09-02-2018 , 05:57   Check if player is looking at FSOLID_NOT_SOLID entity?
Reply With Quote #1

Hey there,
is there any way to check, if player is looking at FSOLID_NOT_SOLID entity?

I use this filter:
Code:
stock int getClientViewEntity(int client) {
    float m_vecOrigin[3];
    float m_angRotation[3];
    GetClientEyePosition(client, m_vecOrigin);
    GetClientEyeAngles(client, m_angRotation);
    Handle tr = TR_TraceRayFilterEx(m_vecOrigin, m_angRotation, MASK_ALL, RayType_Infinite, TRDontHitSelf, client);
    int pEntity = -1;
    if (TR_DidHit(tr)) {
        pEntity = TR_GetEntityIndex(tr);
		PrintToChatAll("GOT HIT %i", pEntity);
        delete tr;
        if (!IsValidEntity(pEntity))
            return -1;

        return pEntity;
    }
    delete tr;
    return -1;
}

stock bool TRDontHitSelf(int entity, int mask, any data) {
    if (entity == data)
        return false;
    return true;
}
but it detects only solid entities.
Trsak is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 09-16-2018 , 14:42   Re: Check if player is looking at FSOLID_NOT_SOLID entity?
Reply With Quote #2

Quote:
Originally Posted by Trsak View Post
Hey there,
is there any way to check, if player is looking at FSOLID_NOT_SOLID entity?

I use this filter:
Code:
stock int getClientViewEntity(int client) {
    float m_vecOrigin[3];
    float m_angRotation[3];
    GetClientEyePosition(client, m_vecOrigin);
    GetClientEyeAngles(client, m_angRotation);
    Handle tr = TR_TraceRayFilterEx(m_vecOrigin, m_angRotation, MASK_ALL, RayType_Infinite, TRDontHitSelf, client);
    int pEntity = -1;
    if (TR_DidHit(tr)) {
        pEntity = TR_GetEntityIndex(tr);
		PrintToChatAll("GOT HIT %i", pEntity);
        delete tr;
        if (!IsValidEntity(pEntity))
            return -1;

        return pEntity;
    }
    delete tr;
    return -1;
}

stock bool TRDontHitSelf(int entity, int mask, any data) {
    if (entity == data)
        return false;
    return true;
}
but it detects only solid entities.

If it's impossible, loop through all entities, change them to solid, make the trace, and make them back to not solid.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 09-18-2018 , 19:40   Re: Check if player is looking at FSOLID_NOT_SOLID entity?
Reply With Quote #3

Sadly none of the traceray APIs can hit FSOLID_NOT_SOLID ents as it doesn't use the partition they're tracked in, there has been some work (and some more PRs are upcoming) by a few people to re-implement tracerays on top of the low-level primitives provided by the engine (rather than the trace API) that provide a lot more functionality (including the ability to do this), so keep an eye on changes to SM.
__________________
asherkin 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:50.


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