Feature #9575

Fired EH returning the projectile object

Added by zGuba almost 5 years ago. Updated over 4 years ago.

Status:Closed Start date:03/12/2010
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:Event Handlers
Target version:1.55.75445
Affected ArmA II version: First affected ArmA II version:
Reproduced by another DH user:No Single / Multi Player?:
I am using some Mods:No BIForumURL:
I am using: NGUrl:
Reproducible for you:No WIKIurl:
Related to content of DLC:

Description

Currently we need to search for the bullet with nearestObject function family. The problem is that the search result relies much on performance, and f.e. minigun bullets or fast moving shells sometimes won't be catched at all.

History

Updated by CarlGustaffa almost 5 years ago

Big yes to this one. The usual search and destroy doesn't always work i.e. if several artillery guns fire at about the same time. Means my scripted illumination (or whatever) shells have some accompanied explosion somewhere else on the map.

Basically, I've given up on firing artillery guns, and now the firebase is usually placed far away :p

Updated by Xeno almost 5 years ago

I really do hope we get this change at least for OA.

Updated by BigDawgKS over 4 years ago

This would be a nice feature, but it's not a necessity. You can already grab and pass the projectile object to your script without it "missing". Ex:
player addEventHandler ["fired",{_this+[nearestObject[_this select 0,_this select 4]] execVM "fired.sqf"}];

The projectile is grabbed in non-parallel space, so it is always found regardless of the round/execution speed.

Updated by kju over 4 years ago

  • Due date deleted (05/12/2010)
  • Assignee deleted (Luca)

Updated by zGuba over 4 years ago

BigDawgKS wrote:

This would be a nice feature, but it's not a necessity. You can already grab and pass the projectile object to your script without it "missing". Ex:
player addEventHandler ["fired",{_this+[nearestObject[_this select 0,_this select 4]] execVM "fired.sqf"}];

The projectile is grabbed in non-parallel space, so it is always found regardless of the round/execution speed.

Sorry BigDawgKS, it often misses with rapid fire weapons like miniguns. NearestObject is quite costful operation, so projectile object returned with fired EH is really necessary.

Updated by BigDawgKS over 4 years ago

zGuba wrote:

BigDawgKS wrote:

This would be a nice feature, but it's not a necessity. You can already grab and pass the projectile object to your script without it "missing". Ex:
player addEventHandler ["fired",{_this+[nearestObject[_this select 0,_this select 4]] execVM "fired.sqf"}];

The projectile is grabbed in non-parallel space, so it is always found regardless of the round/execution speed.

Sorry BigDawgKS, it often misses with rapid fire weapons like miniguns. NearestObject is quite costful operation, so projectile object returned with fired EH is really necessary.

I think you're missing the point. The way I described will not miss the projectile, regardless of how fast you fire or anything else. It really has nothing to do with how fast nearestObject is, since it will suspend the engine while it looks (meaning the round can not move until it is found). If you want proof, use this code on your minigun:
this addEventHandler ["fired",{deleteVehicle nearestObject[_this select 0,_this select 4]}];

You can even try firing into the ground at point blank. The rounds will still be deleted before impacting the ground. As a matter of fact, it will even catch the projectile before it impacts even if you fire it with the muzzle clipping into an object or wall, so it looks like this will even grab the round in the same tick as it's created (before any impact detection even kicks in).

Updated by Sickboy over 4 years ago

Tried a rapid fire weapon like miniguns on vehicles too ?

Updated by BigDawgKS over 4 years ago

Sickboy wrote:

Tried a rapid fire weapon like miniguns on vehicles too ?

Yes, that's what I tested the above example on. I pointed the minigun directly at the ground and fired it at 4000rpm. Not one round hit the ground.

Updated by zGuba over 4 years ago

Please try with several infantry teams and tank platoons.

Updated by Sickboy over 4 years ago

Ah, i must've missed that part when reading, sry!

zGuba wrote:

Please try with several infantry teams and tank platoons.

Perhaps the problem is rather in where the nearestObject call is made. If it is inside a spawned script instance (anywhere in the callstack), this is probably the cause of missing some bullets.

Updated by zGuba over 4 years ago

The problem occurs when you don't want to delete bullets. Sometimes living bullets are catched twice. See ace_sys_air_fcs where I had to add bullet to special array to prevent it beign adjusted twice, resulting in 3 or more visible bullet paths: one adjusted correctly, one unadjusted and one adjusted twice.

Saying it's not a problem is just neglecting the obvious fact.

Updated by kju over 4 years ago

Without specific examples nothing is a fact zGuba.
Provide the code for others to test and we can continue to discuss.

Updated by zGuba over 4 years ago

Please get ACE and replace contents of ace_sys_air_fcs x\ace\addons\sys_air_fcs\fnc_fired.sqf file with that:

// Tank FCS by q1184
// Fired EH
// Call via XEH

