Raised This Month: $ Target: $400
 0% 

Detect headshot in hl2dm w/crossbow


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
foo bar
AlliedModders Donor
Join Date: Dec 2012
Location: Canada
Old 01-24-2013 , 01:28   Detect headshot in hl2dm w/crossbow
Reply With Quote #1

Hello!

I'm new to scripting in Sourcepawn and am quite enjoying it.
I'm trying to track headshots made by the crossbow using an SDKHook_TraceAttackPost event, but the hitgroup always comes back as 0. My understanding is the crossbow does not use hitscan so I figure this approach won't work.

I've also tried GetEventInt(event, "hitgroup") in a player_hurt event. It comes back as 0 too.

How can I detect a headshot made with a crossbow?

[foo] bar
foo bar is offline
norris1975
New Member
Join Date: Jan 2013
Old 01-24-2013 , 04:38   Re: Detect headshot in hl2dm w/crossbow
Reply With Quote #2

Sourcemod has a TON of plugins and is currently considered the best plugin for any Source Dedicated Server. The main issue with Mani is the lack up update support. Sourcemod is frequently updated and new plugins are always coming out. In fact, many bugs are often fixed with Sourcemod plugins before they are fixed my Valve.
norris1975 is offline
foo bar
AlliedModders Donor
Join Date: Dec 2012
Location: Canada
Old 01-24-2013 , 04:49   Re: Detect headshot in hl2dm w/crossbow
Reply With Quote #3

Quote:
Originally Posted by norris1975 View Post
Sourcemod has a TON of plugins and is currently considered the best plugin for any Source Dedicated Server. The main issue with Mani is the lack up update support. Sourcemod is frequently updated and new plugins are always coming out. In fact, many bugs are often fixed with Sourcemod plugins before they are fixed my Valve.
Yes. I've been converting a number of mani scripts over to Sourcemod for this very reason.

But how does this help me figure out if a crossbow_bolt hit someone in the head? ;)
foo bar is offline
blodia
Veteran Member
Join Date: Sep 2009
Location: UK
Old 01-24-2013 , 08:48   Re: Detect headshot in hl2dm w/crossbow
Reply With Quote #4

if its a projectile it should have an entity for the bolt in which case you could hook touch and compare its coordinates with the players eye coordinates on touch.
blodia is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-24-2013 , 10:21   Re: Detect headshot in hl2dm w/crossbow
Reply With Quote #5

Are you trying to block the damage or just figure out when it's a headshot?

Either way, SDKHooks OnTakeDamage is probably a better method of detecting it.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 01-24-2013 at 10:21.
Powerlord is offline
Root_
Veteran Member
Join Date: Jan 2012
Location: ryssland
Old 01-24-2013 , 10:29   Re: Detect headshot in hl2dm w/crossbow
Reply With Quote #6

Take a look at a SuperLogs for HL2MP, may be helpful in your case
__________________


dodsplugins.com - Plugins and Resources for Day of Defeat
http://twitch.tv/zadroot
Root_ is offline
foo bar
AlliedModders Donor
Join Date: Dec 2012
Location: Canada
Old 01-24-2013 , 12:14   Re: Detect headshot in hl2dm w/crossbow
Reply With Quote #7

Thanks blodia, Powerlord and root.

I switched over to SDKHooks' OnTakeDamage and OnTakeDamagePost, but the weapon being passed in is -1 ("unspecified"). I'm not sure if I'm doing something wrong with the call or not, though. It does pass in the damagePosition which makes it pretty simple to tell if the hit was approximately head level.

I'm trying to specifically animate a different effect if a player is headshot by a crossbow bolt.

root: I did take a look at superlogs but it's unclear to me how exactly their crossbow support works. I don't see my superlogs-hl2mp triggering a headshot with a crossbow either, so I wonder if they really have it working.

[foo] bar
foo bar is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-24-2013 , 12:43   Re: Detect headshot in hl2dm w/crossbow
Reply With Quote #8

I just checked the Superlogs support for HL2DM, and it does check the hitgroup using TraceAttack to see if it's equal to 1 (HITGROUP_HEAD from wstatshelper.inc).

Are you sure headshots are returning hitgroup 0?

Alternately, make sure you're using the correct arguments in your callbacks:

PHP Code:
    // TraceAttack
    
Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype, &ammotypehitboxhitgroup),
    
    
// TraceAttackPost
    
