Home   Help Search Login Register  

Author Topic: Array of Targets  (Read 1753 times)

0 Members and 1 Guest are viewing this topic.

Offline TheArgyll

  • Members
  • *
Array of Targets
« on: 14 Jun 2007, 04:00:46 »
I am trying to create an array of targets by writing a function that is passed the X and Y origins, X and Y offsets, and X and Y number of targets. But after 3 hours, I am still getting nothing.
Does anyone have any idea how to do this, and have the targets named sequencially, for example, Target_1, Target_2 etc... Any ideas of code to orientate all targets to face due east would also be welcome.
Thanks,
Argyll.

Forgot to attach my code. Here it is:
This code is to create an array of targets from a NE location DOWN and to the LEFT.

Code: [Select]
Private [_Base[_X,_Y], "_OffX", "_OffY", "_TotX", "_TotY"];

_BaseX=(_This[_Base Select 0]);
_BaseY=(_This[_Base Select 1]);

_OffX=(_This Select 1);
_OffX=(_This Select 2);

_TotX=(_This Select 3);
_TotX=(_This Select 4);

_CurX=_BaseX;
_CurY=_BaseY;

#CreateTarg
CreateVehicle ["TargetEPopup", [(_CurX - _OffX), (_CurY),0],[],0, "NONE"];
_CurX = _CurX + _OffX;
_CurY = _CurY - _OffY;
_TotX = _TotX - 1;
?(_TotX == 0) : {_CurY = _CurY + _OffY;
_TotY = _TotY -1;
?(_TotY == 0) : exit;
Goto "CreateTarg";
« Last Edit: 14 Jun 2007, 10:04:32 by bedges »

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Array of Targets
« Reply #1 on: 14 Jun 2007, 18:00:45 »
What exactly is the effect you are trying to create and why do you use a separate counter for x and y?

First thing is that this should be done in a script, not a function. Functions are generally used when you need a return value. This is what your code would look like if corrected to run as an sqs script. You can only use goto in sqs scripts and you do not need semi-colons to terminate lines. You've got the right ideas but have a combination of typos and syntax errors.

_BaseX=(_This Select 0) select 0
_BaseY=(_This Select 0) select 1

_OffX=_This Select 1
_OffY=_This Select 2

_TotX=_This Select 3
_TotY=_This Select 4

_nX = _TotX
#CreateTarg
_targ = CreateVehicle ["TargetEPopup", [_BaseX + _OffX, _BaseY + OffY,0],[],0, "NONE"]
_targ setDir 90
_nX = _nX - 1
if (_nX == 0) then {_BaseY = _BaseY + _OffY; _nX = _TotX; _TotY = _TotY -1}
if (_TotY != 0) then {goto "CreateTarg}
« Last Edit: 15 Jun 2007, 14:23:44 by Mr.Peanut »
urp!

Offline TheArgyll

  • Members
  • *
Re: Array of Targets
« Reply #2 on: 14 Jun 2007, 18:34:33 »
Well, I am trying to recreate a realistic range, but allowing the mission creator to choose intervals between the targets on both axis. The code I came up with seems a very clunky way to do this, and the edited code doesnt seem to want to work either. If you can suggest an easier way to do this, please help. Thanks for the reply.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Array of Targets
« Reply #3 on: 14 Jun 2007, 19:14:49 »
nul = [_base, _offset, _total, _facing, _stagger] execVM "targetarray.sqf";
_base = 2d or 3d position array
_offset = 2d offset array
_total = 2d total array
_facing = direction for targets to face
_stagger = TRUE or FALSE

e.g.
nul = [[2000,3000,0],[10,20],[4,8],90,TRUE] execVM "targetarray.sqf";
will place target array centered at 2000,3000, with 4 targets spaced 10m apart in east-west direction, and 8 targets spaced 20m apart in north-south direction, targets will be facing _dir degrees i.e. 90=east, _stagger set to TRUE will stagger the targets, FALSE will not.


edit:
targetarray.sqf
_x = (_this select 0) select 0;
_y = (_this select 0) select 1;
_dx = (_this select 1) select 0;
_dy = (_this select 1) select 1;
_nx = (_this select 2) select 0;
_ny = (_this select 2) select 1;
_dir = _this select 3;
_stagger = _this select 4;
_x = _x - _dx*_nx/2;
_y = _y - _dy*_ny/2;
for [{_j = 0},{_j < _ny},{_j = _j + 1}] do
{
   if _stagger then {_x = _x +  _dx/2 - (_j mod 2)*_dx;};
   for [{_i = 0},{_i < _nx},{_i = _i + 1}] do
   {
       _pos = [_i*_dx + _x, _j*_dy + _y, 0];
       _targ = CreateVehicle ["TargetEPopup", _pos,[],0, "NONE"];
       _targ setDir _dir;
   };
};
« Last Edit: 15 Jun 2007, 14:22:26 by Mr.Peanut »
urp!

Offline TheArgyll

  • Members
  • *
Re: Array of Targets
« Reply #4 on: 14 Jun 2007, 20:55:52 »
Thanks again for the reply. This is giving me an error "Type String; Expected Array"... Any ideas ?

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Re: Array of Targets
« Reply #5 on: 14 Jun 2007, 22:04:35 »
Code: [Select]
       _pos = [_i*_dx + _x, _j*dy + _y, 0];

There's an underscore missing after the * above.  Should be *_dy. 

That's one problem anyway...
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Array of Targets
« Reply #6 on: 15 Jun 2007, 00:20:57 »
Code: [Select]
_x = (_this select 0) select 0;
_y = (_this select 0) select 1;
_dx = (_this select 1) select 0;
_dy = (_this select 1) select 1;
_nx = (_this select 2) select 0;
_ny = (_this select 2) select 1;
_dir = _this select 3;
_stagger = _this select 4;
_cos = cos -_dir;
_sin = sin -_dir;
_x = _x - (_cos*_dx*_nx/2 - _sin*_dy*_ny/2);
_y = _y - (_sin*_dx*_nx/2 + _cos*_dy*_ny/2);
for [{_j = 0},{_j < _ny},{_j = _j + 1}] do
{
   _yt = _j*_dy;
   if _stagger then {_x = _x + _cos*(_dx/2 - (_j mod 2)*_dx) - _sin*(_dy/2 - (_j mod 2)*_dy);};
   for [{_i = 0},{_i < _nx},{_i = _i + 1}] do
   {
       _xt = _i*_dx;
       _pos = [_cos*_xt - _sin*_yt + _x, _sin*_xt + _cos*_yt + _y, 0];
       _targ = CreateVehicle ["TargetEPopup", _pos,[],0, "NONE"];
       _targ setPos _pos;
       _targ setDir _dir;
   };
};
« Last Edit: 16 Jun 2007, 00:00:17 by Mr.Peanut »
urp!

Offline TheArgyll

  • Members
  • *
Re: Array of Targets
« Reply #7 on: 15 Jun 2007, 00:57:19 »
Thanks for the replies, I now have it operational. Cheers !

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Array of Targets
« Reply #8 on: 15 Jun 2007, 04:20:17 »
No problem. The axis rotation is a bit screwed up still, but my head is too soft to fix it right now. By playing around you can get what you want, but the script is not behaving exactly as I want it to.


edit: script should now behave
edit2: now script does really behave.
« Last Edit: 16 Jun 2007, 00:00:55 by Mr.Peanut »
urp!