Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Ben1775

Using alive with BIS_fnc_spawnVehicle

Recommended Posts

Thanks in advance for any help.

 

Goal:  Spawn in a crewed APC whenever the vehicle does not exist (destroyed or mission start).  Vehicle will be assigned waypoints.

 

Error:  missing ; line 3 (_Vehicle=APCVehicle1[0])

 

Troubleshooting

  1. Removed line 3 and used !alive APCVehicle1 for line 4
  2. Removed line 3 and used !alive APCVehicle1[0] for line 4
  3. Created Crewed APC, then synced to System ==> Multiplayer ==> Vehicle Respawn module
    1. Spawns vehicle with crew at start
    2. Respawns vehicle without crew
  4. Added Expression to Respawn Module to assign crew
    1. Spawns vehicle with crew at start
    2. Respawns vehicle without crew

 

Ben

Mission initializes with
APCCrew1 = [];
APCVehicle1 = [];

Trigger calls this .sqf

if (isServer) then 
{
	_Vehicle=APCVehicle1[0];
	if (!alive _Vehicle) then 
	{
		APCCrew1 = creategroup EAST; 
		APCVehicle1 = [getMarkerPos "APC_Spawn", 020, "O_APC_Wheeled_02_rcws_F", APCCrew1] call BIS_fnc_spawnVehicle;

		_wp1 = APCCrew1 addWaypoint [(getmarkerpos "APC_WP1"), 0];
		_wp1 setWaypointType "MOVE";

		_wp2 = APCCrew1 addWaypoint [(getmarkerpos "APC_WP2"), 0];
		_wp2 setWaypointType "MOVE";

		hint "Enemy APC on the move towards home base";
     };
};

 

Share this post


Link to post
Share on other sites

APCCrew1 = []; is an array (useless as you change it later for a group)

APCVehicle1 = [];   is an empty array, so useless if you don't work with some elements.

 

APCVehicle1[0] is not a valid variable (mix of variable name and array). The first element of a non-empty array APCVehicle1 is (APCVehicle1 # 0)  but if your array stays empty... you will not gain anything.

 

!alive _vehicle   applies to an object (edited or scripted, but an object).

 

Share this post


Link to post
Share on other sites

Thank you for the information First Lieutenant pierremgi,

I've replaced "= []" with the full spawning of the crew and vehicle in the initialization of the mission.

Would you elaborate on how to properly use alive to detect if the vehicle is destroyed?

Share this post


Link to post
Share on other sites

You must elaborate an array of vehicles;

APCVehicles = [car1, truck36,tank5,bob,karl,jeep6,...];  // where car1,truck36... are the variable name of edited object

You can pushBack scripted ones by:

_vehicle = blahblah from bis_fnc_spawnVehicle  or createVehicle command

APCVehicles pushBack _vehicle;

 

 

then, you must detect when a vehicle of this array is !alive, in a trigger or a loop (to check that repeatedly):

cond:

(APCVehicles findIf {!alive _x} > -1)

on act:

0 = thisTrigger spawn {

  private _idx = (APCVehicles findIf {!alive _x});
  private _vehicle = APCVehicles deleteAt _idx;

  private _vehicleArray = [getMarkerPos "APC_Spawn", 020, typeOf _vehicle, group _vehicle] call BIS_fnc_spawnVehicle;

  _vehicle = _vehicleArray # 0;

  APCVehicles pushBack _vehicle;
};

 

That's for the principle. You'll face other problems with groups, safe positions (on multiple kills), adapted waypoints...

If you need something more elaborated >>> use MGI respawn vehicle (script or even better: module )

Share this post


Link to post
Share on other sites

×