Jump to content
Sign in to follow this  
clydefrog

Spawning vehicles that will perform a random patrol

Recommended Posts

Where is it the "_firstpatrol = MyPatrolGroups select 0;" and " _secondpatrol = MyPatrolGroups select 1;" code goes?

In the place, where you need to refer to these groups.

After that code first patrol you will have under _firstpatrol variable (so for example code hint (str (count (units _firstpatrol))); in the same place (same file) will display on screen actual number of units in first patrol group), and second... well. Do I need to finish? :)

Remove "_" from variables if this place is located inside trigger or another file, not inside same sqf file as "_firstpatrol = MyPatrolGroups select 0;" and " _secondpatrol = MyPatrolGroups select 1;". (there is more issues with so called scopes and local (_) variables, but nevermind for now).

Share this post


Link to post
Share on other sites
In the place, where you need to refer to these groups.

So that would be

MyPatrolGroups = [_firstpatrol = MyPatrolGroups select 0; _secondpatrol = MyPatrolGroups select 1;];

?

Share this post


Link to post
Share on other sites

No. This is wrong, and - why? Both, _firstpatrol and _secondpatrol (or whatever name) variable you define (=) when you need to use somewhere name of a spawned group (you said, that you will refer to that groups, i do not know, where and for what purpose you will do that...). MyPatrolGroups is filled automatically after each spawn, you define it only once, as empty ([]) in init sqf.

Share this post


Link to post
Share on other sites

I thought it was wrong but I don't know where to put them, I don't think you said.

I want to refer to the groups so I can use them as a task like to destroy a convoy. I will put in a trigger condition e.g.

({alive _x} count units tankgroup1) < 1

to count if there are no units left alive in the group, then in the onAct a Task Accomplished hint etc.

and sorry, at the moment I still don't have a great understanding of what you are trying to explain to me, I'm not a scripter.

Share this post


Link to post
Share on other sites

So this act field will look like here with "my" method:

({alive _x} count units (MyPatrolGroups select 0)) < 1

Share this post


Link to post
Share on other sites

Yeah, so far I understand I need to put in my init.sqf:

MyPatrolGroups = [];

and then in patrol.sqf

_patrol = _config call RYD_Patrol;

_grp = _patrol select 0;

MyPatrolGroups set [(count MyPatrolGroups),_grp];

I am unsure of what that last line does (MyPatrolGroups set [(count MyPatrolGroups),_grp]; ) and also still I do not know where I declare the group names ( _firstpatrol = MyPatrolGroups select 0; _secondpatrol = MyPatrolGroups select 1; etc.)

instead of where it says

_grp = _patrol select 0;

do I put e.g. :

_firstpatrol = MyPatrolGroups select 0;
_secondpatrol = MyPatrolGroups select 1;
_thirdpatrol = MyPatrolGroups select 2;

etc?

Share this post


Link to post
Share on other sites

if you refer to that groups by using this:

({alive _x} count units (MyPatrolGroups select 0)) < 1
(for first patrol)

and perhaps following in other triggers:

({alive _x} count units (MyPatrolGroups select 1)) < 1
(for second patrol)
({alive _x} count units (MyPatrolGroups select 2)) < 1
(for third patrol)

etc.

then this:

_firstpatrol = MyPatrolGroups select 0;

_secondpatrol = MyPatrolGroups select 1;

_thirdpatrol = MyPatrolGroups select 2;

Is no longer needed, as this is just another form of reference to the group, given only as example, and good only for sqf file.

This:

MyPatrolGroups set [(count MyPatrolGroups),_grp];

adds new entry to the initially empty MyPatrolGroups.

(count MyPatrolGroups) will return number of currently present in the array elements, so, as index number of first element is 0, second is 1 and so on, this will give always first not used yet "slot" index in the array. This way, by set command, new spawned group name (_grp) will be added as new, next element in MyPatrolGroups array. For example, if array contains one element, eg: [group1] then count MyPatrolGroups is equal to 1. So on position of index "1" (second position) will be placed newly spawned group, so after that this array will look: [group1,group2]. Repeating procedure will give next element added on third "slot" and so on, and so on.

Another, slower (but difference is meaningless here) way to do same is:

MyPatrolGroups = MyPatrolGroups + [_grp];

Share this post


Link to post
Share on other sites
if you refer to that groups by using this:

(for first patrol)

and perhaps following in other triggers:

(for second patrol)

(for third patrol)

etc.

then this:

Is no longer needed, as this is just another form of reference to the group, given only as example, and good only for sqf file.

This:

adds new entry to the initially empty MyPatrolGroups.

(count MyPatrolGroups) will return number of currently present in the array elements, so, as index number of first element is 0, second is 1 and so on, this will give always first not used yet "slot" index in the array. This way, by set command, new spawned group name (_grp) will be added as new, next element in MyPatrolGroups array. For example, if array contains one element, eg: [group1] then count MyPatrolGroups is equal to 1. So on position of index "1" (second position) will be placed newly spawned group, so after that this array will look: [group1,group2]. Repeating procedure will give next element added on third "slot" and so on, and so on.

Another, slower (but difference is meaningless here) way to do same is:

MyPatrolGroups = MyPatrolGroups + [_grp];

That's pretty much gone right over my head, I am too much of a noob to understand this haha

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×