Jump to content
Sign in to follow this  
kaleb c0d3

SOLVED: "Dirty" vehicle seat after using moveInCargo and variants

Recommended Posts

Sup all. I'm asking for advice on a strange AI behaviour using moveInCargo.

 

Scenario:
I'm making a teleport module that allows a player to teleport to other player (a quality of life mod to help zeus with players disconnections). The first release of this mod was simple: a custom dialog that let the player pick a teleport location using the others players positions. The problem was when the "target player" was inside a moving vehicle... the teleported player was usually killed by a car accident 😛

In the second release, I want to improve the mod: if the "target player" is inside a vehicle, and the vehicle has free seats, teleport the player to one of these seats.

 

Implementation:
If the "target player" is on foot, its a normal teleport (player setPosASL _target_player).
If the "target player" inside a vehicle, check for available seats (using "fullCrew"), and then using "moveInXXXXX" (cargo, commander, gunner, etc), "assignAsXXXXX" (cargo, commander, gunner, etc), I was able to teleport the player to one of the free seats on that vehicle. If no seats are available, just a "normal" teleport near the vehicle (TODO: air vehicles?).

 

The problem:
When I used one of the "moveInXXXX" functions against a player and a vehicle, the vehicle seat gets 'dirty': no AI can get into that seat anymore. Initially I tought it was some arma-3-wichcraft, a conflicting mod or an error with my code, but taking things to the basic, I was able to reproduce this strange AI behaviour on a fresh & clean mission, without any code. You can reproduce this weird thing like this:

 

  1. Create a new mission.
  2. Place a vehicle with only a unit as driver, and set it to "player unit".
  3. Place the zeus (curator) module.
  4. Start the mission.
  5. Get out from the vehicle.
  6. Enter zeus, spawn an allied squad (4+ units), and order them to get into the vehicle.

 

You will see that the AI won't occupy the 'dirty' player seat. Try switching player seat in the editor and try again, and you will see how the 'dirty seat' changes.
Why is that? Inspecting things a little, and exporting the mission to SQF code, you can see that the Arma 3 engine moves the player unit into a vehicle using "moveInDriver", just like I did it on the teleport code.

Another thing is that the problem is consistent using other "base" mods, for example ACE3: if you want to load a prisioner/wounded AI unit into a 'dirty seat', that seat is not usable anymore.

 

Final toughts:
I think that the scripted versions of moving a player into a seat does not clear/set certain flags on the vehicle, rendering that position unusable for the AI.

 

Sorry for the long post.
Thanks in advance.

Solution #1 (edited post @ 05/02/2022):

Thanks to @fn_Quicksilver, this is one way to fix this:

 

// Add this at initPlayerLocal.sqf or function with preInit/postInit to fix the 'dirty seat' behaviour.
player addEventHandler ["GetOutMan", {
	params ["_unit", "_role", "_vehicle", "_turret"];
	if !(isNull assignedVehicle _unit) then {
		unassignVehicle _unit;
	};
}];


 

Share this post


Link to post
Share on other sites

Hi,

 

Pretty sure this is related to vehicle/seat assignment.

 

When a unit (player or AI) is exiting a vehicle, you need to unassign that unit from the vehicle/seat. Once the seat is no longer assigned to a unit, the next unit will enter the seat without issues.

 

In much of my work, when player exits the vehicle, I have made sure the player is no longer connected to the vehicle in this manner.

 

using the commands:

 

leaveVehicle

unassignVehicle

 

you can use this command to check for "dirty" seat

 

assignedVehicle

 

assignedVehicleRole

  • Like 2

Share this post


Link to post
Share on other sites

Thank you very much @fn_Quiksilver, you nailed it!

 

Managed to patch it using an event handler like this (works in SP & MP):

 

// Add this at initPlayerLocal.sqf or function with preInit/postInit to fix the 'dirty seat' behaviour.
player addEventHandler ["GetOutMan", {
	params ["_unit", "_role", "_vehicle", "_turret"];
	if !(isNull assignedVehicle _unit) then {
		unassignVehicle _unit;
	};
}];

The "if !(isNull assignedVehicle _unit)" is used to made the fix stacked event handler friendly, just in case of another mod doing magic with the "GetOutMan" EH.

 

Thanks again, man.

  • Like 1

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  

×