OnSniperRifleFired: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{Welcome| | {{Welcome| | ||
desc=This function is called when a player fires a sniper rifle. This function is not called if the npc itself is firing the sniper rifle using [[FireSniperRifle]]. If more than one npc is there, this function gets called when other npcs fire sniper rifle using FireSniperRifle.| | desc=This function is called when a player fires a sniper rifle. This function is not called if the npc itself is firing the sniper rifle using [[FireSniperRifle]]. If more than one npc is there, this function gets called when other npcs fire sniper rifle using FireSniperRifle.| | ||
params=<syntaxhighlight lang="lua">( playerid, weaponid, x, y, z, dx, dy, dz | params=<syntaxhighlight lang="lua">( playerid, weaponid, x, y, z, dx, dy, dz )</syntaxhighlight> | ||
)</syntaxhighlight> | |||
<poem>::playerId : The ID of the player who fired | <poem>::playerId : The ID of the player who fired | ||
::weaponid: The ID of the weapon fired. ( Usually 28 or 29 ) | ::weaponid: The ID of the weapon fired. ( Usually 28 or 29 ) | ||
Line 16: | Line 15: | ||
function OnSniperRifleFired( playerid, weaponid, x, y, z, dx, dy, dz ) | function OnSniperRifleFired( playerid, weaponid, x, y, z, dx, dy, dz ) | ||
{ | { | ||
dx= dx/16.0; dy = dy/16.0; dz = dz/16.0; | |||
local start = Vector( x, y, z ); | local start = Vector( x, y, z ); | ||
local start += Vector( dx, dy, dz ); | local start += Vector( dx, dy, dz ); |
Latest revision as of 12:02, 27 November 2022
Description:
This function is called when a player fires a sniper rifle. This function is not called if the npc itself is firing the sniper rifle using FireSniperRifle. If more than one npc is there, this function gets called when other npcs fire sniper rifle using FireSniperRifle.
Parameters:
( playerid, weaponid, x, y, z, dx, dy, dz )
playerId : The ID of the player who fired
weaponid: The ID of the weapon fired. ( Usually 28 or 29 )
x : The source x co-ordinate of the firing.
y : The source y co-ordinate of the firing.
z : The source z co-ordinate of the firing
dx : The x component of the normalized direction vector multiplied by 16.0
dy : The y component of the normalized direction vector multiplied by 16.0
dz : The z component of the normalized direction vector multiplied by 16.0
Example
function OnSniperRifleFired( playerid, weaponid, x, y, z, dx, dy, dz ) { dx= dx/16.0; dy = dy/16.0; dz = dz/16.0; local start = Vector( x, y, z ); local start += Vector( dx, dy, dz ); local end = start + Vector( 90.0 * dx, 90.0 * dy, 90.0 * dz ); //90.0 is the range of Ruger //Now RayTrace function with the above values viz. start, end and flag as 2 will give hit position. //RayTrace is clientside function. So all the values can be passed to playerid via server local command= format("PLOS %d %.4f %.4f %.4f %.4f %.4f %.4f %d %d", playerid, x, y, z, dx, dy, dz, 2, weaponid ); SendCommand(command); //This will call the onPlayerCommand with cmd = "PLOS" and rest as text. }