Jump to content
Sign in to follow this  
BinaryMan

Moving newly created ai units

Recommended Posts

I am wanting to move all 6 newly created ai units to the a marker called "CenterOfTown". The script below correctly creates 1 rifleman with the rank of sergeant and 5 rifleman units with the rank private. The script below also puts all of the units into the same group.

However my script is not moving the newly created units to the "CenterOfTown" marker, I have double check to make sure that I have spelled the name of my marker correctly. Further more, I am not seeing any syntax errors in my code. Can anyone see what I am doing wrong here?

_NewGroup = createGroup east;
for [{_i = 0}, {_i < 6}, {_i = _i + 1}] do
{

_MarkerToSpawnAt = format ["A%1", _i];
if( _i == 0) then
{
	"O_Soldier_F" createUnit [getMarkerPos _MarkerToSpawnAt, _NewGroup, "ACommander = this", .5, "SERGEANT"];
}
else
{
	"O_Soldier_F" createUnit [getMarkerPos _MarkerToSpawnAt, _NewGroup, "", .5, "PRIVATE"];
};
};
Hint "Finished Createing";
sleep 2;
ACommander doMove (getMarkerPos "CenterOfTown");
Hint "Moved";
sleep 2;

Thank you in advance.

Share this post


Link to post
Share on other sites
Not tested but maybe try...

leader _NewGroup doMove (getMarkerPos "CenterOfTown");

The following code above does not move any units to the Marker "CenterOfTown". I did a quick test just now with the following code.

_NewGroup = createGroup east;
"O_Soldier_F" createUnit [getMarkerPos "A1", _NewGroup, "", .5, "SERGEANT"];
leader _NewGroup doMove (getMarkerPos "CenterOfTown");

The code above DOES properly move the single spawned unit to the town. I am even more perplexed to the reason why the code below is not moving the entire group to the town.

_NewGroup = createGroup east;
for [{_i = 0}, {_i < 6}, {_i = _i + 1}] do
{

_MarkerToSpawnAt = format ["A%1", _i];
_GoToMarker = "CenterOfTown";
if( _i == 0) then
{
	"O_Soldier_F" createUnit [getMarkerPos _MarkerToSpawnAt, _NewGroup, "", .5, "SERGEANT"];
}
else
{
	"O_Soldier_F" createUnit [getMarkerPos _MarkerToSpawnAt, _NewGroup, "", .5, "PRIVATE"];
};
};
leader _NewGroup doMove (getMarkerPos "CenterOfTown");

In order to run my code do the following:

Place down 5 markers.

Name the first marker "A1".

Name the second marker "A2".

...

Name the fifth marker "A5".

Create a game logic module and under its init line type

dummy = [] execVM "NameOfYourSqfFile.sqf";

Lastly create a marker and name it "CenterOfTown"

Edited by BinaryMan
Changed the instructions for running my code to be more clear

Share this post


Link to post
Share on other sites

Does nobody know what the problem is? I'm quite stuck.

---------- Post added at 01:24 ---------- Previous post was at 00:07 ----------

I figured out the problem, I need to send an order to each unit to move not just the leader. This was my fundamental misunderstanding. Thank you ArmaSalt3!

Share this post


Link to post
Share on other sites

no probs mate =)

this is how i would have done it with regards to moving each individual units. How about you?

{_x doMove (getMarkerPos "CenterOfTown")} foreach units _NewGroup;

Share this post


Link to post
Share on other sites

My Solution is as follows:

units _NewGroup doMove (getMarkerPos "CenterOfTown");

I'm not sure which one is faster (if one is faster than the other) or easier to read. Thoughts?

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  

×