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

Get entity player is pointing at...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
imported_hippo
Junior Member
Join Date: Mar 2006
Old 04-16-2006 , 17:35   Get entity player is pointing at...
Reply With Quote #1

Is there any way to get the entity / entity index a player is pointing at with their crosshairs?

I have looked through the sdk and didn't find anything that looked useful. I may be blind, which is why I am asking.

I just need a function name and the header file its in. I should be able to figure out the rest (vfunc hooking, etc).

Hippo
imported_hippo is offline
awuh0
Senior Member
Join Date: Apr 2005
Location: /dev/null
Old 04-16-2006 , 18:41  
Reply With Quote #2

I did this with geteyeangles and engine trace. Later Ill post some code if you need it.
__________________
~The_wUh
_________________
Ph34r teh zombies!!!
find a better way to play CSS, connect to...
thewuh.servebeer.com
thecircus.servebeer.com
awuh0 is offline
Send a message via ICQ to awuh0 Send a message via AIM to awuh0 Send a message via MSN to awuh0
showdax
Senior Member
Join Date: Dec 2004
Old 04-18-2006 , 17:35  
Reply With Quote #3

Quote:
Originally Posted by awuh0
I did this with geteyeangles and engine trace. Later Ill post some code if you need it.
Could you post this code?
showdax is offline
Send a message via MSN to showdax
awuh0
Senior Member
Join Date: Apr 2005
Location: /dev/null
Old 04-19-2006 , 01:41  
Reply With Quote #4

sure, I posted it on sourceplugins.

This is from the hook mod that will prolly get released soon.

http://sourceplugins.com/viewtopic.php?p=29162#29162
__________________
~The_wUh
_________________
Ph34r teh zombies!!!
find a better way to play CSS, connect to...
thewuh.servebeer.com
thecircus.servebeer.com
awuh0 is offline
Send a message via ICQ to awuh0 Send a message via AIM to awuh0 Send a message via MSN to awuh0
showdax
Senior Member
Join Date: Dec 2004
Old 04-19-2006 , 02:01  
Reply With Quote #5

Code:
        class CTraceFilterEntitiesOnlyReally: public CTraceFilterEntitiesOnly
        {
                bool ShouldHitEntity(IHandleEntity*, int)
                {
                        return true;
                }
        };

        void g_PlayerRunCommand(CUserCmd* cmd, IMoveHelper* move)
        {
                if ((cmd->buttons & 32) == 0)
                        RETURN_META(MRES_IGNORED);

                CBasePlayer* player = META_IFACEPTR(CBasePlayer);
                edict_t* entity = g_BaseMap[reinterpret_cast<CBaseEntity*>(player)];
                if (!entity)
                        RETURN_META(MRES_IGNORED);
#if 0
                IPlayerInfo* info = g_PlayerInfoManager->GetPlayerInfo(entity);
                if (!info)
                        RETURN_META(MRES_IGNORED);
#endif
                Vector start = reinterpret_cast<SBasePlayer*>(player)->EyePosition();
                Vector end;
                AngleVectors(reinterpret_cast<SBasePlayer*>(player)->EyeAngles(), &end);
                end.NormalizeInPlace();
                end = start + end * 64;

                Ray_t ray;
                ray.Init(start, end);

                CTraceFilterEntitiesOnlyReally filter;
                trace_t result;
                g_EngineTrace->TraceRay(ray, MASK_SHOT, &filter, &result);

                H_CONPRINTF("Hit: 0x%x\n", result.m_pEnt);

                edict_t* target = g_BaseMap[result.m_pEnt];
                if (!target)
                        RETURN_META(MRES_IGNORED);

                int index = g_Engine->IndexOfEdict(target);
                H_CONPRINTF("Hit: %s\n", g_Engine->GetClientConVarValue(index, "name"));

                RETURN_META(MRES_HANDLED);
        }
What am I doing wrong? With this, it sometimes says I'm hitting myself, and I have to aim really weird to hit another player.

Oh, and is there any simple way to visualize the ray? I tried turning on r_visualizetraces but it's not very helpful.
showdax is offline
Send a message via MSN to showdax
awuh0
Senior Member
Join Date: Apr 2005
Location: /dev/null
Old 04-19-2006 , 07:47  
Reply With Quote #6

Your problem is on this line...

Quote:
Originally Posted by showdax
Code:
                end = start + end * 64;
instead of that line do the following

Code:
// before you trace the ray you want to move the start point out of the players body
start += end*64;
// And set the maximum distance you want to trace too.
Vector end = start + end*10000000;
Also, to my knowledge there is no CTraceFilterEntitiesOnlyReally
I have seen; CTraceFilterEntitiesOnly, CTraceFilterWorldOnly, CTraceFilterWorldAndPropsOnly, and CTraceFilterHitAll

And no, sorry Im not aware of any way to visualize it other than using the effects->beam and feeding it the same inputs.
__________________
~The_wUh
_________________
Ph34r teh zombies!!!
find a better way to play CSS, connect to...
thewuh.servebeer.com
thecircus.servebeer.com
awuh0 is offline
Send a message via ICQ to awuh0 Send a message via AIM to awuh0 Send a message via MSN to awuh0
API
Veteran Member
Join Date: May 2006
Old 04-19-2006 , 11:05  
Reply With Quote #7

You could just enable temp_ents. There is a code posted by mani for windows and linux to get it working. I am going to sigscan it though.
__________________
API is offline
Send a message via AIM to API
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 11:11.


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