Raised This Month: $2 Target: $400
 0% 

Solved Problem with headshot detection.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 05-20-2020 , 15:44   Problem with headshot detection.
Reply With Quote #1

Hello,
I have this code and should give a point stored in a vault if it is headshot. More details down:
PHP Code:
new wpnclipammo
        wpn 
get_user_weapon(iAttackerclipammo)
        if(
iAttacker != iVictim && wpn == CSW_KNIFE )
        {
            if(
g_iIsHeadshot)
            {
                
pdData[iAttacker][Kills] += 1
                pdData
[iAttacker][Headshot] += 1
            
}
            else
            {
                
pdData[iAttacker][Kills] += 1
            
}
        } 
The problem is it count the kills, deaths, damage, but not the headshots.
See this picture:
Click for ScreenShot
__________________

Last edited by Shadows Adi; 05-22-2020 at 18:05.
Shadows Adi is offline
thEsp
Veteran Member
Join Date: Aug 2017
Location: Land of Eagles
Old 05-20-2020 , 15:48   Re: Problem with headshot detection.
Reply With Quote #2

As for CS, read 3rd byte of DeathMsg event.
thEsp is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-20-2020 , 17:45   Re: Problem with headshot detection.
Reply With Quote #3

Would need to see more code.. e.g. where is the code you posted executed?
__________________
Bugsy is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 05-20-2020 , 18:59   Re: Problem with headshot detection.
Reply With Quote #4

This is registered event:
PHP Code:
RegisterHam(Ham_Killed"player""fw_PlayerKilled"1
And this is the public of the function:
PHP Code:
public fw_PlayerKilled(iVictimiAttackershouldgib)
{
    if( 
iVictim == iAttacker || !is_user_connected(iAttacker) || !is_user_connected(iVictim) )
        return 
HAM_IGNORED

    
if(is_user_connected(iAttacker) && is_user_alive(iAttacker))
    {
        new 
g_iIsHeadshot read_data(3);
        new 
szName[33]
        
get_user_name(iVictimszNamecharsmax(szName))
        new 
aName[32]
        
get_user_name(iAttackeraNamecharsmax(aName))
        
        new 
wpnclipammo
        wpn 
get_user_weapon(iAttackerclipammo)
        if(
iAttacker != iVictim && wpn == CSW_KNIFE )
        {
            if(
g_iIsHeadshot)
            {
                
pdData[iAttacker][Kills] += 1
                pdData
[iAttacker][Headshot] += 1
            
}
            else
            {
                
pdData[iAttacker][Kills] += 1
            
}
        }
        if(!
is_user_alive(iVictim) && iVictim != iAttacker && wpn == CSW_KNIFE )
        {
            
pdData[iVictim][Deaths]  += 1
        
}
        return 
HAM_HANDLED
    
}
    return 
PLUGIN_HANDLED

__________________
Shadows Adi is offline
thEsp
Veteran Member
Join Date: Aug 2017
Location: Land of Eagles
Old 05-20-2020 , 19:09   Re: Problem with headshot detection.
Reply With Quote #5

Adi, you're doing it wrong. You don't have to read arguments from Handsandwich forwards with read_x() functions. There are none passed in that way, however they are directly passed. Check this link for more details: http://amxmodx.org/api/ham_const. In your case, you should register "DeathMsg" (that's probably the last resort).

Here's a little example: http://amxxmodx.ru/core/amxmodxinc/7...h-sobytiy.html.

Last edited by thEsp; 05-20-2020 at 19:09.
thEsp is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-20-2020 , 19:28   Re: Problem with headshot detection.
Reply With Quote #6

Use DeathMsg. I started out making comments on your code but it got messy since there are a ton of things wrong. I removed things that were not needed, including getting the player names.

PHP Code:
register_event"DeathMsg" "DeathMsg" "a" "4=knife" "1>0" );

public 
DeathMsg()
{
    new 
iKiller read_data);
    new 
iVictim read_data);

    
pdData[iVictim][Deaths]++;
    
pdData[iKiller][Kills]++;
    
pdData[iKiller][Headshot] += read_data);

__________________

Last edited by Bugsy; 05-20-2020 at 19:29.
Bugsy is offline
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 05-20-2020 , 19:34   Re: Problem with headshot detection.
Reply With Quote #7

If you are using Fakemeta
You may be able to use this.
PHP Code:
new isHeadShot = (get_pdata_int(iVictim75) == HIT_HEAD); 
__________________

Last edited by +ARUKARI-; 05-20-2020 at 19:39.
+ARUKARI- is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-20-2020 , 19:52   Re: Problem with headshot detection.
Reply With Quote #8

Yeah, that will work, I've used it my aimbot detection plugin but forgot about it. But still, I don't see a reason to not use DeathMsg, which provides the advantage of having condition filters and it's easy to get weapon name/headshot.

PHP Code:
const m_LastHitGroup 75;
#define XO_PLAYER 5

if ( get_pdata_intiVictim m_LastHitGroup XO_PLAYER ) == HIT_HEAD )
{


__________________

Last edited by Bugsy; 05-20-2020 at 19:55.
Bugsy is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 05-22-2020 , 14:29   Re: Problem with headshot detection.
Reply With Quote #9

Solved, thank you all for your help. I've been used @Bugsy's way.
__________________

Last edited by Shadows Adi; 05-22-2020 at 14:29.
Shadows Adi 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 22:52.


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