Jump to content
Sign in to follow this  
topeira

How to make an antire squad to "setunitpos"?

Recommended Posts

in many cases i like to give a

this setunitpos "middle" to soldiers so they stay crouched and behave a lot more realistically.

this is a really simple question -

what do i type in the init of the squads leader so that every soldier under his command has "this setunitpos "middle" behavior?

if u can explain what does all the _X and the { means than i'll be grateful since i can vaguely remember what the init line should look like, but im far from knowing it... and googling it gave me nada.

thanks :)

Share this post


Link to post
Share on other sites

{[color="Blue"]_x[/color] [color="DarkOrange"]setUnitPos[/color] "MIDDLE"} [color="Blue"]forEach[/color] [color="DarkOrange"]units[/color] [color="DarkOrange"]group[/color] [color="DarkGreen"][b]this[/b][/color];

forEach format:

{command} forEach array;

The _x is a special "built in" variable. It means "the current value" of the forEach array.

The setUnitPos, units and group are all commands. setUnitPos "MIDDLE" is the command that will command the unit to remain kneeling. In this case _x will be the unit each time through the array.

units is a command that creates an array of units from a group. The group in this case is a second command, group this, which uses the keyword this. The this keyword in this case refers to the leader who's init field you're putting this. So "group this" ends up meaning "the group of this unit". So units group this means "each of the units in the group that this unit is part of".

So the way you'd "read" that in English would be:

setUnitPos "MIDDLE" for each of the units in the group of this unit.

Edited by kylania
Oops!

Share this post


Link to post
Share on other sites

Would it be something like "{_x setUnitPos "MIDDLE"} foreach units player/groupname;"?

Edited by Daveyboy154
Too slow!

Share this post


Link to post
Share on other sites

if u can explain what does all the _X and the { means than i'll be grateful

thanks :)

{} tells the game engine that the enclosed text contains code

_x refers to each and every unit within a specified array

setUnitPos self explanatory command

"MIDDLE" the string that tells the game what position to chose ("DOWN", "MIDDLE", "UP")

forEach command that goes along with _x

units the plural form refers to all units within the selected group

this the selected group is the same group as the loon whose init field this is. If you refer to the same group from an external script you must exchange this with groupName

Share this post


Link to post
Share on other sites

this the selected group is the same group as the loon whose init field this is. If you refer to the same group from an external script you must exchange this with groupName

That's wrong. In init space, this is just the unit. You need the group command to get the group. Then you use units to get an array of members for that group.

However, if you're in a waypoint's on act space, you can use thislist to get an array of units in the group (to which the waypoint belongs). Just FYI.

---------- Post added at 03:27 PM ---------- Previous post was at 03:23 PM ----------

So the way you'd "read" that in English would be:

setUnitPos "MIDDLE" for each of the units in the group of this unit.

To be more correct (ok, this isn't really proper English, but better describes how the code works):

for each unit X of the list of units in the group of this guy, do the following: set unitpos of X to MIDDLE

Share this post


Link to post
Share on other sites

guys, thanks a lot for taking so much time to try and explain.

forgive me but my enlish ain't perfect nor is my "scriptonese" :P so i gotta ask:

what is ARRAY and what is LOON ? how would u translate it to someone who doesn't speak english?

Share this post


Link to post
Share on other sites

i usually put the code like this:

{_x setunitpos "UP"} foreach units groupleadername

works best if you name the group leader and replace the "name" from the code with it. For some reason i have had problems with code if i try it to use the group for it:

{_x setunitpos "UP"} foreach units group groupname

Some codes that needs to count how many are still alive from the group, have worked better when used the groupleaders name instead...dunno why thou =/

Share this post


Link to post
Share on other sites

Well, in that case "loon" is the unit. Must be some kind of nickname for "guy" or "dude" or "unit" or something. :)

A variable is a single value. An array is a group of values.

Example:

myVariable = 1;
myOtherVariable = "bob";
myArray = [1,2,3,4];
myOtherArray = [1,"2",3,"four"];  // note that in this example 1 and 3 are numbers while "2" and "four" are strings.

You can read more about them here: http://community.bistudio.com/wiki/Array

Share this post


Link to post
Share on other sites
i usually put the code like this:

{_x setunitpos "UP"} foreach units groupleadername

The problem with this is thati t requires the group leader to be alive (and still in that group). It works fine in the init, but if you used this code in mid-mission it would not be guarunteed to work.

{_x setunitpos "UP"} foreach units group groupname

This doesn't work because groupname is already a group, making the group command redundant (and wrong, since group expects an object).

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  

×