OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Centerbe on 14 Feb 2009, 12:25:32

Title: Anti-Air ammo with time-range fuse
Post by: Centerbe on 14 Feb 2009, 12:25:32
Hi, im newbie in scripting

how i can show the distance from player to target with sqf?
i see in some player view arma just show a cursor and distances in meters...

Code:

_range = target distance player; //????
hint _range;

thanks?
Title: Re: newbie help
Post by: Worldeater on 14 Feb 2009, 12:43:40
Welcome! :)

What do you mean with "target"? The object you are looking at? Or maybe the object your barrel is pointing at? Or your next waypoint?


Oh, and please, please with a cherry on top, write a proper topic description next time. ;)
Title: Re: distance from player to target with sqf?
Post by: Centerbe on 14 Feb 2009, 13:41:35
Hi Worldeater im sorry for bad description....

with target i mean the selected (lock) target of a player or AI....
I see in commander view when a target is locked, on screen appear name of unit locked and the range in meters of this from the observer. I think this distance is selected by the cursor, if cursor il lock on target it gives the distance in meters. If u know how misure the distance from the barrel to the object this is pointing at i think it can work similar.... Or if possible, i can the same use the variable showed in this commanding view?

I show you better my project;
I only need this approximative number in meters and divide this number for 790 (velocity in meter/sec of my ammo) then i have a time in sec my muzzle will fly from barrel to target. I need use this time as explosionTime in my cfgAmmo. So my ammo shell will explode at given approximative distance like real Anti Air shell.
Title: Re: distance from player to target with sqf?
Post by: Mandoble on 14 Feb 2009, 14:09:27
There is noly one point missing there as ArmA doesnt have any command to give you your current locked on target.
Title: Re: distance from player to target with sqf?
Post by: Centerbe on 14 Feb 2009, 14:25:36
Ok,
can i do the same with object observed or object barrel is pointing at?
Title: Re: distance from player to target with sqf?
Post by: Mandoble on 14 Feb 2009, 14:31:23
There is not such a thing as "object observed or pointed at" in ArmA returned by any command.
Title: Re: distance from player to target with sqf?
Post by: Centerbe on 14 Feb 2009, 14:40:41
I understand,
i need make a thing similar to a rangefinder.... or use the position of next enemy air unit
Title: Re: distance from player to target with sqf?
Post by: Mandoble on 14 Feb 2009, 14:46:29
Which is the case you want to solve? an AA unit vs a plane? A soldier vs a soldier?
If the former, then you have an option as there will be unlikely many planes in front of you gun. You may get your weapon Direction (the weapon of the vehicle), and then look for the closest air unit. Then get the angle between that unit and your vehicle position and calculate the difference between that angle and your weapon direction. If the difference is less than 20 degrees, you may "conclude" that, if any, this plane should be the target.
Title: Re: distance from player to target with sqf?
Post by: Centerbe on 14 Feb 2009, 15:26:41
Is a ship cannon vs a plane,
i can get this angle simple in one geometric plane (X-Y) and conclude if this object is the target.
Its a little difficoult for a beginners.... but i can try. How i can get position of closest air unit and direction of my weapon?

_targetPos = player nearTargets 5000
_weaponDir = direction weapons player

thank you very much....
Title: Re: distance from player to target with sqf?
Post by: Mandoble on 14 Feb 2009, 15:51:15
Might be nearTargets is not the best solution, you may try:
Code: [Select]
   private["_ship", "_trigger", "_planes"];
   _ship = _this select 0;
   _maxrange = 2000;
   _trigger = createTrigger ["EmptyDetector", getPos _ship];
   _trigger setTriggerActivation ["ANY", "PRESENT", false];
   _trigger setTriggerArea [_maxrange, _maxrange, 0, false];
   _trigger setTriggerType "NONE";
   _trigger setTriggerStatements ["this", "", ""];
   _trigger setTriggerTimeout [0, 0, 0, false ];
   Sleep 1;
   while {true} do
   {
      _trigger setPos getPos _ship;
      _planes = [];
      {
         if (_x isKindOf "Air") then
         {
            if (isEngineOn _x) then
            {
               _planes = _planes + [_x];
            };
         };
      } forEach list _trigger;

      if (count _planes > 0) then
      {
         // Check potential targets here
      };
      Sleep 0.5;
   };


Title: Re: distance from player to target with sqf?
Post by: Centerbe on 14 Feb 2009, 17:46:08

