Jump to content
Sign in to follow this  
alarm9k

AI crew exit vehicle when moved from player group to a separate AI group

Recommended Posts

I have a simple script that moves units from human player's group to High Command. It selects all units from team WHITE and moves them to a new group:

_selected join _newGroup;

and then does HC stuff which is irrelevant here.

Before the latest patch (1.34) it all worked fine: AI units that were spawned outside the vehicle and ordered to enter it (commander, gunner, driver) remained at their positions after being moved to a new group. After the patch they exit the vehicle!

This is only true for the AI what were initially spawned outside.

If I spawn a vehicle with the crew inside that belongs to player's group, they stay inside after being moved to another group.

I cannot understand what causes their different behaviour. Does anyone know?

Share this post


Link to post
Share on other sites

I'm not sure what exactly is going on or how you make the changes but I might have an idea. This doesn't have anything to do with my answer but, are you creating a new group or making them join a group that exists already? If a new group, you might want to put down a unit with 0% chance of spawning. Even though he doesn't spawn, it will make the group exist at start of mission.

Now my idea; Units spawned outside the vehicle are probably leaving the vehicle because it's no longer theirs. Joining a new group gives new orders. If the group doesn't "own" that vehicle, the leader will likely tell them to get out. You might want to assign them to the vehicle so that even if they switch groups, they still see the vehicle as theirs. Like a few missions I've played where we start in a vehicle, then get out on foot to fight, then you end up with a stupid AI group leader telling units to get back into vehicles that are miles away. If you use "assignascargo" or "assignasdriver" etc. command then they know that they belong to that vehicle.

You can also include those "assignas" to trigger when the switch triggers. If you look around the scripting page, looking up "assaign..." you will see other options that might be similar that might help.

So my advice is to have the group created from start of mission. even if you have one unit with 0 probability of presence.

Second is to use the assign command to tell the units where they belong or don't belong. Also, a small side note, they might be getting out because their leader is telling them to get in. Sometimes if the vehicle isn't yours, you being in it makes the AI think it's yours because you are inside it. Sometimes the Ai will tell you to do something you are already doing. Whenever I select all my units to get in, if someone is inside already, they get out and get back in. That's why I hate having vehicle crew in my group.

Share this post


Link to post
Share on other sites
because it's no longer theirs
If the group doesn't "own" that vehicle
they belong to that vehicle

Well, that was the question itself: what command sets this value (if it does exist) and how to read it. I have tried all reasonable comibinations of "assignAs", "addVehicle" etc to _assign_ this mysterious property, and all kinds of "assignedVehicle", "assignedVehicleRole" etc to find the difference between two groups behaving differently. To no avail.

And yes, I move units from my group to a newly created empty group.

Share this post


Link to post
Share on other sites

A workaround could be to delete the old crew as soon as they enter the vehicle then use something like BIS_fnc_spawnCrew, which returns the crew that you just spawned so you can assign them to all the HC stuff that you need to.

Share this post


Link to post
Share on other sites
delete the old crew as soon as they enter the vehicle then use something like BIS_fnc_spawnCrew

Yes, sure... but every dirty hack like this one adds too much overhead: need to save units' loadout, health values etc to spawn exactly the same unit as a crew member. Anyone looking at the resulting code would be terrified (facepalm)

Edited by alarm9k

Share this post


Link to post
Share on other sites

Well actually, based off of what your saying this may be faster than what your current script is doing, unless you want to actually see the units get spawned and enter the vehicle, this function saves the need to add waypoints and all that to each of the units and just directly spawns them in the vehicle, so it would actually make the script "lighter" in a sense while also allowing you to do what you need to with those particular units.

Like I said, that's how I have read your OP, if my assumptions are wrong, please enlighten me :p.

Share this post


Link to post
Share on other sites

What you suggest may be faster but... it won't have the same functionality. I use my script to move units to and from High Command in single player missions. Just to... make it easier for myself to command the AI around. I occasionally add it to 3rd party SP missions and play them that way. The whole script is just 18 lines of code:

add_to_hc = {
private ["_newGroup", "_selected"];
_newGroup = createGroup playerSide;
_selected = [];

{
	if (assignedTeam _x == "MAIN" and _x != player) then
	{
		_selected = _selected + [_x];
	};
}
forEach units group player;
_selected join _newGroup; // <-- Here they exit the vehicle!
player hcSetGroup [_newGroup];
};
hcRemoveAllGroups player;
player addAction ["Add Team White to HC", add_to_hc, [], 0.02];
player addAction ["Remove Team from HC", "hc\del.sqf", [], 0.01];

