Jump to content
Nope.X

I need to delete units when they've reached their waypoint

Recommended Posts

Hello,

So I have a small problem (hopefully). As the title states, I want to delete a group of units when they've reached their waypoint the problem is that I don't know how to detect whether or not they've reached their waypoint and how to delete the units when the script detected them reaching the waypoint.

Here's the code I used to create the move order:

Patrol_Evac_1 commandMove (getMarkerPos "Move_Patrol_Evac_1");
Patrol_Evac_2 commandMove (getMarkerPos "Move_Patrol_Evac_2");
Patrol_Evac_3 commandMove (getMarkerPos "Move_Patrol_Evac_3");

They have as you can see different waypoints so they need to be deleted at different times.

Share this post


Link to post
Share on other sites
1 hour ago, Nope.X said:

Hello,

So I have a small problem (hopefully). As the title states, I want to delete a group of units when they've reached their waypoint the problem is that I don't know how to detect whether or not they've reached their waypoint and how to delete the units when the script detected them reaching the waypoint.

Here's the code I used to create the move order:


Patrol_Evac_1 commandMove (getMarkerPos "Move_Patrol_Evac_1");
Patrol_Evac_2 commandMove (getMarkerPos "Move_Patrol_Evac_2");
Patrol_Evac_3 commandMove (getMarkerPos "Move_Patrol_Evac_3");

They have as you can see different waypoints so they need to be deleted at different times.

Why are there invisible spaces in Patrol_Evac_1 etc.?

 

commandMove will only move individual units, not groups.

For individual units this will do the trick:

_units = [Patrol_Evac_1,Patrol_Evac_2,Patrol_Evac_3];
_waypoints = ["Move_Patrol_Evac_1","Move_Patrol_Evac_2","Move_Patrol_Evac_3"];

