Headshot Bugged
#1

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!
Reply
#2

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

https://sampwiki.blast.hk/wiki/Playerstates
Reply
#3

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.
Reply
#4

Please anyone help!
Reply
#5

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;
}
Reply
#6

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

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.
Reply
#8

Try the testing on Localhost if not already.
Reply
#9

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!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)