OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: TheArgyll 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.
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";
-
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}
-
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.
-
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;
};
};
-
Thanks again for the reply. This is giving me an error "Type String; Expected Array"... Any ideas ?
-
_pos = [_i*_dx + _x, _j*dy + _y, 0];
There's an underscore missing after the * above. Should be *_dy.
That's one problem anyway...
-
_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;
};
};
-
Thanks for the replies, I now have it operational. Cheers !
-
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.