As you can see, it's simple, it does not alter or replace units and it gets (well, it did before) the job done. Deleting units and spawning them again inside the vehicle... would require a lot more code, if we wanted to keep the same functionality. I mean, if I order a sniper team to enter a Hunter, make them a separate HC group and order them to move 5km into position, I want them to be exactly the same sniper and spotter with the same rifles, ammo, radios, grenades and mines -- not some general crewmen.

Edited by alarm9k

Share this post


Link to post
Share on other sites

I don't see the need for the "_selected" array why not just have the units that meet the required conditions join the new group directly?

[_x] join _newGroup;

As far as the exiting on group change issue, I'm not too sure what could be going on there other than AI being pesky once again (after a patch).

Going off of Victim's idea, you could use the assignedVehicle command as a debug tool to see if the units are getting unassigned from the vehicle because this command returns objNull if there is no vehicle assigned to the unit.

Edited by JShock

Share this post


Link to post
Share on other sites
you could use the assignedVehicle command as a debug tool

I did, I did....

why not just have the units that meet the required conditions join the new group directly?

Don't remember why I did this. I might have had a reason... probably :)

Share this post


Link to post
Share on other sites

I mean the only thing it could be is either a group changing problem, which from this seems doubtful, or it could be a HC problem/new feature that popped up in the latest update. But see if making them join inside the forEach loop changes anything?

Edited by JShock

Share this post


Link to post
Share on other sites
HC problem/new feature

Not HC. They misbehave either with or without HC, just upon entering new group.

But see if making them join inside the forEach loop changes anything?

Well... why not.

Share this post


Link to post
Share on other sites

hi, thanks to few infos here and there, here the only way i found to make crews staying in the tank after joining an other group :

 

vehiChgSquad = compile "
_tank = _this select 0;
_group = _this select 1;
_leader = leader _group;
{deleteVehicle _x;} forEach crew _tank;
[_tank,_group] call BIS_fnc_spawnCrew;
_group selectLeader _leader;
{_x commandFollow _leader;}forEach crew _tank;
";
[TheTank,TargetSquad] call vehiChgSquad;

this means crews will be recreated :(  this is the only way i found after a lot of tries by so many manners.

Share this post


Link to post
Share on other sites
vehiChgSquad = {
	params ["_tank","_group"];
	private ["_leader","_driver","_gunner","_commander","_cargo"];
	_leader = leader _group;
	_driver = assignedDriver _tank;
	_gunner = assignedGunner _tank;
	_commander = assignedCommander _tank;
	_cargo = assignedCargo _tank;

	(crew _tank) joinSilent _group;

	_driver assignAsDriver _tank;
	_gunner assignAsGunner _tank;
	_commander assignAsCommander _tank;
	{
		_x assignAsCargo _tank;
	} count _cargo;

	_group selectLeader _leader;
	{
		_x commandFollow _leader;
	} count crew _tank;
};
[TheTank,TargetSquad] call vehiChgSquad;

try this instead

 

 

 

or this (slightly more elaborate):


fnc_assignVehicleRole = {
	params ["_unit","_veh","_data"];
	private ["_role"];
	_data params ["_role",["_tp",[]]];

	switch (_role) do 
	{
		case "Driver": 
		{
			_unit assignAsDriver _veh;
		};
		
		case "Gunner": 
		{
			_unit assignAsGunner _veh;
		};

		case "Commander": 
		{
			_unit assignAsCommander _veh;
		};

		case "Turret": 
		{
			_unit assignAsTurret [_veh,_tp];
		};

		case "Cargo": 
		{
			if (_tp isEqualTo []) then {
				_unit assignAsCargo _veh;
			} else {
				_unit assignAsTurret [_veh,_tp];
			};
		};
	};
};

fnc_vehiChgSquad = {
	params ["_tank","_group"];
	private ["_leader"];
	_leader = leader _group;
	
	{
		_role = assignedVehicleRole _x;
		[_x] joinSilent _group;
		_x doFollow _leader;
		[_x,_tank,_role] call fnc_assignVehicleRole;
	} count crew _tank;
};

[TheTank,TargetSquad] remoteExec ["fnc_vehiChgSquad", 2]; // make sure this is always run on the server

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  

×