OnPlayerWeaponShot

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 20:39, 11 January 2018
IstuntmanI (Talk | contribs)
(another OnPlayerWeaponShot problem)
← Previous diff
Revision as of 22:27, 8 February 2018
RogueDrifter (Talk | contribs)
(A fix for the Hit type bug about drivers being shot.)
Next diff →
Line 21: Line 21:
{{bug| {{bug|
* Isn't called if you fired in vehicle as driver or if you are looking behind with the aim enabled (shooting in air). * Isn't called if you fired in vehicle as driver or if you are looking behind with the aim enabled (shooting in air).
-* It is called as ''BULLET_HIT_TYPE_VEHICLE'' with the correct hitid (the hit player's vehicleid) if you are shooting a player which is in a vehicle. It won't be called as ''BULLET_HIT_TYPE_PLAYER'' at all.+* It is called as ''BULLET_HIT_TYPE_VEHICLE'' with the correct hitid (the hit player's vehicleid) if you are shooting a player which is in a vehicle. It won't be called as ''BULLET_HIT_TYPE_PLAYER'' at all. Although, There's an include that attempts to fix this issue.
* <b>Partially fixed in SA-MP 0.3.7</b>: If fake weapon data is sent by a malicious user, other player clients may freeze or crash. To combat this, check if the reported weaponid can actually fire bullets.}} * <b>Partially fixed in SA-MP 0.3.7</b>: If fake weapon data is sent by a malicious user, other player clients may freeze or crash. To combat this, check if the reported weaponid can actually fire bullets.}}
 +* A possible fix <b>(Optional for you to use)</b> to the SA-MP OnPlayerWeaponShot driver's shot bug: [[http://forum.sa-mp.com/showthread.php?t=649231| Include]]
 +*Example Usage for the include <b>(only possible if you use the include)</b> :
 +<pawn>
 +//An example of usage for the new hittype #5
 +//Omit from anti-cheat checks such as fakedeath for variables set.
 +public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
 +{
 + if(hittype == 5) //If its the new hittype (a player (driver/passenger) was shot while being paused)
 + {
 + new opwsString[120];
 + format(opwsString, sizeof(opwsString), "Player %i was shot by %i when he was paused by the weapon %i hittype %i (paused)", hitid,
 +playerid, weaponid, hittype);
 + SendClientMessageToAll(-1, opwsString);
 +
 + return 1;
 + }
 +}
 +</pawn>
{{notes| {{notes|
* This callback is only called when [[Lag_Compensation|lag compensation]] is <b>enabled</b>. * This callback is only called when [[Lag_Compensation|lag compensation]] is <b>enabled</b>.
Line 29: Line 47:
- <i>BULLET_HIT_TYPE_NONE</i>: the <b>fX</b>, <b>fY</b> and <b>fZ</b> parameters are normal coordinates, will give 0.0 for coordinates if nothing was hit (e.g. far object that the bullet can't reach);<br /> - <i>BULLET_HIT_TYPE_NONE</i>: the <b>fX</b>, <b>fY</b> and <b>fZ</b> parameters are normal coordinates, will give 0.0 for coordinates if nothing was hit (e.g. far object that the bullet can't reach);<br />
- Others: the <b>fX</b>, <b>fY</b> and <b>fZ</b> are offsets relative to the <b>hitid</b>.}} - Others: the <b>fX</b>, <b>fY</b> and <b>fZ</b> are offsets relative to the <b>hitid</b>.}}
- 
{{Example}} {{Example}}
<pawn> <pawn>

Revision as of 22:27, 8 February 2018



OnPlayerWeaponShot was added in SA-MP 0.3z This callback was added in SA-MP 0.3z and will not work in earlier versions!


Description:

This callback is called when a player fires a shot from a weapon. Only bullet weapons are supported. Only passenger drive-by is supported (not driver drive-by, and not sea sparrow / hunter shots).


Parameters:
(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
playeridThe ID of the player that shot a weapon.
weaponidThe ID of the weapon shot by the player.
hittypeThe type of thing the shot hit (none, player, vehicle, or (player)object).
hitidThe ID of the player, vehicle or object that was hit.
fXThe X coordinate that the shot hit.
fYThe Y coordinate that the shot hit.
fZThe Z coordinate that the shot hit.


Return Values:

  • 0 - Prevent the bullet from causing damage.
  • 1 - Allow the bullet to cause damage.
  • It is always called first in filterscripts so returning 0 there also blocks other scripts from seeing it.


Image:32px-Circle-style-warning.png

Warning

Known Bug(s):
  • Isn't called if you fired in vehicle as driver or if you are looking behind with the aim enabled (shooting in air).
  • It is called as BULLET_HIT_TYPE_VEHICLE with the correct hitid (the hit player's vehicleid) if you are shooting a player which is in a vehicle. It won't be called as BULLET_HIT_TYPE_PLAYER at all. Although, There's an include that attempts to fix this issue.
  • Partially fixed in SA-MP 0.3.7: If fake weapon data is sent by a malicious user, other player clients may freeze or crash. To combat this, check if the reported weaponid can actually fire bullets.


  • A possible fix (Optional for you to use) to the SA-MP OnPlayerWeaponShot driver's shot bug: [Include]
  • Example Usage for the include (only possible if you use the include) :
//An example of usage for the new hittype #5 
//Omit from anti-cheat checks such as fakedeath for variables set.
 
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if(hittype == 5) //If its the new hittype (a player (driver/passenger) was shot while being paused)
    {
        new opwsString[120];
        format(opwsString, sizeof(opwsString), "Player %i was shot by %i when he was paused by the weapon %i hittype %i (paused)", hitid, 
playerid, weaponid, hittype);
        SendClientMessageToAll(-1, opwsString);
 
        return 1;
        }
}
Image:32px-Ambox_warning_orange.png

Notes

- BULLET_HIT_TYPE_NONE: the fX, fY and fZ parameters are normal coordinates, will give 0.0 for coordinates if nothing was hit (e.g. far object that the bullet can't reach);
- Others: the fX, fY and fZ are offsets relative to the hitid.

Example Usage:

public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    new szString[144];
    format(szString, sizeof(szString), "Weapon %i fired. hittype: %i   hitid: %i   pos: %f, %f, %f", weaponid, hittype, hitid, fX, fY, fZ);
    SendClientMessage(playerid, -1, szString);
 
    return 1;
}
Tip

Image:Light_bulb_icon.png

GetPlayerLastShotVectors can be used in this callback for more detailed bullet vector information.


Related Callbacks

The following callbacks might be useful as well, as they are related to this callback in one way or another.


Related Functions

The following functions might be useful, as they're related to this callback in one way or another.

Personal tools