Im sorry Mandoble im feeling me very stupid ask to you this...
but if _x is the plane ID, i need measures the distance from _ship to _x

Code: [Select]
   private["_ship", "_trigger", "_planes"];
   _ship = _this select 0;
   _maxrange = 2000;
   _trigger = createTrigger ["EmptyDetector", getPos _ship];
   _trigger setTriggerActivation ["ANY", "PRESENT", false];
   _trigger setTriggerArea [_maxrange, _maxrange, 0, false];
   _trigger setTriggerType "NONE";
   _trigger setTriggerStatements ["this", "", ""];
   _trigger setTriggerTimeout [0, 0, 0, false ];
   Sleep 1;
   while {true} do
   {
      _trigger setPos getPos _ship;
      _planes = [];
      {
         if (_x isKindOf "Air") then
         {
            if (isEngineOn _x) then
            {
               _planes = _planes + [_x];
            };
         };
      } forEach list _trigger;

      if (count _planes > 0) then
      {
         if (side _planes == east) then          // if the planes is a enemy
      {
             _dist = _planes distance _trigger;
              hint format ["%1", _dist];          // show the distance value
      };
 
      };
      Sleep 0.5;
   };


I hope this is correct....
Title: Re: distance from player to target with sqf?
Post by: Mandoble on 14 Feb 2009, 17:55:09
Code: [Select]
   private["_ship", "_trigger", "_planes", "_msg", "_dist"];
   _ship = _this select 0;
   _maxrange = 2000;
   _trigger = createTrigger ["EmptyDetector", getPos _ship];
   _trigger setTriggerActivation ["ANY", "PRESENT", false];
   _trigger setTriggerArea [_maxrange, _maxrange, 0, false];
   _trigger setTriggerType "NONE";
   _trigger setTriggerStatements ["this", "", ""];
   _trigger setTriggerTimeout [0, 0, 0, false ];
   Sleep 1;
   while {true} do
   {
      _trigger setPos getPos _ship;
      _planes = [];
      {
         if (_x isKindOf "Air") then
         {
            if ((isEngineOn _x) && (side _x == east)) then
            {
               _planes = _planes + [_x];
            };
         };
      } forEach list _trigger;

      if (count _planes > 0) then
      {
         _msg = "";
         {
             _dist = _x distance _ship;
             _msg = _msg + format["Target:%1 - Range: %2\n", _x, _dist];
         } forEach _planes;
         hint _msg;          // show the distances and targets values
      };
      Sleep 0.5;
   };
Title: Re: distance from player to target with sqf?
Post by: Centerbe on 14 Feb 2009, 18:13:23
great.... it work fine.... :clap:
thanks very much i will study the code for progress....
thanks very much mandoble.
Title: Re: distance from player to target with sqf?
Post by: Mandoble on 14 Feb 2009, 18:31:40
You are still missing a point there, to make sure that the plane is more or less in front of your weapon.
Title: Re: distance from player to target with sqf?
Post by: Centerbe on 14 Feb 2009, 18:48:16
Im sorry mandoble i dont want disturb you yet....
i need measuring if angle of weapon is +/- at 10° from angle of target?

i need a correct syntax tutorial.... i use a basic tutorial but the examples dosent work....
im also tryng to divide the range in meters for 790 but result give me an error....
Title: Re: distance from player to target with sqf?
Post by: Mandoble on 14 Feb 2009, 18:58:16
i need measuring if angle of weapon is +/- at 10° from angle of target?

Yes, and you might consider also the vertical deviation, so that the target is in the cone of your weapon.
Title: Re: distance from player to target with sqf?
Post by: Centerbe on 14 Feb 2009, 19:24:24
ohhh now work...
i had divide it for 790.... values showed are plausibles

now i will check the correct target pointings:

I can use weaponDirection command,

_weaponDir = "NDD_Fletcher" weaponDirection "5inch"   // is a vector?
_targetDir = getPosASL _x                                       
_difference = _weaponDir - _targetDir
 if (-50 < _difference < 50) then
         {
                                                                         // target aquisition
          };
