FireSniperRifleEx: Difference between revisions

From NPC for VCMP 0.4 Servers
Jump to navigation Jump to search
(Created page with "<poem style="border: 2px solid #d6d2c5; background-color: #ADD8E6; padding: 1em;"> This function has been added in v1.6. </poem> {{Welcome| desc=T...")
 
No edit summary
 
Line 9: Line 9:
::aimdir = The normalized direction vector(from aimpos to target ) multiplied by 16.
::aimdir = The normalized direction vector(from aimpos to target ) multiplied by 16.
</poem>|
</poem>|
example=<source lang="lua">
relfuncs=*[[FireSniperRifle]]
//Sniper Rifle
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, Vector( 16.0*dx, 16.0*dy, 16.0*dz) );
}
 
//Grab npc ID
function OnNPCConnect(myplayerid)
{
    npcid<-myplayerid;
}
</source>
}}
}}

Latest revision as of 19:48, 9 January 2023

This function has been added in v1.6.


Description:
This will send a packet to server which is filled by the following parameters.


Parameters:

( sniperid, aimpos, aimdir)

sniperid : The weapon ID of sniper (28 or 29) to fire.
aimpos : The Vector aim position of NPC ( can be determined using server using player.AimPos or can be calculated artificially).
aimdir = The normalized direction vector(from aimpos to target ) multiplied by 16.


Return Values:
This function does not return any specific values.



Related Functions

The following functions may be helpful as they relate to this function in one way or another.