SA-MP Forums Archive
Headshot system kills team members - 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 system kills team members (/showthread.php?tid=450387)



Headshot system kills team members - JimmyCh - 12.07.2013

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!


Respuesta: Headshot system kills team members - PHudson - 12.07.2013

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))



Re: Headshot system kills team members - JimmyCh - 12.07.2013

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.


Respuesta: Headshot system kills team members - PHudson - 12.07.2013

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)



Re: Headshot system kills team members - JimmyCh - 13.07.2013

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)
                {
??


Re: Headshot system kills team members - ThePhenix - 13.07.2013

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


Re: Headshot system kills team members - JimmyCh - 13.07.2013

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..


Respuesta: Headshot system kills team members - PHudson - 13.07.2013

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?).


Re: Headshot system kills team members - JimmyCh - 13.07.2013

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