Title: Re: distance from player to target with sqf?
Post by: Mandoble on 14 Feb 2009, 20:46:47
weaponDirection returns a direction vector where, for example, [0,1,0] means north and level [x,y,z].
But your getPosASL is a position. And definitively you cannot get angles, or angle differences substracting a 3D position from a direction vector.
Title: Re: distance from player to target with sqf?
Post by: Centerbe on 14 Feb 2009, 20:56:14
ok, i can get the weapon direction angle with "getDir" but how get the angle of target relative to the weapon position in rad?
Title: Re: distance from player to target with sqf?
Post by: Planck on 14 Feb 2009, 21:02:11
Possibly you could use the command rad (http://ofpec.com/COMREF/index.php?action=details&id=259).


Planck
Title: Re: distance from player to target with sqf?
Post by: Mandoble on 14 Feb 2009, 21:21:50
Why do you want to use rads? All trigonometry functions in ArmA work well with degrees.
And no, you cannot get the weapon direction with getDir, getDir will return the vehicle direction.

Code: [Select]
// Angle to target (between ship and target), between -180 and 180 degrees.
_atarget = ((getPos _target select 0)-(getPos _ship select 0)) atan2 ((getPos _target select 1)-(getPos _ship select 1));
_wvdir = _ship weaponDirection "5inch"; // If 5inch is any weapon ...

// Angle of the weapon, between -180 and 180 degrees.
_aweapon = (_wvdir select 0) atan2 (_wvdir select 1);
Title: Re: distance from player to target with sqf?
Post by: Centerbe on 14 Feb 2009, 22:05:29
ah, getDir give a direction in degrees not in rad....
so i get 2 Arrays in degree of target and weapon,

_difference = (( _atarget select 0) - (_aweapon  select 0)) atan2 (( _atarget select 1) - (_aweapon  select 1));

 if (( -10 < (_difference select 0) < 10 ) atan2 ( -10 < (_difference select 1) < 10)) then
{
                  // // target aquisition
};


Title: Re: distance from player to target with sqf?
Post by: Mandoble on 14 Feb 2009, 22:07:02
No, in my example, _atarget is the angle in degrees between the ship and the target, and _aweapon is the angle in degrees of the weapon. None of them is any array, just plain angles.
Title: Re: distance from player to target with sqf?
Post by: Centerbe on 14 Feb 2009, 22:34:04
i will try the code....

Code: [Select]
  private["_ship", "_trigger", "_planes", "_msg", "_dist", "_target", "_atarget", "_wvdir", "_aweapon", "_diff"];
   _ship = _this select 0;
   _maxrange = 5000;
   _trigger = createTrigger ["EmptyDetector", getPos _ship];
   _trigger setTriggerActivation ["ANY", "PRESENT", false];
   _trigger setTriggerArea [_maxrange, _maxrange, 0, false];
   _trigger setTriggerType "NONE";
   _trigger setTriggerStatements ["this", "", ""];
   _trigger setTriggerTimeout [0, 0, 0, false ];
   Sleep 1;
   while {true} do
   {
      _trigger setPos getPos _ship;
      _planes = [];
      _target = [];
     
      {
         if (_x isKindOf "Air") then
         {
            if ((isEngineOn _x) && (side _x == east)) then
            {
               _planes = _planes + [_x];
               _target = _target + [_x];
            };
         };
      } forEach list _trigger;
                   
        if (count _planes > 0) then
            {
    // Angle to target (between ship and target), between -180 and 180 degrees.
          _atarget = ((getPos _target select 0)-(getPos _ship select 0)) atan2 ((getPos _target select 1)-(getPos _ship select 1));
          _wvdir = _ship weaponDirection "5inch"; // If 5inch is any weapon ...
          // Angle of the weapon, between -180 and 180 degrees.
          _aweapon = (_wvdir select 0) atan2 (_wvdir select 1);
    _diff = (_atarget select 0)-(_aweapon  select 0) atan2 (_atarget select 1) - (_aweapon select 1);
          _msg = "";
         {
             _dist = _x distance _ship;
             _times = _dist / 790;
             _msg = _msg + format["Target:%1 - Range: %2\n", _x, _times];
         } forEach _planes;
         hint format ["%1",_msg];          // show the distances and targets values
      };
      Sleep 0.5;
   };
    [\code]
Title: Re: distance from player to target with sqf?
Post by: Mandoble on 14 Feb 2009, 23:55:19
This is becoming chaotic and erratic. Please, check the commands (http://www.ofpec.com/COMREF/index.php) and the data types you are using into that script as well as the loops inside as in its current shape it is a nonsense.

BTW, is "5inch" any valid weapon?
Do you have any _target variable initialized?
Why do you check the weapon direction and angle of target inside the first loop instead of the loop where you have the potential planes?
What kind of condition or set or whatever is this??  :blink: :blink: :blink:
Code: [Select]
Set (configFile >> "CfgAmmo" >> "AA" >> "explosionTime") == _times;
Take your time and analyze your script as you didnt do an error but a lot of them.

Title: Re: distance from player to target with sqf?
Post by: Centerbe on 15 Feb 2009, 00:19:40
i will check all... im sorry
"5inch" is a valid weapon in the cfgWeapons
i have deleted the "Set (configFile >> "CfgAmmo" >> "AA" >> "explosionTime") == _times;" string....
Title: Re: Anti-Air ammo with time-range fuse
Post by: Mandoble on 15 Feb 2009, 10:11:59
With the new topic it is a bit clearer what you are trying to do but:
- Is this intended for players firing the guns manually?
- If yes, are the targets going to be formations of very slow flying bombers?

Because if you try to fire with this idea against an incoming 800km/h Su34, when you detect it, lets say at 3Km you may calculate the range, the muzzle velocity of the shell and conclude that you need to have a 1.5 seconds timed fuse based only on range to target and muzzle vel. But in 1.5 seconds the Su34 is 333m closer to your ship. So, in fact, your shell will explode too late even if the shell was fired considering an interception course.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Centerbe on 15 Feb 2009, 12:33:02
Hi mandoble,

Yes players can fire manually.

The addon is a WW2 Fletcher Destroyer with; 5 turrets with 5inch cannon (also anti air, with radar range shells time), 4 turrets with double 40mm bofors cannons (primary anti air), and 8 turrets with 20mm anti air machine guns.

The enemy planes will be the same planes of ww2 with relative low velocity and agility....
in numerous test, i have used the germans BF109 as enemy targets.
I had do many test, and in all of this the gunners AI can anyway (low, around 5-10%) hit planes without any explosive ammo, simple with direct hit of shells.

I have do other tests with explosive shells with a explosionTime ammo set up.... they hit planes perfectly an realistic look smoke explosion on air, explosion was at determinate range and relative times (example 0.5-2 sec).

Now this anti-air shell work fine with a simple determinate explosiontime valor, if this srcipt will work i think i will rename this as "Mando Anti-Air Explosive Shells".

A script question; why have you make a new _target variable and you havent use the previous _x variable for targets? I have modifield script, deleted bad strings, put targets discriminations is into the second loop and initialized _target as _x. But i have the same an error on _difference string.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Mandoble on 15 Feb 2009, 12:40:03
Might be this (http://www.ofpec.com/forum/index.php?topic=29981.0) can be of some help for you.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Centerbe on 15 Feb 2009, 12:58:14
I had just see your gun script, but it shoot at planes with defined dispersion of shells....!?

I dont want increase the direct target hit probably of this weapons.

In this case weapons dont hit the planes increasing the hit target probability, but more WW2 realistic with a explosion of shells at given range.... also if targets arent hitted directly but simple in proximity. The AI gunners will aiming normally the targets as well they can. Shells are explosives (it give a realistic explosion on air in any case), and explodes at a given range (time in script).

This idea born from the constatation that much real WW2 ammo, use a time fuse shells (see a WW2 movie)... and in some case, time of fuse was setting up by the radar rangefinder in general, by ship radar in this case.

This is different also from proximity range explosion fuse, because proximity fuse explode only if they will be near the targets.... but for ww2 realistic shells they must explodes anyway.

For your questions; the fact is i neednt a precise time-range valutation of all targets, because in real it wasnt much precise, but works fine the same. The probably of shoot down a target is the sum of a direct hit explosion and an indirect explosion at a given range.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Mandoble on 15 Feb 2009, 13:02:45
With mando gun you define the dispersion (it is an automatic gun) but the shells explode by proximity. Anyway mando gun is designed to work for automatic systems with even minimum reaction time and able to intercept incoming missiles, but probably the code in these scripts will help you with your calculations for the 5" guns.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Centerbe on 15 Feb 2009, 13:44:44
Of course, i will study your gun code... also if like i say before i dont need a proximity fuse, and for a newbie like me is difficoult understand in detailed how one of your expert script real work. Some things will rest for me certainly misunderstood. Thanks very much for your interesting in this project, you are true generous and patient people.

PS: i have corrected some bad string of code, but i have the same an error on "_difference" definition string.
I think i have bad defined "_target" variable as "_x".

Other problem, i have find a command for get a number from the config files (GetNumber), but exist a command for Set a variable into the config file?
Title: Re: Anti-Air ammo with time-range fuse
Post by: Mandoble on 15 Feb 2009, 13:59:38
You cannot modify the config, it is read-only.
and the _x inside a {} forEach array loop represents each of the elements of the array (one after another in the loop), so _x inside a {} forEach is a "reserved" word.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Centerbe on 15 Feb 2009, 14:14:33
well, i hope exist a way to set an object explode at a varible time..... or all this work is useless.

for _target, i will define it inside the {} forEach array ... or like something else...i try.Thanks.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Mandoble on 15 Feb 2009, 14:48:54
You can cause an "on-air" explosion at the position of an object (the shell) at any time. What you cannot do is just to force an object to explode n seconds after its creation. You may download Mando Missile (http://www.ofpec.com/ed_depot/index.php?action=details&id=536&game=ArmA), inside warheads folder you will find several scripts that cause mid-air explosions, including smoke effects, etc. For each round fired by your gun you need to calculate the flight time and generate one of these explosions at shell's position after the desired delay (and removing  the shell itself). Mando Gun shells also generate mid air explosions, but quite small for a 5inch gun.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Centerbe on 15 Feb 2009, 15:29:26
Great.... i will use it! Thanks
Umm im working on target discrimination now... i get an error if i define;

Code: [Select]
_diff = ((_atarget select 0)-(_aweapon  select 0)) atan2 ((_atarget select 1) - (_aweapon select 1));

but i havent if define;

Code: [Select]
_diff = (_atarget - _aweapon) atan2 (_atarget -_aweapon);
Title: Re: Anti-Air ammo with time-range fuse
Post by: Mandoble on 15 Feb 2009, 16:43:39
in the code _aweapon and _atarget are already angles, not sure why do you keep applying atan2 to calculated angles.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Centerbe on 15 Feb 2009, 17:19:53
see the test file, it show only times of possible targets. Look at time explosion (1.6sec):

http://files.filefront.com/FireTestmpg/;13292800;/fileinfo.html

or

http://www.youtube.com/watch?v=MOiZc6hZJB8 (http://www.youtube.com/watch?v=MOiZc6hZJB8)

But _aweapon and _atarget arent angles in X and Y ? I use atan2 for subtraction of X angles and Y angles separately... or not?  ???

Title: Re: Anti-Air ammo with time-range fuse
Post by: Mandoble on 15 Feb 2009, 19:43:54
Look at the angles, variables and angle diff in the picture.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Centerbe on 15 Feb 2009, 20:44:18
Well, the script now work.... im tryng to understand how much is AI capable to follow with weapons directions the angles of targets. So i show the differences from the angles of weapons and the anlges of targets;

Code: [Select]
   
{
_target = _x
_atarget = ((getPos _target select 0)-(getPos _ship select 0)) atan2 ((getPos _target select 1)-(getPos _ship select 1));
_wvdir = _ship weaponDirection "5inch"; // If 5inch is any weapon ...
_aweapon = (_wvdir select 0) atan2 (_wvdir select 1);
_diff = _atarget - _aweapon;
_dist = _x distance _ship;
_times = _dist / 790;
_msg = _msg + format["Target:%1 - Range: %2\n", _x, _diff];  // show the differences of angles
} forEach _planes;
         hint format ["%1",_msg];         
The differences of angles are around +/- 5° for correct targets, but i think its relative to the AI capacity to follow them and the turrets agility. I can try to increase the turret velocity for more accurate aiming? Or i can try also to calculate differences of angles around X axis?
Title: Re: Anti-Air ammo with time-range fuse
Post by: Mandoble on 16 Feb 2009, 20:20:22
Well, if the target is not just fling headon to the turret, then the AI will need to keep turning the turret, but for slow planes the angular velocity of the turret doesnt need to be any fast to keep the gun more or less aligned. But, if the 5inch muzzle vel is really that slow (790m/s) then it will require more than a second to reach the target at maximum operational range. Now lets suppose the Bf109s are aproaching headon to the Fletcher at 550 km/h, that means than in a second they have advanced more than 150m towards the ship and the detonation calculated time at firing time will be definitively wrong. The reason is the following, the AI aims to an intercption point, which is closer than the position of the target when the AI fires, but your calculated time is based on the position of the target, not on the interception point calculated by the AI.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Centerbe on 17 Feb 2009, 12:46:51
True your considerations, but i see in many cases that differences of angles are +/- around 0.
I think this is possible when planes directions of movement (vector) arent much perpendicular at the ship positions. In extreme case the planes vectors coincides with ship positions, also the turrets Y aiming angles of predicted trajectory coincides with planes angles from ship. In the opposite case the the planes vectors of movement are perpendicular at the ship position, the turrets Y aiming angles are at max difference from the planes angles from ship (advance trajectory prediction). So, the max difference values from turrets and targets angles (advance trajectory prediction), are directly proportional at the targets velocity, and inverse proportional from the muzzles velocity and targets distances.

I think this system should be in crisis not only for time exploding but also for target discrimination with fast and close targets, and relative high angular velocity. At contrary time explosion setting will be in severe crisis when angular velocity are small, when planes vectors of movement are along the ship position. Times of explosion will calculated from the moment of fire, but planes distances from ship changes during shell flyng times, and at moment of interception planes will be more close or far respect previous calculation, shell will explode too many forward or behind the real target position. So, the difference between planes positions calculated and planes position of intercepting will be more in proportion at planes velocity, and inverse proportion of muzzle velocity.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Mandoble on 17 Feb 2009, 15:13:35
I would say definitively this system is not for ArmA AI. The ship needs to create barriers of flak with each mounting firing about 10~15 shells per minute, so, if you enter that area there are high probabilities of suffering heavy damage. But not to pinpoint single targets ZSU-style.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Centerbe on 17 Feb 2009, 16:04:06
Umm i think some of this mental problems are silly. Now, i use a fixed time explosion... 1,6 sec if i remenber well, and like i show to you in movie, anti-air shell efficiency are the same good, very good. Its now work fine also if this kind of error is relevant, and at maximum of it. This because in this weapon neednt a real precision evalutation of times and targets distances... approximation work the same well. The same principle was in real, the old AA systems adopted a fire control based on simply radar device, in some aspect approximative, or in most case a manual time setting of shell, and it works well. Fletcher have a large amout of AA weapons 5 turret with 5inch cannon, 4 dual 40mm bofors and 8 20mm machine guns. Now with only 3 cannon turrets working, fletcher have however a good killing rate. The question isnt explode a shell at the same precise space target position, but simply approx around it. I can also use a manual time set for AA weapons, with a prefixed time of explosion example 1s, 1.5s, 2s ecc ecc

The collimation and discrimination of targets worries me more than explosion times.
However, in alternative i can write a code for a simple proximity fuse.

I need test the effective funcional of script.... how i can explode shells at given times? What is the command?
I must calculate times from shells creation to the predicted time.
Thanks very much...

PS: i have your msn contact... but u dont use msn?
Title: Re: Anti-Air ammo with time-range fuse
Post by: Mandoble on 17 Feb 2009, 16:48:53
You need to add a "Fired" event handler, when the associated script is executed (automatically) you get the time and the shell (the object), you wait the desired delay and then you remove the shell and create a mid-air explosion. Use "search" option in this forum for "Fired" Event handler.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Worldeater on 17 Feb 2009, 16:52:46
how i can explode shells at given times? What is the command?

There is no command to do this. But it is possible to have airburst ammo in ArmA. I'm currently testing some for the Vulcan. Here's what I did:

Step #1: Create a new ammo type
The original ammo for the Vulcan has no explosionTime (http://community.bistudio.com/wiki/CfgAmmo_Config_Reference#explosionTime) set. So I created a new ammo type that explodes immediately after creation.

Code: (config.cpp) [Select]
...
class CfgAmmo {
    class B_20mm_AA;
    class B_20mm_AA_Burst : B_20mm_AA {
        explosionTime = 0.00001; // zero won't work properly!
    };
};
...

Step #2: Replace the fired bullet via script
It goes like this:
- Detect when the gun is fired (via the "Fired" event handler)
- Find all bullets near the gun (via nearObjects).
- There may be "foreign" bullets around so find all bullets that were fired from this gun (comparison of two vectors: bullet velocity and weaponDirection).
- If the bullet was fired from the gun, start a tiny "fuse script" that waits and then replaces the old bullet (the non-exploding one) with the new one (that explode immediately after creation).


This approach works pretty well considering the high RPM rate of the M168. I'll try to create example mission so you can have a look at it. Just give me a day or two.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Centerbe on 17 Feb 2009, 17:14:15
Well, i use just now a fired event handler for initialize this script execution, i will initialize with init event handler i think....

My bullet have just a time airburst... i need redefine it as 0.0000001sec
But i dont understand why explode it immediately and then replace with other?

Afther you simply create an explosion at given time? But the targets between the barrel and predicted explosion dosent inpact in any object? U can hit only if target is at determinate point?

 ???

The mandoble script work.... this is the code
Code: [Select]
////////////////////////////////////////
//                                    //
//      Mandoble Time Fuse Shells     //
//                //
//                //
////////////////////////////////////////

  private["_ship", "_trigger", "_planes", "_msg", "_dist", "_target", "_atarget", "_wvdir", "_aweapon", "_diff"];
   _ship = _this select 0;
   _target = _this select 0;
   _maxrange = 5000;
   _trigger = createTrigger ["EmptyDetector", getPos _ship];
   _trigger setTriggerActivation ["ANY", "PRESENT", false];
   _trigger setTriggerArea [_maxrange, _maxrange, 0, false];
   _trigger setTriggerType "NONE";
   _trigger setTriggerStatements ["this", "", ""];
   _trigger setTriggerTimeout [0, 0, 0, false ];
   Sleep 1;
   while {true} do
   {
      _trigger setPos getPos _ship;
      _planes = [];
     
      {
         if (_x isKindOf "Air") then
         {
            if ((isEngineOn _x) && (side _x == east)) then
            {
               _planes = _planes + [_x];
             
            };
         };
      } forEach list _trigger;
                   
        if (count _planes > 0) then
            {
               
          _msg = "";
         {
       _target = _x;
       _atarget = ((getPos _target select 0)-(getPos _ship select 0)) atan2 ((getPos _target select 1)-(getPos _ship select 1));
             _wvdir = _ship weaponDirection "5inch"; // If 5inch is any weapon ...
             _aweapon = (_wvdir select 0) atan2 (_wvdir select 1);
             _diff = _atarget - _aweapon;
           
            if ((_diff < 4) && (_diff > -4)) then
            {
             _dist = _x distance _ship;
             _times = _dist / 790;            //   if 790 is the muzzle velocity in m/s
             _msg = _msg + format["Target:%1 - Range: %2\n", _x, _times];
            };
           
         } forEach _planes;
         hint format ["%1",_msg];          // show the times for predicted targets
      };
      Sleep 0.5;
   };


Title: Re: Anti-Air ammo with time-range fuse
Post by: Worldeater on 17 Feb 2009, 18:05:44
I think we have a language problem here. Let me explain again what happens:

1. The gun fires a regular, non-exploding bullet ("BulletA").
2. A script ("Script1") detects this bullet and starts another script ("Script2").
3. "Script2" waits 1s, 2s, whatever and then deletes "BulletA".
4. "Script2" then creates a new bullet ("BulletB") at the same position where the "BulletA" was. "BulletB" has a explosionTime of 0.0001s so it will explode immediately.
Title: Re: Anti-Air ammo with time-range fuse
Post by: Centerbe on 17 Feb 2009, 18:16:52
im sorry.... english isnt my mother leanguage as you can see.
you can not understand how much I'm ashamed now...   ::)

i imagine that bullet B will be created only if buttet A havent inpacted anything.... in other case we have 2 explosions   :D
Title: Re: Anti-Air ammo with time-range fuse
Post by: Worldeater on 17 Feb 2009, 18:30:05
I have to appologize for making you feel bad. It wasn't my intent to do so.

I'm just trying to help since I think this destroyer is a great project and should get all available support!
Title: Re: Anti-Air ammo with time-range fuse
Post by: Centerbe on 17 Feb 2009, 18:42:08
sure... its a great and also FREE project.... because my addons are all free for editing, who want partecipate to this project is wellcome. But its an hard work, much textures, models, polygons, turrets, guns, ammos, configs to do... ...ecc ecc

have u see the video of fletcher in action?
http://www.armaholic.com/forums.php?m=posts&p=44615&n=last#bottom
Title: Re: Anti-Air ammo with time-range fuse
Post by: Worldeater on 19 Feb 2009, 12:10:38
Yes, I saw this video. The whole thing just looks great!

And about the airburst ammo: yes, my script checks if bullet A still exists.