private ["_unit,"_weapon","_v","_data","_index","_cur","_vel","_dirang","_curelevation","_curwindage","_dir","_spd","_ammo","_bullet","_upx","_upy","_upz","_x1","_y1","_z1","_k"];

_unit = _this select 0;
_weapon = _this select 1;
_ammo = _this select 4;
_bullet = _this select 5;
if (isNull _bullet) exitwith {};

_data = _unit getVariable "ace_sys_air_fcs_fired";
_index = _data find _ammo;
if (_index < 0 ) exitwith {};

_cur = _data select (_index + 1);
_curwindage = _cur select 0;
_curelevation = _cur select 1;

_v = velocity _bullet;
_spd = _v distance [0,0,0];
_dir = vectorDir _bullet;

_dirang = [(_dir select 0) atan2 (_dir select 1), sqrt((_dir select 1)^2 + (_dir select 0)^2) atan2 - (_dir select 2)];
_dirang = [(_dirang select 0) + _curwindage, (_dirang select 1) + _curelevation];

_dir = [sin(_dirang select 1) * sin(_dirang select 0), sin(_dirang select 1) * cos(_dirang select 0), - cos(_dirang select 1)];
_vel = [(_dir select 0) * _spd, (_dir select 1) * _spd, (_dir select 2) * _spd];

//vectorup for properly drawn tracers

_x1 = _dir select 0;
_y1 = _dir select 1;
_z1 = _dir select 2;
_upz = sqrt (_x1^2 + _y1^2);
_k = -_z1/_upz;
_upx = _k*_x1;
_upy = _k*_y1;

//Applying changes

_bullet setVectorDirAndUp [_dir,[_upx,_upy,_upz]];
_bullet setVelocity _vel;

// sync mp

_bullet setPosASL getPosASL _bullet;

Updated by BigDawgKS over 4 years ago

zGuba wrote:

Please try with several infantry teams and tank platoons.

Just tested. One group of 6 M1A1s & 2 USMC infantry squads vs a group of 5 T-90s and 2 Russian infantry squads. Gave all of them the eventhandler using an anybody present trigger and the following code:
{_X addEventHandler ["fired",{deleteVehicle nearestObject[_this select 0,_this select 1]}]} forEach thislist

It was quite a spectacular battle actually, and not a single rifle round, MG round, tank shell, or missile ever escaped deletion right out of the muzzle.

I think that's conclusive enough to say that this code effectively grabs the projectile 100% of the time. But I'm not sure I understand the problem you said you were having with grabbing multiple rounds. Can you please create an stand-alone example that doesn't require ACE? The only reason I can think of that a round is being grabbed more than once is if your eventhandler is getting activated multiple times (ie your eventhandler was added multiple times).

Updated by zGuba over 4 years ago

zGuba wrote:

The problem occurs when you don't want to delete bullets.

Updated by BigDawgKS over 4 years ago

zGuba wrote:

zGuba wrote:

The problem occurs when you don't want to delete bullets.

I don't understand. Deleting was just an easy way to test it, it should work just as fine for anything else you want to do with the grabbed projectile. What exactly is the problem you're having?

Updated by zGuba over 4 years ago

When you delete bullet, it is no longer took in account. Otherwise one bullet can be catched twice, especially when muzzle end is distant to vehicle's center point.

Updated by BigDawgKS over 4 years ago

zGuba wrote:

When you delete bullet, it is no longer took in account. Otherwise one bullet can be catched twice, especially when muzzle end is distant to vehicle's center point.

I see, I think I understand how that can happen. Still, you can get around it by using a position closer to the muzzle to use for the nearestObject command.

Updated by kju over 4 years ago

zGuba where is the nearestObject in your code?

In this state the example is unlikely to convince BI to introduce it I assume.
Either you want to make the effort to create a simple repro mission or not.

Updated by Sickboy over 4 years ago

I have extracted the code to:
http://dev-heaven.net/projects/ace-mod2/repository/revisions/develop/entry/Addons/sys_air_fcs/fnc_fired_test.sqf
And can confirm the behaviour.
This is what zGuba logged: http://pastebin.com/nDbziGFn

I didn't believe it at first either; must've been some variable in the calcs, however now reading about the relation of muzzle location and vehicle center etc, I suppose it makes a bit more sense.

I see, I think I understand how that can happen. Still, you can get around it by using a position closer to the muzzle to use for the nearestObject command.

Maybe that is so, but just because there are 'other' workarounds available, can still mean fixing it for good by including is better, easier, less error prone, and it would solve it for good, instead of half-assed :)

In any case, a good small repro mission, will hopefully help us get the object in the fired EH, iirc VBS has it, so you'd think it's a 3 second job (can't vote it down on that imo).

Updated by BigDawgKS over 4 years ago

I'm just trying to be realistic here. :)

The chances of BIS adding this are pretty slim, so in the mean time you can try using a position close to the muzzle to at least get your code working. IMO, a good idea might be to use selectionPosition and get the exact position of the muzzle, then start your nearestObject search there. That should give you the round you just fired every time, and not any other rounds.

Updated by kju over 4 years ago

  • Status changed from Assigned to Closed
  • Target version set to 1.55 BETA

Available in 1.55 (beta).

Updated by kju over 4 years ago

  • Target version changed from 1.55 BETA to 1.55.75445

Also available in: Atom PDF