public(victimattackerinflictorFloat:damagedamagetypeammotypehitboxhitgroup), 
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 01-24-2013 at 12:46.
Powerlord is offline
foo bar
AlliedModders Donor
Join Date: Dec 2012
Location: Canada
Old 01-24-2013 , 16:17   Re: Detect headshot in hl2dm w/crossbow
Reply With Quote #9

Quote:
Originally Posted by Powerlord View Post
I just checked the Superlogs support for HL2DM, and it does check the hitgroup using TraceAttack to see if it's equal to 1 (HITGROUP_HEAD from wstatshelper.inc).

Are you sure headshots are returning hitgroup 0?

Alternately, make sure you're using the correct arguments in your callbacks:

PHP Code:
    // TraceAttack
    
Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype, &ammotypehitboxhitgroup),
    
    
// TraceAttackPost
    
public(victimattackerinflictorFloat:damagedamagetypeammotypehitboxhitgroup), 

Here's some test code I've been using to see what TraceAttackPost is seeing.

In superlogs-hl2mp.sp (Version 1.1.3) I've changed OnTraceAttack to:

PHP Code:
public OnTraceAttack(victimattackerinflictorFloat:damagedamagetypeammotypehitboxhitgroup)
{

        
PrintToServer("SuperLogs:hl2mp 208 OnTraceAttack hitgroup=%d"hitgroup);

        if (
hitgroup && attacker && attacker <= MaxClients && victim && victim <= MaxClients)
        {

                if (
IsValidEntity(inflictor))
                {
                        
decl String:inflictorclsname[64];
                        if (
GetEntityNetClass(inflictorinflictorclsnamesizeof(inflictorclsname)) && strcmp(inflictorclsname"CCrossbowBolt") == 0)
                        {
                                
PrintToServer("SuperLogs:hl2mp OnTraceAttack CCrossbowBolt; inflictorclsname=%s hitgroup = %d"inflictorclsname,hitgroup);
                                
g_iNextBowHitgroup[victim] = hitgroup;
                                return;
                        } else {
                                
PrintToServer("SuperLogs:hl2mp OnTraceAttack inflictor inflictor=%d classname=%s",inflictor,inflictorclsname);
                        }

                }
                
g_iNextHitgroup[victim] = hitgroup;
        }


With the 357 hitgroup is 1, as evidenced by the server output:

Quote:
SuperLogs:hl2mp 208 OnTraceAttack hitgroup=1
SuperLogs:hl2mp OnTraceAttack inflictor inflictor=1 classname=CHL2MP_Player
L 01/24/2013 - 13:02:05: World triggered "killlocation" (attacker_position "1588 103 -1") (victim_position "1208 208 33")
L 01/24/2013 - 13:02:05: "[foo] bar<2><STEAM_0:0:15703618><Unassigned>" triggered "headshot"
L 01/24/2013 - 13:02:05: "[foo] bar<2><STEAM_0:0:15703618><Unassigned>" killed "spawnkillerbait<3><STEAM_0:0:59539635><Unass igned>" with "357"
With crossbow, I see:

Quote:
SuperLogs:hl2mp 208 OnTraceAttack hitgroup=0
L 01/24/2013 - 13:02:16: World triggered "killlocation" (attacker_position "1588 103 -1") (victim_position "1208 208 33")
L 01/24/2013 - 13:02:16: "[foo] bar<2><STEAM_0:0:15703618><Unassigned>" killed "spawnkillerbait<3><STEAM_0:0:59539635><Unass igned>" with "crossbow_bolt"

Note that there is no "triggered headshot" log from superlogs on the crossbow hit either, but there is for the 357.


A much simpler test yields the same result:

PHP Code:
#include <sourcemod>
#include <smlib>
#include <sdkhooks>

#include <sdktools_sound.inc>


public OnPluginStart()
{
        for(new 
i=1;i<MaxClients;i++){
                if(
IsClientInGame(i))
                {
                        
SDKHook(iSDKHook_TraceAttackPost,Event_TrackAttack);
                }
        }
}

public 
OnClientPutInServer(client)
{
        
SDKHook(clientSDKHook_TraceAttackPost,Event_TrackAttack);
}

public 
Action:Event_TrackAttack(victim, &attacker, &inflictor, &Float:damage, &damagetype, &ammotypehitboxhitgroup)
{
        
PrintToServer("Bowtest TraceAttack: victim=%d,inflictor=%d,hitgroup=%d",victim,inflictor,hitgroup);

Quote:
Bowtest TraceAttack: victim=2,inflictor=25970,hitgroup=0


Now I do see that superlogs-hl2mp is doing some mangling in OnTakeDamage but hitgroup starts out 0, and ends up being set to 7.

PHP Code:
public OnTakeDamage(victimattackerinflictorFloat:damagedamagetype)
{
        if (
attacker && attacker <= MaxClients && victim && victim <= MaxClients)
        {
                
decl Stringweapon[MAX_WEAPON_LEN PREFIX_LEN];
                
GetClientWeapon(attackerweaponsizeof(weapon));
                new 
weapon_index = -1;
                if (
IsValidEntity(inflictor))
                {
                        
decl String:inflictorclsname[64];
                        if (
GetEntityNetClass(inflictorinflictorclsnamesizeof(inflictorclsname)) && strcmp(inflictorclsname"CCrossbowBolt") == 0)
                        {
                                
PrintToServer("OnTakeDamage: inflictorclsname=%s"inflictorclsname);
                                
weapon_index CROSSBOW;
                        }
                }
                if (
weapon_index == -1)
                {
                        
weapon_index get_weapon_index(weapon[PREFIX_LEN]);
                }
                new 
hitgroup = ((weapon_index == CROSSBOW)?g_iNextBowHitgroup[victim]:g_iNextHitgroup[victim]);
                
PrintToServer("OnTakeDamage 251 hitgroup=%d",hitgroup);
                if (
hitgroup 8)
                {
                        
hitgroup += LOG_HIT_OFFSET;
                        
PrintToServer("OnTakeDamage 255 hitgroup=%d",hitgroup);
                }
                new 
bool:headshot = (GetClientHealth(victim) <= && hitgroup == HITGROUP_HEAD);
                
PrintToServer("OnTakeDamage: hitgroup=%d",hitgroup);
                
PrintToServer("OnTakeDamage: weapon_index=%d",weapon_index);
                if (
weapon_index > -1)
                {
                        
g_weapon_stats[attacker][weapon_index][LOG_HIT_HITS]++;
                        
g_weapon_stats[attacker][weapon_index][LOG_HIT_DAMAGE] += RoundToNearest(damage);
                        
g_weapon_stats[attacker][weapon_index][hitgroup]++;
                        if (
headshot)
                        {
                                
PrintToServer("This was a headshot!");
                                
g_weapon_stats[attacker][weapon_index][LOG_HIT_HEADSHOTS]++;
                        } else {
                                
PrintToServer("Not a headshot");
                        }
                }
                if (
weapon_index == CROSSBOW)
                {
                        
g_iNextBowHitgroup[victim] = 0;
                }
                else
                {
                        
g_iNextHitgroup[victim] = 0;
                }
        }

yields:

Quote:
L 01/24/2013 - 13:11:27: World triggered "killlocation" (attacker_position "1588 103 -1") (victim_position "1208 208 33")
L 01/24/2013 - 13:11:27: "[foo] bar<2><STEAM_0:0:15703618><Unassigned>" killed "spawnkillerbait<3><STEAM_0:0:59539635><Unass igned>" with "crossbow_bolt"
OnTakeDamage: inflictorclsname=CCrossbowBolt
OnTakeDamage 251 hitgroup=0
OnTakeDamage 255 hitgroup=7
OnTakeDamage: hitgroup=7
OnTakeDamage: weapon_index=0
Not a headshot
I'm not sure what to make of this at the moment. I will need to spend some more time walking through this.

[foo] bar
foo bar is offline
StrikerMan780
AlliedModders Donor
Join Date: Jul 2009
Location: Canada
Old 04-22-2013 , 20:23   Re: Detect headshot in hl2dm w/crossbow
Reply With Quote #10

As far as I know, it's impossible to properly detect headshots with crossbow bolts, being projectiles rather than hitscan traces, they ignore hitboxes and uses the player's bounding box as the basis for hit detection. Someone correct me if I'm wrong.

Last edited by StrikerMan780; 04-22-2013 at 20:24.
StrikerMan780 is offline
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 13:47.


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