0
\$\begingroup\$

I'm fairly new to ArmA 3 scripting, and I'd like to know how to only spawn starting vehicles depending on how many players opt in to the mission. Say, the mission has four slots, but only two people fill them. There would be four vehicles, but two would be deleted on the mission start because those players weren't present. I've tried putting this code in the initialization of each vehicle;

sleep 1; if (isNull unit1) then {deleteVehicle this} else {};

But it only gives me errors when the mission starts.

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

You can get the number of human players at any time with:

_numHumans = count allPlayers;

A better solution may be to have players spawn into vehicles when they load into the game, as they may not be registered in allPlayers when initServer.sqf is ran.

In initPlayerServer.sqf (a script with this filename will run on the server every time a player connects):

params ["_player", "_didJIP"];

// Create a vehicle at the player's location and move them to the drivers seat.
_vehicleClass = "O_MRAP_02_GMG_F"; // Ifrit GMG's Type Classname
_veh = _vehicleClass createVehicle (getPos _player);
_player moveInDriver _veh;

This script will have the effect of the player spawning in the vehicle requested when they load into the game. You could easily have it spawn near them or at a specified location you can set either in the script or an editor marker.

\$\endgroup\$
0
\$\begingroup\$

I wouldn't create a static number of vehicles and then delete them if the max players isn't reached. This doesn't leave much room for join in progress players. Instead, you could create a spawn point for your players and then drop a crate or sign at the spawn location, use an addAction to add a menu item for players looking at the sign to spawn a new vehicle using the command createVehicle.

If you absolutely wanted the player to spawn in a vehicle then you could set the init.sqf script (which is launched when the player picks a side and loads the mission) to perform a createVehicle and moveInDriver to move him in to the new vehicle within a second.

Hopefully this helped you.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .