require "DAMN_Parts";
require "DAMN_Spawns";

--***********************************************************
--**                   KI5 / bikinihorst                   **
--***********************************************************

DAMN.Parts:processConfigV2("M151A2", {
	["Bumper"] = {
		partId = "M151A2Bumper",
		itemToModel = {
			["Base.M151A2Bumper1_Item"] = "Bumper1",
			["Base.M998Bullbar1_Item"] = "Bumper2",
		},
		default = "first",
	},
	["BumperRear"] = {
		partId = "M151A2BumperRear",
		itemToModel = {
			["Base.M151A2BumperRear"] = "BumperRear0",
		},
		default = "trve_random",
		noPartChance = 10,
	},
	["CabArmor"] = {
		partId = "M151A2CabArmor",
		itemToModel = {
			["Base.M151A2CabArmor1_Item"] = "CabArmor1",
		},
        default = "trve_random",
		noPartChance = 95,
	},
	["Tarp"] = {
		partId = "M151A2Tarp",
		itemToModel = {
			["Base.M151A2Tarp1_Item"] = "Tarp1",
		},
        default = "trve_random",
		noPartChance = 50,
	},
	["WindshieldArmor"] = {
		partId = "M151A2WindshieldArmor",
		itemToModel = {
			["Base.M151A2WindshieldArmor1_Item"] = "WindshieldArmor1",
		},
        default = "trve_random",
		noPartChance = 95,
	},
	["BarrierLeft"] = {
		partId = "M151A2BarrierLeft",
		itemToModel = {
			["Base.M151A2BarrierLeft1_Item"] = "PRX75rigBarrierLeft1htdoora",
		},
	},
	["BarrierRight"] = {
		partId = "M151A2BarrierRight",
		itemToModel = {
			["Base.M151A2BarrierRight1_Item"] = "BarrierRight1",
		},
	},
	["SpareTire"] = {
		partId = "M151A2SpareTire",
		itemToModel = {
			["Base.V102Tire2"] = "SpareTire1",
		},
        default = "trve_random",
		noPartChance = 50,
	},
});


function M151A2.ContainerAccess.Trunk(vehicle, part, chr)
	if chr:getVehicle() == vehicle then
		local seat = vehicle:getSeat(chr)
		return seat == 3 or seat == 2 or seat == 1 or seat == 0;
	elseif chr:getVehicle() then
		return false
	else
		if not vehicle:isInArea(part:getArea(), chr) then return false end
		local doorPart = vehicle:getPartById("TrunkDoor")
		if doorPart and doorPart:getDoor() and not doorPart:getDoor():isOpen() then
			return false
		end
		return true
	end
end