Headshot system kills team members
#1

So, I'm working on a headshot system, but it keeps killing my teammates if you headshot them with any weapon.
Now what I want is, if you headshot someone with sniper only, also that if you're in Class Sniper and weapon 34, it will show on kill list:
Just the weapon and the playerid, without killerid.
My code:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
        if(IsPlayerConnected(killerid))
        {
            if(gPlayerClass[playerid] == SNIPER && gTeam[killerid] != gTeam[playerid])
            {
                if(GetPlayerWeapon(killerid) == 34)
                {
                    if(GetPVarInt(playerid, "Headshotted") == 1)
                    {
                    SetPVarInt(playerid, "Headshotted", 0);
                    GameTextForPlayer(playerid, "~r~Headshotted", 3000, 3);
                    GameTextForPlayer(killerid, "~r~Headshot", 3000, 3);
                    SendDeathMessage(playerid,INVALID_PLAYER_ID,34);
                    return 1;
                    }
                }
                else
                {
                if(GetPlayerWeapon(killerid) == 34 && gTeam[killerid] != gTeam[playerid])
                    {
                    if(GetPVarInt(playerid, "Headshotted") == 1)
                    {
                    SetPVarInt(playerid, "Headshotted", 0);
                    GameTextForPlayer(playerid, "~r~Headshotted", 3000, 3);
                    GameTextForPlayer(killerid, "~r~Headshot", 3000, 3);
                    SendDeathMessage(playerid,killerid,reason);
                    return 1;
                    }
               }
            }
            }
Will rep+ the person that helps me solve this!
Reply
#2

There should be a function that decreases damaged player's health (not the one you posted). Before decreasing it, add this condition:

pawn Код:
if(GetPlayerTeam(playerid) != GetPlayerTeam(damagedplayerid))
Reply
#3

What exactly does that do?
I don't understand it..
Plus it says undefined damagedplayerid.


I already got the system where you headshot and they automatically die, I just want to prevent that from other weapons other than sniper, and team members.
Reply
#4

The code I posted checks both players (the shooter and the victim) don't belong to the same team. If they do, the victim doesn't loose any health.
damagedplayerid must be replaced with the variable that contains the player ID who has shot. I don't know what is it called in your script.
I'm afraid you have to modify the system you already have, because you can't fix that using OnPlayerDeath, as the player has already dead and lost health. If you would also like to check if the player is using a sniper use this condition instead:

pawn Код:
if(GetPlayerTeam(playerid) != GetPlayerTeam(damagedplayerid) && GetPlayerWeapon(playerid) == 34)
Reply
#5

I have no idea what you just said.

Isn't it the same as:
pawn Код:
if(gPlayerClass[playerid] == SNIPER && gTeam[killerid] != gTeam[playerid])
            {
                if(GetPlayerWeapon(killerid) == 34)
                {
??
Reply
#6

PHP код:
if(GetPlayerTeam(playerid) != GetPlayerTeam(killerid)) 
It will check if "playerid" isn't the same team killerid.


Suggest you to use this:

https://sampforum.blast.hk/showthread.php?pid=937824#pid937824
Reply
#7

So, what was wrong with my code? I had put:
pawn Код:
if(gTeam[killerid] != gTeam[playerid])
Please tell me why it is different than the one you gave..
Reply
#8

As I said previously, you can't check that in OnPlayerDeath. That's because the player is already dead and even if that condition is false, he will remain dead. Please, read carefully because I've already said this. You've got to check that when killerid attempts to headshot playerid in another callback (OnPlayerGiveDamage, maybe?).
Reply
#9

I tried everything, even another headshot system, but nothing worked.
Anyway thanks to all who helped me
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)