_delete = [_units,_waypoints] spawn {
	params ["_units","_waypoints"];
	{_x commandMove getMarkerPos (_waypoints#(_units find _x))} forEach _units;
	while {count _units > 0} do {
		{deleteVehicle (_units deleteAt (_units find _x))} forEach (_units select {_x distance2D getMarkerPos (_waypoints#(_units find _x)) < 10});
		sleep 1;
	}
};

Will delete units that are closer than 10m from their individual marker destinations and also exit the loop if no more units exist.

 

Cheers

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

@Grumpy Old Man Okay, I should've specified with units I mean groups of enemies so that above wouldn't work right, if so what am I to use instead?

And what do you mean by invisible spaces, these: _?

 

Cheers

 

Share this post


Link to post
Share on other sites
3 hours ago, Nope.X said:

@Grumpy Old Man Okay, I should've specified with units I mean groups of enemies so that above wouldn't work right, if so what am I to use instead?

And what do you mean by invisible spaces, these: _?

 

Cheers

 

 

I recommend trying the code before making assumptions. AI units operate on the same routines no matter which side they belong to.

 

Edit: Sorry, disregard the above. I misread your reply. 

 

Incase of groups just use regular waypoints and their activation statements: 

 

Private _wp = Patrolgroup addWaypoint [getMarkerPos "testmarker", 0];

_wp setWaypointType "Move";

_wp setWaypointStatements ["true", "{ deleteVehicle _x} forEach thisList;" ];

 

P. S. We really need more editing options on mobile. 

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, Grumpy Old Man said:

Why are there invisible spaces in Patrol_Evac_1 etc.?

forum bug

Share this post


Link to post
Share on other sites
9 minutes ago, sarogahtyp said:

forum bug

@sarogahtyp So nothing to worry about right?

 

26 minutes ago, mrcurry said:

 

I recommend trying the code before making assumptions. AI units operate on the same routines no matter which side they belong to.

 

Edit: Sorry, disregard the above. I misread your reply. 

 

Incase of groups just use regular waypoints and their activation statements: 

 

Private _wp = Patrolgroup addWaypoint [getMarkerPos "testmarker", 0];

_wp setWaypointType "Move";

_wp setWaypointStatements ["true", "{ deleteVehicle _x} forEach thisList;" ];

 

P. S. We really need more editing options on mobile. 

@mrcurry Do I need to have the private before my variable, because I learned that the "_" is enough to make the variable private?
Also since it seems you know your way around variables, can I change a variable from within another script?

I can agree with the need for more editing options on mobile!

Cheers

Edited by Nope.X

Share this post


Link to post
Share on other sites
6 minutes ago, Nope.X said:

So nothing to worry about right?

you have to worry about it if you copy code out of forum because there are often invisible characters inside of it which cause error messages.

  • Like 2

Share this post


Link to post
Share on other sites
3 minutes ago, sarogahtyp said:

you have to worry about it if you copy code out of forum because there are often invisible characters inside of it which cause error messages.

 

This is actually so common , that it should be fixed if is possible.

@Dedmen can you have a check about it ?

Thanks !

  • Like 1

Share this post


Link to post
Share on other sites
22 minutes ago, Nope.X said:

Do I need to have the private before my variable, because I learned that the "_" is enough to make the variable private?

this is not the same and if you need it or not you have to decide yourself...

look at example 3 of the private wiki entry.

 

with private you are able to ensure to modify an already known variable in the current scope only. 

means you could use a variable in a script like _cool and give it a value of 123.

then you start a new scope by doing a while loop. inside of that while you could use private _cool; and then change the value of _cool to 345.

as long as you are inside the while loop _cool will be 345.

but if you are exiting that loop then _cool will have the value 123 as set before you entered the while loop...

Share this post


Link to post
Share on other sites
 
 
 
On 6/19/2019 at 6:27 PM, Grumpy Old Man said:

 

commandMove will only move individual units, not groups.

For individual units this will do the trick:


_units = [Patrol_Evac_1,Patrol_Evac_2,Patrol_Evac_3];
_waypoints = ["Move_Patrol_Evac_1","Move_Patrol_Evac_2","Move_Patrol_Evac_3"];

_delete = [_units,_waypoints] spawn {
	params ["_units","_waypoints"];
	{_x commandMove getMarkerPos (_waypoints#(_units find _x))} forEach _units;
	while {count _units > 0} do {
		{deleteVehicle (_units deleteAt (_units find _x))} forEach (_units select {_x distance2D getMarkerPos (_waypoints#(_units find _x)) < 10});
		sleep 1;
	}
};

 

@Grumpy Old Man Would I just need to add my other units to the _units list? E.g. 

_units = [Patrol_Evac_1,Patrol_Evac_2,Patrol_Evac_3,Patrol_Evac_4,Patrol_Evac_5,Patrol_Evac_6,Patrol_Evac_7,Patrol_Evac_8];

If the above works even with more than 3 units, do I then need to individually assign each unit it's own move command or can I just give the group a move command and they'll still get deleted?

 

Cheers!

Share this post


Link to post
Share on other sites

@Nope.X Can't quote your post for some reason, forum fun, heh.

The snippet should work for individual units, just add them to the units array and for each added unit add a marker for the unit to move towards.

For deleting the entire group depends if you want to delete only units from the group that are within deletion range, or delete the entire group if at least one unit is within deletion range.

As stated earlier, commandMove only moves a single unit, I don't see how this would work for entire groups, you'd need to use move instead, which will make the entire units group move towards the position.

 

Cheers

 

Share this post


Link to post
Share on other sites

@Grumpy Old Man I'd like to delete the entire group if at least one unit is within the range because I don't want any stragglers out and about due to Arma's AI.

I have now switched commandMove to move wherever I need to order a group to move.
What part if any would need to be changed in the script you've sent?

 

_delete = [_units,_waypoints] spawn {
	params ["_units","_waypoints"];
	{_x commandMove getMarkerPos (_waypoints#(_units find _x))} forEach _units;
	while {count _units > 0} do {
		{deleteVehicle (_units deleteAt (_units find _x))} forEach (_units select {_x distance2D getMarkerPos (_waypoints#(_units find _x)) < 10});
		sleep 1;
	}
};

This part checks whether units are close to the waypoint or if they aren't and if they are close deletes the units right?

 

Cheers!

Edited by Nope.X

Share this post


Link to post
Share on other sites
32 minutes ago, Nope.X said:

@Grumpy Old Man I'd like to delete the entire group if at least one unit is within the range because I don't want any stragglers out and about due to Arma's AI.

I have now switched commandMove to move wherever I need to order a group to move.
What part if any would need to be changed in the script you've sent?

 

Cheers!

Adjusted my snippet from above to delete entire groups:

 

_groupLeaders = [Patrol_Evac_1,Patrol_Evac_2,Patrol_Evac_3];//only add one unit per group
_waypoints = ["Move_Patrol_Evac_1","Move_Patrol_Evac_2","Move_Patrol_Evac_3"];

_delete = [_groupLeaders,_waypoints] spawn {
	params ["_groupLeaders","_waypoints"];	
	{_x move getMarkerPos (_waypoints#_forEachIndex)} forEach _groupLeaders;
	while {count _groupLeaders > 0} do {
		{
		if (count (units _x select {_x distance2D getMarkerpos (_waypoints#_forEachIndex) < 15}) > 0) then
			{
				{deleteVehicle _x} forEach units _x;
			}
		} forEach _groupLeaders;
		sleep 1
	}
};

Simply add one unit per group to the _groupLeaders array and make sure every group has a marker inside the waypoints array, when at least one unit is within 15m of the respective marker the entire group will be deleted.

This will work with as many groups you'll need, as long as every group has their own waypoint.

 

Alternatively and more clean solution would be to use scripted waypoints and onAct:

_groupLeaders = [Patrol_Evac_1,Patrol_Evac_2,Patrol_Evac_3];//only add one unit per group
_waypoints = ["Move_Patrol_Evac_1","Move_Patrol_Evac_2","Move_Patrol_Evac_3"];

{
	_mrk = _waypoints#_forEachIndex;
	//make sure no other waypoints exist
	while {count (waypoints group _x) > 0} do
	{
		deleteWaypoint ((waypoints group _x)#0);
	};
	_wp = group _x addWaypoint [getMarkerPos _mrk,0];
	[group _x,0] setWaypointType "MOVE";
	[group _x,0] setWayPointStatements ["true","{deleteVehicle _x} forEach units this"]
} forEach _groupLeaders;

 

Cheers

Share this post


Link to post
Share on other sites

@Grumpy Old Man firstly thanks a lot it finally worked! I still have one last question though.

Could you either explain to me how detecting if a unit is close to its waypoint works or create my a script in which I can insert what's supposed to happen when they are a certain distance away?

 

That'd be so awesome!

Cheers

Share this post


Link to post
Share on other sites
6 hours ago, Nope.X said:

@Grumpy Old Man firstly thanks a lot it finally worked! I still have one last question though.

Could you either explain to me how detecting if a unit is close to its waypoint works or create my a script in which I can insert what's supposed to happen when they are a certain distance away?

 

That'd be so awesome!

Cheers

You can simply modify the above snippet, setWaypointStatements will be executed when the group completes the waypoint.

 

Cheers

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

×