I'm making a script for a mission that you can use to create a group of units and a truck with createUnit and let them move to a position on the map.
The problem is that this is not working properly. My problem is replacing the driver when he gets killed and getting everyone out when the vehicle is under attack. After this getting them back in and let them move out towards their destination.
Once at their destination they remain there for a few minutes and will get back in the truck to drive back to their starting position. During this ride back dead drivers should be replaced too and if the enemy gets near and attacks the truck everyone should get out. After the fight the truck should move again.
The code I wrote could do the simple thing of letting get into the truck and let them drive towards the destination. Get them out, wait, get them back in and drive back.
But, the code I made failed when I shot the driver.
_moveTo = _this select 0;
_aantalMan = 8;
_o = 1;
nummerVracht = nummerVracht + 1;
_truck1 = "TruckV3SCivil" createVehicle getpos out_gate;
_i = 1;
#make
?(_i == 1): "Civilian11" createUnit [getpos policeSpawn,truckMaster,format["vracht%1_%2 = this;",nummerVracht,_i],0.6,"captain"]; _unit = call format["vracht%1_%2",nummerVracht,_i]; ;_unit moveInDriver _truck1;
?(_i == 1): [_unit] join GrpNull; _Group1 = group _unit;
?(_i != 1): "Civilian8" createUnit [getpos policeSpawn,truckMaster,format["vracht%1_%2 = this;",nummerVracht,_i],0.6,"private"]; _unit = call format["vracht%1_%2",nummerVracht,_i]; [_unit] join GrpNull; ;_unit moveInCargo _truck1;
_unit removeWeapon "binocular";
if (_i <= _aantalMan-1) then { _i = _i + 1; goto "make" }
_unitArray = [call format["vracht%1_1",nummerVracht],call format["vracht%1_2",nummerVracht],call format["vracht%1_3",nummerVracht],call format["vracht%1_4",nummerVracht],call format ["vracht%1_5",nummerVracht],call format["vracht%1_6",nummerVracht],call format["vracht%1_7",nummerVracht],call format["vracht%1_8",nummerVracht]]
(call format["vracht%1_1",nummerVracht]) moveInDriver _truck1;
_unitArray doMove getpos _moveTo;
"_x setBehaviour {AWARE}" foreach _unitArray;
"_x allowFleeing 0" foreach _unitArray;
"_x setCombatMode {RED}" foreach _unitArray;
~5
#loop
?!(alive (driver _truck1)): goto "newDriver"
goto "loop"
#newDriver
_unit = call format["vracht%1_%2",nummerVracht,_o];
~2
hint format ["%1",_unit];
if(alive _unit) then { _unit moveInDriver _truck1; } else { _o = _o + 1; goto "newDriver" }
@(_unit == driver _truck1)
#GetIn
if(_o <= count _unitArray) then { _o = _o + 1; } else { _unitArray doMove getPos _moveTo; _o = 1; goto "loop" }
_unit = call format["vracht%1_%2",nummerVracht,_o];
_unit AssignAsCargo _truck1;
goto "GetIn"
EDIT: sorry for any dutch text in the code
The script I use is the following. Although I have about four versions of it, none of them work. This is my latest one. Can anyone help me. The problems I have right now, is that I know no way of letting everyone get out when the enemy is present. And that replacing the driver takes too long (about 15 seconds or so) and it will only work once, whereas I thought that it should work every time.
EDIT: Another problem, how to remove dead units from an array. I might have a solution for my problem if I know how to do this. My other big problem remains, how to check if there's enemy units in the vicinity.