OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: haroon1992 on 03 Sep 2009, 17:24:50
-
_evennumber=_this select 0;
_oddnumberarray=[1,3,5,7,9]
How can i check if an even number is equal to any of the odd numbers in the _oddnumberarray?
OR
How can i check if an arguement ([this] exec "script.sqs") in a script is equal to ANY ONE of the elements provided in an array.
Also, how can i forward 1 by 1 for all elements in an array?
Eg. a time counter
_array = [1,2,3,4,5,6,7,8,9,10]
starts from 1 and ends in 10...
Haroon1992.........................................................................
-
1. I think you want to know if _evennumber is in _oddnumberarray? (Code is sqf for me.)
if (_evennumber in _oddnumberarray) then {hint "odd not in a bad way";};
But, forewarned is forearmed, to compare arrays, there's a deepEquals function or set of scripts around here somewhere that can do much more.
2. If an argument is equal to an element of an array? I think at that point, you're going to need to use global variables that can switch from one script to another. I guess I would need more information on what you're trying to accomplish. (Oh, and I know next to nothing about sqs.)
3. Iterating through an array is rather easy, and there are a couple different ways. Probably the easiest IMHO:
{
hint format ["number %1", _x];
sleep 1;
} forEach _array;
Literally "for each" element of the array, it will assign that value to _x within the loop.
You can also set it up:
_count = (count _array) - 1; // because ArmA arrays start at element 0
for [{_i = 0}, {_i <= _count}, {_i = _i + 1}] do
{
hint format ["number %1", _array select _count];
sleep 1;
};
This should do the same thing. The cool thing about the second way is that you can make it count down with a couple simple changes:
_count = (count _array) - 1; // because ArmA arrays start at element 0
for [{_i = _count}, {_i <= 0}, {_i = _i - 1}] do
{
hint format ["number %1", _array select _count];
sleep 1;
};
Does that help?
-
Thank you
I was just doing a house-patrol script and i wanted to know how to check the MAXIMUM number positions available for units in a certain BUILDING.
[For example, the hotel has a max of 256 positions for the units to patrol]
I am trying to do a dynamic house-patrol script...which makes the units patrol the nearest house for a while and moving to other house and patrol and so on....[Similar to house to house patrolling/searching]
And i want the units to patrol all the positions[domove to all positions] of the nearest house[which is possible for patrol].[Not asking , i know how to do this]
-
Excellent! I worked on something similar awhile back, too. :) When you get it working, will you post it? :)
-
Yeah, I will post it.....but unfortunately it will be in .sqs format, but there maybe someone in the community who will do the .sqf conversion....
Although this script seems not a HARD one [at least Mandoble can do it] but it fits in the hard section of my brain, so I may need help.
Now the array case,if you could answer me [if you know] how to get the MAXIMUM position of a building, it will be nice.
Here is the first RAW script...
_target = _this select 0;
_radius=_this select 1;
_timegiven=_this select 2;
_heli="HeliHempty" createvehicle position _target
_heli setpos [(getpos _target select 0)+(random _radius+random -_radius),(getpos _target select 1)+(random _radius+random -_radius),0]
;creates an invisible Helipad and move it to some where around _target within _radius.
#loop
if (not(alive _target)) then {exit};
_target domove getpos nearestbuilding _heli
;unit moves to building...
if (isNil "_timegiven") then {goto "notime"};
~_timegiven-1
#notime
_heli setpos [(getpos _target select 0)+(random _radius+random -_radius),(getpos _target select 1)+(random _radius+random -_radius),0]
~1
goto "loop"
The script currently makes the unit move to the buildings only, not all the positions of the buildings.
It should be :
_target domove (nearestbuilding _heli buildingpos position)
instead of
_target domove getpos nearestbuilding _heli
I have tried
_counter = nearestbuilding _heli count buildingpos
hint format ["%1",_counter]
_target domove (nearestbuilding _heli _counter )
And all i got in the hint is :
scalor
The hint shows scalor and i don't know what is that.
The script can be further expanded, with mode,speed, behaviour of unit etc but i just wanted to show you the simplest one[right now].
If you can, please test it with your machine,as mine has an out-dated ver of ArmA
Haroon1992...............................