Jump to content
Sign in to follow this  
dreadedentity

AI not getting out of Assault boats

Recommended Posts

I wanted to make a beach insertion with inflatable landing craft. I have a boat named "boat1" which is not grouped to my units and my squad all with "this moveInCargo boat1;" in their INIT fields (this works fine). Now, the boat has a TRANSPORT UNLOAD waypoint set on the beach, but when it gets there it kicks me out but none of my squad. This is really confusing me because I made a quick helicopter insertion before I worked on this mission and the T UNLOAD worked perfectly. I believe it may have something to do with the waypoint placement being unreachable with the boat (too far inland) because when I manually order my squad to disembark, the boat driver continues with his waypoints, which are exiting the boat and then joining my squad. One last piece of supporting evidence, I removed the JOIN waypoint and added that code to the UNLOAD's "On Act." field but that also doesn't run until I manually order my squad to dismount.

I don't know why this isn't working and I've tried everything I can think of so if somebody more experienced could help me figure this out, that'd be great.

NOTE: The beach landing consists of 4 boats (hence boat1) intended to be led by human players, but for testing purposes requires AI. I have watched the other squads disembark properly but I'm not sure if that's because of a successful UNLOAD or because the squad leaders are ordering their troops to disembark. Not sure if that makes a difference.

Thanks.

Share this post


Link to post
Share on other sites

You could put something like this in the On Activation field of the waypoint:

0 = [] spawn {{unassignVehicle _x ; _x action ["Eject",  boat1]; sleep 1;} forEach (assignedCargo boat1);};

and change the waypoint to a normal "MOVE" one.

Share this post


Link to post
Share on other sites

Thanks for the help, works like a dream. Could you please tell me what the "spawn" command does and how/why you chose _x as the variable? Also, the crewman inside the boat didn't get out so I made the boats drive away and despawn using "destroyVehicle this;" but I followed them with a helicopter and it only deletes the crewman but not the vehicle. How can I make the crewman jump out of the boat and join my squad, or delete the entire boat after the drop?

Share this post


Link to post
Share on other sites

spawn is needed here to make a new thread so sleep can be executed.

_x is a predefined variabel inside forEach as a pointer.

Share this post


Link to post
Share on other sites

spawn basically creates a virtual script. You can't use the sleep command in a waypoint or trigger unless you spawn a script, or thread, as Lappihuan said. The code I used can be put in a waypoint or trigger On Act without spawn or sleep, like this:

{unassignVehicle _x ; _x action ["Eject",  boat1]} forEach (assignedCargo boat1);

...but all the units would be ejected at the same instant, which doesn't look good. I used spawn so there could be a 1 second delay (sleep 1) between each unit disembarking.

forEach uses the _x variable to refer to each element in the array, which in this case was the array of units provided by assignedCargo.

If you want to have the crew of the boat get out as well, you can add to that array like this:

... forEach (assignedCargo boat1 + crew boat1);

Share this post


Link to post
Share on other sites

Thanks for the help guys. I did some more testing on my own and I've almost made the insertion the exact way that I want it. I was having issues with the boats not moving to the shore with the MOVE waypoint, so I changed it back to TRANSPORT UNLOAD and deleted it's "On Act." field. Next, I added a trigger with condition:

!(player in boat1)

and in the Activation field:

deleteVehicle (driver boat1); {_x action ["Eject", boat1];} forEach crew boat1; group1 createUnit ["B_Soldier_F", getPos player]; boat1 engineOn false;

Everything looks good, no errors, the boat drives up on shore, my units dismount, the boat driver is deleted, the engine gets turned off...

HOWEVER

my createUnit function doesn't work (this was my workaround to having the boat driver get out and a JOIN waypoint set on my character, which requires the unit to get in proximity with the unit it's trying to join to, not very helpful when under heavy OPFOR fire). Group 1 is my group, also.

EDIT: I managed to get the createUnit to work by using createUnit array. New trigger "On Act." looks like this:

enableRadio false; deleteVehicle (driver boat1); {_x action ["Eject", boat1];} forEach crew boat1; _x = group1 createUnit ["B_Soldier_F",(getPos player),[],0,"NONE"]; boat1 engineOn false;

If you want to use this exact code, don't forget to set your group in the INIT field of your group leader, like:

group1 = group this;

One last question and I think I can take it from here for a while: I made a unit and used the sideChat function, however, I want to change the unit name to something like "Crossroad" or "Command" but it comes out as "Alpha 3-3" so I guess I need to somehow change the unit designation. How do I do this?

Edited by DreadedEntity

Share this post


Link to post
Share on other sites

groupName setGroupId ["Assault Squad"];

Also be aware that if you're making a multiplayer mission, a trigger that creates a unit will create the unit once for every player connected. Meaning, if there are four human players, four units will be spawned. Unless you wrap the whole thing in isServer.

if (isServer) then {stuff};

Share this post


Link to post
Share on other sites

Thanks, I'll try that out.

Also be aware that if you're making a multiplayer mission, a trigger that creates a unit will create the unit once for every player connected. Meaning, if there are four human players, four units will be spawned.

I removed all references to "player" and named my 4 playable squad leaders "player1" through "player4". Any player-specific code has been repeated 3 times with names replaced like "player2" or "player4". I know this is super un-optimized and I could probably do something with the "playableUnits" function and "forEach", but I'll figure that out on my own. It seems to work fine right now with AI characters, but will this method work alright in a multiplayer mission?

And lastly, seriously, the very last question I'll ask for this thread. Is there any way to create and edit scripts in the editor or do I need to create, edit, and move them into the mission files entirely outside of the editor (how do I even do that)?

EDIT: To clarify about the repeated code, I have a trigger and it's "On Act." field is this:

player1 addAction ["<t color='#FF0000'>Begin Invasion</t>", "invasion.sqf", [], 6, false, true];
player2 addAction ["<t color='#FF0000'>Begin Invasion</t>", "invasion.sqf", [], 6, false, true];
player3 addAction ["<t color='#FF0000'>Begin Invasion</t>", "invasion.sqf", [], 6, false, true];
player4 addAction ["<t color='#FF0000'>Begin Invasion</t>", "invasion.sqf", [], 6, false, true];

Will this work fine when I export and play with friends? Also clarifying my last question, when I do the action a box pops up saying invasion.sqf not found. I guess I can just use Notepad++ to work on that script, but how do I put it in the mission file when I'm finished?

Edited by DreadedEntity
Grammar, clarification

Share this post


Link to post
Share on other sites

The mission folder can be found in My Documents\Arma 3 Other Profiles\username\missions. You just save a script as .sqf and put it right in there.

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  

×