// Code derived from TheKappatalist420 on reddit in r/dayz https://www.reddit.com/r/dayz/comments/9hamlp/the_dayz_server_owner_howto_and_faq/
// Use one or another only, using all at the same time will undoubtedly cause issues (spawning all vehicles into 1 location just seems silly)
// Spawn Sedan at Player - Sedan is terribly uncontrollable, traction is practically non-existent. Doors, trunk and hood cannot be opened unless someone is already inside the vehicle (the option does not seem to cause an update on the model). Terrible storage capacity
EntityAI oCar = EntityAI.Cast(GetGame().CreateObject("CivilianSedan", player.GetPosition(), false, true));
oCar.GetInventory().CreateAttachment("CivSedanWheel");
oCar.GetInventory().CreateAttachment("CivSedanWheel");
oCar.GetInventory().CreateAttachment("CivSedanWheel");
oCar.GetInventory().CreateAttachment("CivSedanWheel");
oCar.GetInventory().CreateAttachment("CivSedanWheel");
oCar.GetInventory().CreateAttachment("CivSedanDoors_Driver");
oCar.GetInventory().CreateAttachment("CivSedanDoors_CoDriver");
oCar.GetInventory().CreateAttachment("CivSedanDoors_BackLeft");
oCar.GetInventory().CreateAttachment("CivSedanDoors_BackRight");
oCar.GetInventory().CreateAttachment("CivSedanTrunk");
oCar.GetInventory().CreateAttachment("CivSedanHood");
oCar.GetInventory().CreateAttachment("SparkPlug");
oCar.GetInventory().CreateAttachment("EngineBelt");
oCar.GetInventory().CreateAttachment("CarRadiator");
oCar.GetInventory().CreateAttachment("CarBattery");
oCar.GetInventory().CreateAttachment("HeadlightH7");
// Spawn Bus at Player - This is terribly broken. The doors do not open, and dialog to enter the vehicle as driver or passenger are absent. List may be missing some parts. Storage is not wide enough to fit an SVD, Mosin9130 or IZH18 Rifles (1 column short).
EntityAI oBus = EntityAI.Cast(GetGame().CreateObject("TransitBus", player.GetPosition(), false, true));
oBus.GetInventory().CreateAttachment("GlowPlug");
oBus.GetInventory().CreateAttachment("TruckBattery");
oBus.GetInventory().CreateAttachment("TruckExhaust");
oBus.GetInventory().CreateAttachment("TruckRadiator");
oBus.GetInventory().CreateAttachment("BusDoors_Left");
oBus.GetInventory().CreateAttachment("BusDoors_Right");
oBus.GetInventory().CreateAttachment("BusHood");
oBus.GetInventory().CreateAttachment("TransitBusWheel");
oBus.GetInventory().CreateAttachment("TransitBusWheel");
oBus.GetInventory().CreateAttachment("TransitBusWheelDouble");
oBus.GetInventory().CreateAttachment("TransitBusWheelDouble");
oBus.GetInventory().CreateAttachment("HeadlightH7");
// Spawn Van at Player - Incomplete. There is no interaction programmed, from what I can manage to achieve, so Doors and Trunk do not open. List may be missing some parts. Terrible storage capacity
EntityAI oVan = EntityAI.Cast(GetGame().CreateObject("CivilianVan", player.GetPosition(), false, true));
oVan.GetInventory().CreateAttachment("CivVanWheel");
oVan.GetInventory().CreateAttachment("CivVanWheel");
oVan.GetInventory().CreateAttachment("CivVanWheel");
oVan.GetInventory().CreateAttachment("CivVanWheel");
oVan.GetInventory().CreateAttachment("CivVanDoors_Driver");
oVan.GetInventory().CreateAttachment("CivVanDoors_CoDriver");
oVan.GetInventory().CreateAttachment("CivVanDoors_BackRight");
oVan.GetInventory().CreateAttachment("CivVanTrunk");
oVan.GetInventory().CreateAttachment("SparkPlug");
oVan.GetInventory().CreateAttachment("EngineBelt");
oVan.GetInventory().CreateAttachment("CarRadiator");
oVan.GetInventory().CreateAttachment("CarBattery");
oVan.GetInventory().CreateAttachment("HeadlightH7");
// Spawn Offroad Hatchback at Player. Doors, trunk and hood cannot be opened unless someone is already inside the vehicle (the option does not seem to cause an update on the model). Drives reasonably well. Terrible storage capacity
EntityAI oAWD = EntityAI.Cast(GetGame().CreateObject("OffroadHatchback", player.GetPosition(), false, true));
oAWD.GetInventory().CreateAttachment("HatchbackWheel");
oAWD.GetInventory().CreateAttachment("HatchbackWheel");
oAWD.GetInventory().CreateAttachment("HatchbackWheel");
oAWD.GetInventory().CreateAttachment("HatchbackWheel");
oAWD.GetInventory().CreateAttachment("HatchbackWheel");
oAWD.GetInventory().CreateAttachment("HatchbackDoors_Driver");
oAWD.GetInventory().CreateAttachment("HatchbackDoors_CoDriver");
oAWD.GetInventory().CreateAttachment("HatchbackHood");
oAWD.GetInventory().CreateAttachment("SparkPlug");
oAWD.GetInventory().CreateAttachment("EngineBelt");
oAWD.GetInventory().CreateAttachment("CarRadiator");
oAWD.GetInventory().CreateAttachment("CarBattery");
oAWD.GetInventory().CreateAttachment("HeadlightH7");
// Spawn V3S Chassis at Player - Untested, but theoretically should work the same as V3S Cargo tests (except the tailgate as it doesn't exist)
EntityAI oV3S = EntityAI.Cast(GetGame().CreateObject("V3S_Chassis", player.GetPosition(), false, true));
oV3S.GetInventory().CreateAttachment("V3SWheel");
oV3S.GetInventory().CreateAttachment("V3SWheel");
oV3S.GetInventory().CreateAttachment("V3SWheel");
oV3S.GetInventory().CreateAttachment("V3SWheel");
oV3S.GetInventory().CreateAttachment("V3SWheelDouble");
oV3S.GetInventory().CreateAttachment("V3SWheelDouble");
oV3S.GetInventory().CreateAttachment("V3SWheelDouble");
oV3S.GetInventory().CreateAttachment("V3SWheelDouble");
oV3S.GetInventory().CreateAttachment("V3SDoors_Driver");
oV3S,GetInventory().CreateAttachment("V3SDoors_CoDriver");
oV3S.GetInventory().CreateAttachment("V3SHood");
oV3S.GetInventory().CreateAttachment("GlowPlug");
oV3S.GetInventory().CreateAttachment("TruckRadiator");
oV3S.GetInventory().CreateAttachment("TruckExhaust");
oV3S.GetInventory().CreateAttachment("TruckBattery");
oV3S.GetInventory().CreateAttachment("HeadlightH7");
// Spawn V3S Cargo at Player. Doors and hood cannot be opened unless someone is already inside the vehicle (the option does not seem to cause an update on the model). Tailgate does not show interactions for players, so rear passengers are unable to enter the vehicle. Storage is not wide enough to fit an SVD, Mosin9130 or IZH18 Rifles (1 column short).
EntityAI oTruck = EntityAI.Cast(GetGame().CreateObject("V3S_Cargo", player.GetPosition(), false, true));
oTruck.GetInventory().CreateAttachment("V3SWheel");
oTruck.GetInventory().CreateAttachment("V3SWheel");
oTruck.GetInventory().CreateAttachment("V3SWheel");
oTruck.GetInventory().CreateAttachment("V3SWheel");
oTruck.GetInventory().CreateAttachment("V3SWheelDouble");
oTruck.GetInventory().CreateAttachment("V3SWheelDouble");
oTruck.GetInventory().CreateAttachment("V3SWheelDouble");
oTruck.GetInventory().CreateAttachment("V3SWheelDouble");
oTruck.GetInventory().CreateAttachment("V3SDoors_Driver");
oTruck,GetInventory().CreateAttachment("V3SDoors_CoDriver");
oTruck.GetInventory().CreateAttachment("V3SHood");
oTruck.GetInventory().CreateAttachment("GlowPlug");
oTruck.GetInventory().CreateAttachment("TruckRadiator");
oTruck.GetInventory().CreateAttachment("TruckExhaust");
oTruck.GetInventory().CreateAttachment("TruckBattery");
oTruck.GetInventory().CreateAttachment("HeadlightH7");
I recommend commenting out the driver's door, because you'll have to remove it to enter the vehicle anyway
Vehicle Persistence does not save. So a server restart will make your vehicle disappear (at least spawned in this method).
The consensus is that it crashes the client after about 2 minutes of driving. It seems to show fine on the player side for the driver, but other players apparently see the car fly off into space on their screens when it drives, so they are not multiplayer friendly yet.