Jump to content
Sign in to follow this  
twirly

TWIRL Virtual Sniper

Recommended Posts

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 by twirly
Clarity

Share this post


Link to post
Share on other sites

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×