Advertisement

Author Topic: Anti-Air ammo with time-range fuse  (Read 1758 times)

0 Members and 1 Guest are viewing this topic.

Offline Centerbe

  • Members
  • *
Anti-Air ammo with time-range fuse
« 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?
« Last Edit: 15 Feb 2009, 01:08:06 by Centerbe »

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: newbie help
« Reply #1 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. ;)
try { return true; } finally { return false; }

Offline Centerbe

  • Members
  • *
Re: distance from player to target with sqf?
« Reply #2 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.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: distance from player to target with sqf?
« Reply #3 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.

Offline Centerbe

  • Members
  • *
Re: distance from player to target with sqf?
« Reply #4 on: 14 Feb 2009, 14:25:36 »
Ok,
can i do the same with object observed or object barrel is pointing at?

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: distance from player to target with sqf?
« Reply #5 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.

Offline Centerbe

  • Members
  • *
Re: distance from player to target with sqf?
« Reply #6 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

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: distance from player to target with sqf?
« Reply #7 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.

Offline Centerbe

  • Members
  • *
Re: distance from player to target with sqf?
« Reply #8 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....

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: distance from player to target with sqf?
« Reply #9 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;
   };



Offline Centerbe

  • Members
  • *
Re: distance from player to target with sqf?
« Reply #10 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....

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: distance from player to target with sqf?
« Reply #11 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;
   };

Offline Centerbe

  • Members
  • *
Re: distance from player to target with sqf?
« Reply #12 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.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: distance from player to target with sqf?
« Reply #13 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.

Offline Centerbe

  • Members
  • *
Re: distance from player to target with sqf?
« Reply #14 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....