AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Problem with headshot detection. (https://forums.alliedmods.net/showthread.php?t=324598)

Shadows Adi 05-20-2020 15:44

Problem with headshot detection.
 
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

thEsp 05-20-2020 15:48

Re: Problem with headshot detection.
 
As for CS, read 3rd byte of DeathMsg event.

Bugsy 05-20-2020 17:45

Re: Problem with headshot detection.
 
Would need to see more code.. e.g. where is the code you posted executed?

Shadows Adi 05-20-2020 18:59

Re: Problem with headshot detection.
 
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



thEsp 05-20-2020 19:09

Re: Problem with headshot detection.
 
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.

Bugsy 05-20-2020 19:28

Re: Problem with headshot detection.
 
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);



+ARUKARI- 05-20-2020 19:34

Re: Problem with headshot detection.
 
If you are using Fakemeta
You may be able to use this.
PHP Code:

new isHeadShot = (get_pdata_int(iVictim75) == HIT_HEAD); 


Bugsy 05-20-2020 19:52

Re: Problem with headshot detection.
 
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 )
{




Shadows Adi 05-22-2020 14:29

Re: Problem with headshot detection.
 
Solved, thank you all for your help. I've been used @Bugsy's way.


All times are GMT -4. The time now is 03:54.

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