FireSniperRifle: Difference between revisions

From NPC for VCMP 0.4 Servers
Jump to navigation Jump to search
No edit summary
No edit summary
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, alpha, angle )</syntaxhighlight>
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
::alpha : The vertical angle in radians from aimpos to target. +ve value means target is above aimpos.
::dx, dy, dz = The normalized direction vector(from aimpos to target ) multiplied by 16.
::angle : Same as player.Angle on server side (it ranges from -PI to PI) of npc as if bot is facing towards the target from its aiming position.  
</poem>|
</poem>|
example=<source lang="lua">
//The following function will make npc shoot [Vector]tPos with weapon 29.
function SnipeAt(tPos)
{
local Pos=GetMyPos();
local angle= atan2(-(tPos.x-Pos.x), tPos.y-Pos.y);
local aimPos=Vector(tPos.x,tPos.y,tPos.z);
SendOnFootSyncData( 577,Pos.x,Pos.y, Pos.z, angle, GetPlayerHealth( npcid ), GetPlayerArmour( npcid ), 29, 0.0, 0.0, 0.0, aimPos.x, aimPos.y, aimPos.z, PI, PI, Pos.x<tPos.x?PI/2:-PI/2, false );
FireSniperRifle(29, aimPos.x, aimPos.y, aimPos.z, PI, PI, Pos.x<tPos.x?PI/2:-PI/2 );
}
function OnNPCConnect(myplayerid)
{
npcid<-myplayerid;
}
</source>
Since it is difficult to calculate the aiming position and aim direction by npc, it has been found that npc can shoot a target almost accurately (an exception when the player is in the almost north of npc 3.10~3.14 ) when the aiming position of npc is set exactly as the target position and aiming direction z co-ordinate set as -PI/2 if player is to the west ( of npc's position with N (north pole) taking into account. npc angle will be positive ) or PI/2 if player is to the east of npc ( the angle of bot will be negative ).|
note=This was added in v1.3 and will not work in previous builds.|
relfuncs=*[[SendOnFootSyncData]]|
}}

Revision as of 03:51, 24 November 2022

{{Welcome| desc=This will send a packet to server which is filled by the following parameters.|

params=

( 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.

|