Jump to content
Sign in to follow this  
madmedic

delete a rocket in flight

Recommended Posts

Any way to do this?

I'm thinking this might be another way to get tandem guns on an airplane.

If they start out as rockets, firing from the wings...and turn into bullets after they are fired.

Share this post


Link to post
Share on other sites

Hi..

removing the rockets is not so complicated..

what you can do is to add a eventhandler fired.

make the evenhandler exec a script like this.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_air = _this select 0;

_list = (getpos _air) nearObjects 15;

_dir = getdir _air;

_nr = count _list;

_MyAmmoClass = "MY_ROCKET"

for [{_i=0},{_i <= _nr},{_i=_i+1}] do

{

_obj = _list select _i;

_type = typeOf _obj;

if ((_type == MY_ROCKET)) then

{deletevehicle _obj;};

};

but im not sure about replacing rockets with bullets..

if you can test if setting the vector on the bullets when you create it works."vector of plane". then you can do it..

hope this leads you in the right direction..

Share this post


Link to post
Share on other sites

Here is the whole thing with replacing the rocket:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

this addEventHandler ["fired", {[_this select 0, _this select 4] execVM "replace.sqf"}];

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_replace = "R_Hydra_HE"; //define what's the ammo class of the rocket you wanna replace

_replacement = "B_556x45_Ball"; //define what you wanna replace the rocket with

_multipl = 3; //mutltiplier of the speed - used to speed up the replacement

_unit = _this select 0; //get the unit who fired

_ammo = _this select 1; //get the ammo class that was fired

if (_ammo != _replace) exitWith {}; //exit if other ammo is fired

_rocket = nearestObject [_unit, _ammo]; //get the rocket fired

//get rocket's details:

_pos = getPos _rocket;

_dir = getDir _rocket;

_vel = velocity _rocket;

deleteVehicle _rocket; //delete the rocket

_bullet = _replacement createVehicle _pos; //spawn a replacement

//apply rocket's details to the replacement:

_bullet setDir _dir;

_bullet setVelocity [(_vel select 0) * _multipl, (_vel select 1) * _multipl, (_vel select 2) * _multipl];

Share this post


Link to post
Share on other sites

THANKS SOOO MUCH!!! I have tweaked your script a little, and it works PERFECTLY!!!

I will soon release a Camel with working tandem guns to demonstrate this.

I am testing, and tweaking it a little bit...but it appears to be the PERFECT way to add twin guns to an airplane.

(I made a custom rocket weapon, and added it to the camel...and then I added the "rocket" memory points at the machinegun barrels in the model...Then I applied the scripting, and it works great).

Share this post


Link to post
Share on other sites

I'm a little confused. As you "abuse" a rocket launcher as MG replacement (like the idea btw), wouldn't it be easier to create a new ammoclass inheriting from rockets but with models and settings from the desired bullet and also creating respective magazines and weapon?

So it would make the scripting thing needless?

Share this post


Link to post
Share on other sites

I'd recommend to precompile the fired EH function into a global var on init, and use call instead of execVM in the fired EH. Like this:

InitOnce:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">my_firedEH_function = compile preprocessfile "\myaddon\s\myfiredEH.sqf"

Adding the fired EH:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addEventHandler ["fired", {[_this select 0, _this select 4] call my_firedEH_function}];

It will perform much faster and more reliable this way.

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  

×