SA-MP Forums Archive
OnPlayerWeaponShot - 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: OnPlayerWeaponShot (/showthread.php?tid=500797)



OnPlayerWeaponShot - Admigo - 15.03.2014

Hello ,

I have a problem with OnPlayerWeaponShot.
I am trying to detect when someone has shot a player while q or e pressed in a vehicle.
Also i am trying to detect if someone on a bike shot someone.
But i dont know how i can detect that.
Can someone help me with that?

Admigo


Re: OnPlayerWeaponShot - MP2 - 15.03.2014

Drive-by doesn't work with OnPlayerWeaponShot.

You'll have to use key detection (KEY_LOOK_LEFT/KEY_LOOK_RIGHT + KEY_FIRE ?).

You could use GetPlayerKeys under OnPlayerTakeDamage.

pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
    if(GetPlayerState(issuerid) == 2)
    {
        new keys, updown, leftright;
        GetPlayerKeys(issuerid, keys, updown, leftright);
        if((keys & KEY_LOOK_LEFT || keys & KEY_LOOK_RIGHT) && (keys & KEY_FIRE))
        {
            // Driver drive-by
        }
    }
    return 1;
}
NOTE: Players can drive-by FORWARDS (not holding KEY_LOOK_LEFT/RIGHT) while on a motorbike. You could check for that.

EDIT: Actually, thinking about it, you only really need to check if they are a driver, as obviously if they dealt damage from inside a vehicle, it's got to be a weapon. Although the exception is if they drive in to someone, for which the reason would be 'collision'.


Re: OnPlayerWeaponShot - Admigo - 15.03.2014

Quote:
Originally Posted by MP2
View Post
Drive-by doesn't work with OnPlayerWeaponShot.

You'll have to use key detection (KEY_LOOK_LEFT/KEY_LOOK_RIGHT + KEY_FIRE ?).

You could use GetPlayerKeys under OnPlayerTakeDamage.

pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
    if(GetPlayerState(issuerid) == 2)
    {
        new keys, updown, leftright;
        GetPlayerKeys(issuerid, keys, updown, leftright);
        if((keys & KEY_LOOK_LEFT || keys & KEY_LOOK_RIGHT) && (keys & KEY_FIRE))
        {
            // Driver drive-by
        }
    }
    return 1;
}
NOTE: Players can drive-by FORWARDS (not holding KEY_LOOK_LEFT/RIGHT) while on a motorbike. You could check for that.

EDIT: Actually, thinking about it, you only really need to check if they are a driver, as obviously if they dealt damage from inside a vehicle, it's got to be a weapon. Although the exception is if they drive in to someone, for which the reason would be 'collision'.
Thanks MP2. Rep+.
I need this for detecting if Cops hitting innocent players.


Re: OnPlayerWeaponShot - MP2 - 15.03.2014

In which case just use OnPlayerTakeDamage and don't check anything. You don't need to check if they're doing a drive-by.