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

Get hitscan shot coordinates


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
glittershii
Junior Member
Join Date: Oct 2017
Old 12-02-2017 , 16:56   Get hitscan shot coordinates
Reply With Quote #1

I'm looking for a way to get the absolute coordinates (x,y,z) of a hitscan shot. I've read about using bullet_impact but that's not a valid event in the game I'm scripting for (No More Room in Hell).

TakeDamage only works for player hits. I need other shots as well (in fact, player hits won't even reg due to a hitbox bug).
A direct ray trace using the shooter's view coordinates doesn't account for spread, making it inaccurate.

Is there some other event I can use instead?

Last edited by glittershii; 12-03-2017 at 14:15.
glittershii is offline
glittershii
Junior Member
Join Date: Oct 2017
Old 12-03-2017 , 14:18   Re: Get hitscan shot coordinates
Reply With Quote #2

My code. I need a trace ray that goes from the client's eye position to the place where the shot landed (pretty much recreating the trajectory of the bullet)

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#pragma newdecls required

public void OnPluginStart()
{
    
HookEvent("weapon_fired"Event_WeaponFired);
}

public 
Action Event_WeaponFired(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"player_id"));
    
float startpoint[3]
    
float endpoint[3];

    
GetClientEyePosition(clientstartpoint);
    
    
//Need endpoint value, bullet coordinates

    
TR_TraceRayFilter(startpointendpointMASK_SOLIDRayType_EndPointRayDontHitSelfclient);

    if(
TR_DidHit() == true)
    {
        
//do things
    
}
}

public 
bool RayDontHitSelf(int entity,int contentsMaskany data)
{
    return (
entity != data);

Side question: How costly are trace rays?

Last edited by glittershii; 12-03-2017 at 14:48.
glittershii is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 12-03-2017 , 23:35   Re: Get hitscan shot coordinates
Reply With Quote #3

Rather than doing from start->end you can choose start point and angles by using RayType_Infinite, then get endpoint from there.
Example:
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#pragma newdecls required

public void OnPluginStart()
{
    
HookEvent("weapon_fired"Event_WeaponFired);
}

public 
Action Event_WeaponFired(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"player_id"));
    
float startpoint[3]
    
float endpoint[3];

    
GetClientEyePosition(clientstartpoint);
    
GetClientEyeAngles(clientangle);

    
TR_TraceRayFilter(startpointangleMASK_SOLIDRayType_InfiniteRayDontHitSelfclient);

    if(
TR_DidHit())
    {
        
TR_GetEndPosition(endpoint);
        
// Do whatever you need
    
}
}

public 
bool RayDontHitSelf(int entity,int contentsMaskany data)
{
    return (
entity != data);

As for cost of tracerays I wouldn't worry about it until it actually appears to cause issues. I've seen lots of plugins that create traces every frame for every player with seemingly no impact to performance.

Last edited by hmmmmm; 12-04-2017 at 00:24.
hmmmmm is offline
glittershii
Junior Member
Join Date: Oct 2017
Old 12-04-2017 , 08:50   Re: Get hitscan shot coordinates
Reply With Quote #4

Thanks for the response, but using GetClientEyeAngles will just shoot the ray in a straight line. It won't account for bullet spread. That's why I need an endpoint and I need it to be the coordinates of where the bullet hits.
glittershii is offline
Kinsi
Senior Member
Join Date: Apr 2013
Old 12-04-2017 , 16:50   Re: Get hitscan shot coordinates
Reply With Quote #5

Look up the bullet_impact event
__________________
Kinsi is offline
glittershii
Junior Member
Join Date: Oct 2017
Old 12-04-2017 , 17:30   Re: Get hitscan shot coordinates
Reply With Quote #6

Quote:
Originally Posted by Kinsi View Post
Look up the bullet_impact event
As stated in the OP, game doesn't have it
glittershii is offline
Kinsi
Senior Member
Join Date: Apr 2013
Old 12-04-2017 , 18:44   Re: Get hitscan shot coordinates
Reply With Quote #7

Ohh didnt see that. You'd prolly need to reverse engineer the server/engine dll and use DHooks to write a manual hook. No event suggests that you're able to calculate where the bullet actually hit.
__________________
Kinsi is offline
glittershii
Junior Member
Join Date: Oct 2017
Old 12-18-2017 , 17:02   Re: Get hitscan shot coordinates
Reply With Quote #8

That sounds like something that's way beyond my knowledge. I'm willing to learn but I have no idea where to start. Any documentation you recommend?
glittershii is offline
HymnsForDisco
Junior Member
Join Date: Dec 2015
Old 12-24-2017 , 03:51   Re: Get hitscan shot coordinates
Reply With Quote #9

There are SDK hooks for SDKHook_TraceAttack and SDKHook_TraceAttackPost
Maybe one of these will help you
HymnsForDisco is offline
Starbish
AlliedModders Donor
Join Date: Oct 2011
Location: South Korea
Old 12-25-2017 , 10:42   Re: Get hitscan shot coordinates
Reply With Quote #10

Maybe just use OnTakeDamage() will resolve this problem?
__________________
Starbish 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 19:55.


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