FireSniperRifle: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Welcome| | {{Welcome| | ||
desc=This will send a packet to server which is filled by the following parameters.| | desc=This will send a packet to server which is filled by the following parameters.| | ||
params=<syntaxhighlight lang="lua">( sniperid, aimposx, aimposy, aimposz, | params=<syntaxhighlight lang="lua">( sniperid, aimposx, aimposy, aimposz, dx, dy, dz)</syntaxhighlight> | ||
<poem>::sniperid : The weapon ID of sniper (28 or 29) to fire. | <poem>::sniperid : The weapon ID of sniper (28 or 29) to fire. | ||
::aimposx : The x co-ordinate of aim position of NPC ( can be determined using server using player.AimPos or can be calculated artificially). | ::aimposx : The x co-ordinate of aim position of NPC ( can be determined using server using player.AimPos or can be calculated artificially). | ||
::aimposy : The y co-ordinate of aim pos | ::aimposy : The y co-ordinate of aim pos | ||
::aimposz : The z co-ordinate of aimpos | ::aimposz : The z co-ordinate of aimpos | ||
:: | ::dx, dy, dz = The normalized direction vector(from aimpos to target ) multiplied by 16. | ||
</poem>| | </poem>| | ||
example=<source lang="lua"> | example=<source lang="lua"> | ||
// | //Sniper Rifle example taken from Attack Script | ||
function SnipeAt(tPos) | function SnipeAt(tPos, isReloading=false, isHeadShot=false) | ||
{ | { | ||
local Pos=GetMyPos(); | if(isHeadShot)tPos.z+=0.627299; | ||
local angle= atan2(-(tPos.x- | local Pos= GetMyPos(); | ||
local | local aimPos = Vector( Pos.x, Pos.y, Pos.z-0.2); | ||
SendOnFootSyncData( | local angle= atan2(-(tPos.x-aimPos.x), tPos.y-aimPos.y); | ||
FireSniperRifle( | local alpha = atan2( tPos.z - aimPos.z, sqrt( pow( tPos.y - aimPos.y, 2 ) + pow( tPos.x - aimPos.x , 2 ) ) ); | ||
local dx = cos(alpha) * sin(-angle); | |||
local dy = cos(alpha) * cos(-angle); | |||
local dz = sin(alpha); | |||
local keys= 577 ; | |||
local ammo = GetLocalValue(I_CURWEP_AMMO ); | |||
aimPos+=Vector( dx, dy, dz); | |||
/*SendOnFootSyncData( keys, Pos.x,Pos.y, Pos.z, angle, GetPlayerHealth( npcid ), GetPlayerArmour( npcid ), GetPlayerArmedWeapon( npcid ),ammo, 0.0, 0.0, 0.0, aimPos.x, aimPos.y, aimPos.z, dx, dy, dz, false, isReloading ); */ | |||
SetTimerEx("FireSniperRifle", 60, 1, GetPlayerArmedWeapon(npcid), Pos.x, Pos.y, Pos.z, 16.0*dx, 16.0*dy, 16.0*dz ); | |||
} | } | ||
function OnNPCConnect(myplayerid) | //Grab npc ID | ||
{ | function OnNPCConnect(myplayerid) | ||
{ | |||
npcid<-myplayerid; | |||
} | } | ||
</source> | </source>| | ||
}} | }} |
Latest revision as of 18:53, 26 February 2023
Description:
This will send a packet to server which is filled by the following parameters.
Parameters:
( sniperid, aimposx, aimposy, aimposz, dx, dy, dz)
sniperid : The weapon ID of sniper (28 or 29) to fire.
aimposx : The x co-ordinate of aim position of NPC ( can be determined using server using player.AimPos or can be calculated artificially).
aimposy : The y co-ordinate of aim pos
aimposz : The z co-ordinate of aimpos
dx, dy, dz = The normalized direction vector(from aimpos to target ) multiplied by 16.
Return Values:
This function does not return any specific values.
Example
//Sniper Rifle example taken from Attack Script function SnipeAt(tPos, isReloading=false, isHeadShot=false) { if(isHeadShot)tPos.z+=0.627299; local Pos= GetMyPos(); local aimPos = Vector( Pos.x, Pos.y, Pos.z-0.2); local angle= atan2(-(tPos.x-aimPos.x), tPos.y-aimPos.y); local alpha = atan2( tPos.z - aimPos.z, sqrt( pow( tPos.y - aimPos.y, 2 ) + pow( tPos.x - aimPos.x , 2 ) ) ); local dx = cos(alpha) * sin(-angle); local dy = cos(alpha) * cos(-angle); local dz = sin(alpha); local keys= 577 ; local ammo = GetLocalValue(I_CURWEP_AMMO ); aimPos+=Vector( dx, dy, dz); /*SendOnFootSyncData( keys, Pos.x,Pos.y, Pos.z, angle, GetPlayerHealth( npcid ), GetPlayerArmour( npcid ), GetPlayerArmedWeapon( npcid ),ammo, 0.0, 0.0, 0.0, aimPos.x, aimPos.y, aimPos.z, dx, dy, dz, false, isReloading ); */ SetTimerEx("FireSniperRifle", 60, 1, GetPlayerArmedWeapon(npcid), Pos.x, Pos.y, Pos.z, 16.0*dx, 16.0*dy, 16.0*dz ); } //Grab npc ID function OnNPCConnect(myplayerid) { npcid<-myplayerid; }