Перейти к основному содержимому

OnPlayerWeaponShot

Description

This callback is called when a player fires a weapon. Only firearms are supported.

NameDescription
playeridThe ID of the player who fired the weapon.
WEAPON:weaponidThe ID of the weapon fired by the player.
BULLET_HIT_TYPE:hittypeThe type of target hit by the shot.
hitidThe ID of the player, vehicle, or object that was hit.
Float:fXThe X coordinate where the shot hit.
Float:fYThe Y coordinate where the shot hit.
Float:fZThe Z coordinate where the shot hit.

Returns

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

Examples

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

Notes

подсказка

This callback is only called when lag compensation is enabled. If hittype is:

  • BULLET_HIT_TYPE_NONE: The fX, fY, and fZ parameters are absolute coordinates. These will return 0.0 if nothing was hit (e.g., a distant object that the bullet can't reach).
  • Other values: The fX, fY, and fZ values are offsets relative to hitid.
подсказка

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

Known bugs and issues

warning

This callback isn't called when firing from a vehicle as the driver or when shooting while looking backward with the aim enabled (shooting into the air).

warning

When shooting a player inside a vehicle, this callback will be triggered as BULLET_HIT_TYPE_VEHICLE with the correct hitid (the hit player's vehicleid). It won't be triggered as BULLET_HIT_TYPE_PLAYER.

warning

Partially fixed in SA-MP 0.3.7: If fake weapon data is sent by a malicious client, other players' clients may freeze or crash. To prevent this, check if the reported weaponid can, in fact, fire projectiles.

warning

This callback is not called when driving-by as a driver, firing the turret of a Seasparrow, Hunter, or any other armed vehicle.

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

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