SA-MP Forums Archive
Headshot Bugged - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Headshot Bugged (/showthread.php?tid=654347)



Headshot Bugged - BlackLineCnR - 26.05.2018

I created a headshot system by the help of CELL_ but the it wasn't working in-game:-
Код:
public OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid, bodypart)
{
/*    new abc_string[128];
    format(abc_string, 128, "OnPlayerGiveDamage(%d, %d, %.2f, %d, %d)", playerid, damagedid, amount, weaponid, bodypart);
    SendClientMessage(playerid, 0xFFFFFFFF, abc_string);
    SendClientMessage(damagedid, 0xFFFFFFFF, abc_string);*/

    print("Callback called.");
    if(damagedid != INVALID_PLAYER_ID) // Check if the player taking the damage didn't just take damage from other sources
    {
        print("Damaged passed.");
        if(bodypart == 9 && weaponid == 34) // Check if it was the head that was shot and he was also shot with a sniper.. change 34 to weapon of ur choice
        {
            print("Bodypart, weapon passed.");
            if(GetPlayerState(damagedid) == PLAYER_STATE_SPAWNED) // Check if the player is actually spawned..
            {
                print("Spawn check passed.");
                SetPlayerHealth(damagedid, 0.00); // Kill the player
                GameTextForPlayer(playerid, "HEAD SHOT!", 1000, 2); // Just aesthetics
                GameTextForPlayer(damagedid, "HEAD SHOT!", 1000, 2); // Just aesthetics
            }
        }
    }
    return 1;
}
Then added print statements to know the error and we camed to decision that Headpart was not being shooted and only part of body being shoot was 1, Please help me!


Re: Headshot Bugged - Jefff - 26.05.2018

PLAYER_STATE_SPAWNED is only when player is spawning after death so max 1 sec

https://sampwiki.blast.hk/wiki/Playerstates


Re: Headshot Bugged - Cell_ - 26.05.2018

I did do some testing with this guy and the problem with his script was with the bodypart parameter. Instead of calling the actual bodypart being hit, the script always called the code with bodypart as 1, which is not even a recognized bodypart as per the SA-MP wiki. The testing was performed by the OP and according to him, shooting all body parts on another player called the callback with bodypart as 1.

As per OP, the server also has lagcomp enabled so I don't know why the bodypart is always called as 1. The code (with relevant modifications) was tested under both OnPlayerTakeDamage and OnPlayerGiveDamage with the same result.

@Jeff: didn't know that is what it was. However, as stated above, the code never reached that part anyway.


Re: Headshot Bugged - BlackLineCnR - 27.05.2018

Please anyone help!


Re: Headshot Bugged - Kaliber - 27.05.2018

The answer was given already.

Just remove the State check:

Код:
public OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid, bodypart)
{
/*    new abc_string[128];
    format(abc_string, 128, "OnPlayerGiveDamage(%d, %d, %.2f, %d, %d)", playerid, damagedid, amount, weaponid, bodypart);
    SendClientMessage(playerid, 0xFFFFFFFF, abc_string);
    SendClientMessage(damagedid, 0xFFFFFFFF, abc_string);*/

    print("Callback called.");
    if(damagedid != INVALID_PLAYER_ID) // Check if the player taking the damage didn't just take damage from other sources
    {
        print("Damaged passed.");
        if(bodypart == 9 && weaponid == 34) // Check if it was the head that was shot and he was also shot with a sniper.. change 34 to weapon of ur choice
        {
            print("Bodypart, weapon passed.");
            SetPlayerHealth(damagedid, 0.00); // Kill the player
            GameTextForPlayer(playerid, "HEAD SHOT!", 1000, 2); // Just aesthetics
            GameTextForPlayer(damagedid, "HEAD SHOT!", 1000, 2); // Just aesthetics
        }
    }
    return 1;
}



Re: Headshot Bugged - BlackLineCnR - 27.05.2018

Still didn't worked :/ Please help me out!


Re: Headshot Bugged - Mugala - 28.05.2018

are u sure you're not using OnPlayerGiveDamage func in another code?
make sure and also check this.
PHP код:
public OnPlayerGiveDamage(playeriddamagedidFloat:amountweaponidbodypart)
{
    new 
formatting[128];
    
format(formatting,128,"you just on bodypart ID: %d",bodypart);
    
SendClientMessage(playerid,-1,formatting);
    return 
1;

check if head is detectable.


Re: Headshot Bugged - GTLS - 28.05.2018

Try the testing on Localhost if not already.


Re: Headshot Bugged - SubGames - 28.05.2018

Quote:
Originally Posted by Mugala
Посмотреть сообщение
are u sure you're not using OnPlayerGiveDamage func in another code?
make sure and also check this.
PHP код:
public OnPlayerGiveDamage(playeriddamagedidFloat:amountweaponidbodypart)
{
    new 
formatting[128];
    
format(formatting,128,"you just on bodypart ID: %d",bodypart);
    
SendClientMessage(playerid,-1,formatting);
    return 
1;

check if head is detectable.
I have tried this thing in another way, and the only bodypart which is being detected is 1, On whole body!

Havent tried on LocalHost, Will try it today and tell!