Home   Help Search Login Register  

Author Topic: How to get the MAX num of positions in buildings via scripting?  (Read 1584 times)

0 Members and 1 Guest are viewing this topic.

Offline haroon1992

  • Members
  • *
  • My life is hopeless...
_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.........................................................................
« Last Edit: 04 Sep 2009, 17:20:54 by haroon1992 »
Very busy with life, business, and other stuff. Away from OFP for months. Not sure if I could get back onto it. :(

Offline Trexian

  • Members
  • *
Re: Array questions concerning with local variables
« Reply #1 on: 03 Sep 2009, 18:23:20 »
1. I think you want to know if _evennumber is in _oddnumberarray?  (Code is sqf for me.)
Code: [Select]
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:
Code: [Select]
{
  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:
Code: [Select]
_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:
Code: [Select]
_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?
« Last Edit: 03 Sep 2009, 18:24:51 by Trexian »
Sic semper tyrannosauro.

Offline haroon1992

  • Members
  • *
  • My life is hopeless...
Re: Array questions concerning with local variables
« Reply #2 on: 04 Sep 2009, 16:07:32 »
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]





Very busy with life, business, and other stuff. Away from OFP for months. Not sure if I could get back onto it. :(

Offline Trexian

  • Members
  • *
Re: Array questions concerning with local variables
« Reply #3 on: 04 Sep 2009, 17:14:52 »
Excellent!  I worked on something similar awhile back, too. :)  When you get it working, will you post it? :)
Sic semper tyrannosauro.

Offline haroon1992

  • Members
  • *
  • My life is hopeless...
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...

Code: [Select]
_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...............................
« Last Edit: 05 Sep 2009, 16:57:50 by haroon1992 »
Very busy with life, business, and other stuff. Away from OFP for months. Not sure if I could get back onto it. :(