twirly 11 Posted March 25, 2011 (edited) This is a script that simulates a sniper that will not miss non moving targets. One shot, one kill. It's also possible to have a distant gunshot sound that originates at the virtual shooter... and therefore is directional. It came about from this thread by Melmarkian. I had fun doing it and it seems to work well so thought I'd share it. Thanks for the idea! The script is here A demo is here vsniper.sqf:- /* A Virtual Sniper (v1.0.0) Author: Twirly (March 2010) A simple call:- nul = [target,vsniper] execVM "vsniper.sqf"; Where:- target => is your target... can be any object vsniper => is an object where the bullet will originate. An invisible hpad is good. A more complex call:- nul = [target,vsniper,aimhght,muzhght,projectil,muzzveloc] execVM "vsniper.sqf"; These are optional... but to specify a particular item you will need to specify the ones before it. Where:- aimhght => The height of aim. The further the target the higher the aim point. Default is 1.75m (chest height). muzhght => The height that the shot will originate from. Default is 0.5m projectil => The type of projectile. Default is "B_127x107_Ball". muzzveloc => The muzzle velocity. Default is 1000m/sec. */ private ["_target","_vsnipr","_aimhgt","_muzhgt","_prjctl","_muzvel","_dx","_dy","_dis","_ang","_z1","_z2","_z","_elev","_vel","_bullet"]; _target = _this select 0; _vsnipr = _this select 1; _aimhgt = if (count _this > 2) then {_this select 2} else {1.75}; _muzhgt = if (count _this > 3) then {_this select 3} else {0.5}; //default muzzle height 0.5m _prjctl = if (count _this > 4) then {_this select 4} else {"B_127x107_Ball"}; //default aim height above ground level 1.70m (chest height) _muzvel = if (count _this > 5) then {_this select 5} else {1000}; //default muzzle velocity of 1200m/sec; _dx = ((getpos _target) select 0) - ((getpos _vsnipr) select 0); _dy = ((getpos _target) select 1) - ((getpos _vsnipr) select 1); _dis = sqrt(_dx^2+_dy^2); _ang = _dx atan2 _dy; _z1 = (getPosASL _target select 2) + _aimhgt; _z2 = (getPosASL _vsnipr select 2) + _muzhgt; _z = _z1 - _z2; _elev = (atan (_z/_dis) mod 360); _vel = [(_muzvel * (sin _ang)),(_muzvel * (cos _ang)),_muzvel * sin (_elev)]; _bullet = _prjctl createVehicle [((getpos _vsnipr) select 0),((getpos _vsnipr) select 1),_muzhgt]; _bullet setVelocity _vel; //un-comment the next two lines if you have a gunshot sound defined in your description.ext //sleep (_dis/320); //_vsnipr say "gunshot"; In order to hear the gunshot... either download and use the files in the demo or place this in your description.ext and make sure you have the gunshot sound in yourmissionfolder/sounds/ description.ext class CfgSounds { sounds[]= {gunshot}; class gunshot { name = "gunshot"; sound[] = {sounds\gunshot.ogg, db+3, 1}; titles[] = {}; }; }; EDIT: Updated the demo to not include any addons. Edited March 25, 2011 by twirly Clarity Share this post Link to post Share on other sites
demonized 19 Posted March 25, 2011 cool, this will sure come in handy some time :) Share this post Link to post Share on other sites
JojoTheSlayer 35 Posted March 25, 2011 Does the demo use some mod? I cant run it. Share this post Link to post Share on other sites
igneous01 19 Posted March 25, 2011 very interesting script, ive been looking for something similar to this, a few questions: can i execute it when say an ai unit identifies an enemy unit? i personally want to use an ai sniper so that when he sees the player the script would execute. Is it dependant on specific preplaced positions? or can it fire with the same accuracy in many different ranges? thanks for the script, will check it out Share this post Link to post Share on other sites
darkxess 60 Posted March 25, 2011 Does the demo use some mod?I cant run it. Yes it does, by the looks of it its a Vilas addon! Anyways here is the fix: DownLoad Link! And thanks for this, really cool addition to my scripts :) Share this post Link to post Share on other sites
JojoTheSlayer 35 Posted March 25, 2011 Yes it does, by the looks of it its a Vilas addon! Anyways here is the fix: DownLoad Link! And thanks for this, really cool addition to my scripts :) Thx D and thx for the script T. Share this post Link to post Share on other sites
Melmarkian 11 Posted March 25, 2011 Thank you again for the script! I already have a few more ideas to use it. Share this post Link to post Share on other sites
ArmAriffic 10 Posted March 25, 2011 tested and i like it, thanks Share this post Link to post Share on other sites
abdecken 1 Posted March 26, 2011 does it/will it work in multiplayer on a dedicated server? Share this post Link to post Share on other sites
twirly 11 Posted March 26, 2011 Not sure about dedicated or MP server scripting at all.... but from what I understand it will work if it is only run on the server. Share this post Link to post Share on other sites