
function TOZ34Sawnoff_OnCreate(items, result, player)
	for i=0,items:size()-1 do
		local item = items:get(i)
		if item:getType() == "TOZ34Shotgun" then
			result:setCurrentAmmoCount(item:getCurrentAmmoCount())
			if result:haveChamber() and item:haveChamber() and item:isRoundChambered() then
				result:setRoundChambered(true)
			end
			local modData = result:getModData()
			for k,v in pairs(item:getModData()) do
				modData[k] = v
			end
			local parts = item:getAllWeaponParts()
			for i=1,parts:size() do
				tryAttachPart(result, parts:get(i-1), player)
			end
			return
		end
    end
end

function IzhRifleSawnoff_OnCreate(items, result, player)
	for i=0,items:size()-1 do
		local item = items:get(i)
		if item:getType() == "IzhRifle" then
			result:setCurrentAmmoCount(item:getCurrentAmmoCount())
			if result:haveChamber() and item:haveChamber() and item:isRoundChambered() then
				result:setRoundChambered(true)
			end
			local modData = result:getModData()
			for k,v in pairs(item:getModData()) do
				modData[k] = v
			end
			local parts = item:getAllWeaponParts()
			for i=1,parts:size() do
				tryAttachPart(result, parts:get(i-1), player)
			end
			return
		end
    end
end

function MosinSawnoff_OnCreate(items, result, player)
	for i=0,items:size()-1 do
		local item = items:get(i)
		if item:getType() == "MosinSawnoff" then
			result:setCurrentAmmoCount(item:getCurrentAmmoCount())
			if result:haveChamber() and item:haveChamber() and item:isRoundChambered() then
				result:setRoundChambered(true)
			end
			local modData = result:getModData()
			for k,v in pairs(item:getModData()) do
				modData[k] = v
			end
			local parts = item:getAllWeaponParts()
			for i=1,parts:size() do
				tryAttachPart(result, parts:get(i-1), player)
			end
			return
		end
    end
end

function FoldingStock(items, result, player)
	for i=0,items:size()-1 do
		local item = items:get(i)
		if item:getSubCategory() == "Firearm" then
			result:setCurrentAmmoCount(item:getCurrentAmmoCount())
			if	item:isContainsClip() == true then
				result:setContainsClip(true);
			end
			if result:haveChamber() and item:haveChamber() and item:isRoundChambered() then
				result:setRoundChambered(true)
			end
			local modData = result:getModData()
			for k,v in pairs(item:getModData()) do
				modData[k] = v
			end
			local parts = item:getAllWeaponParts()
			if (result:isAimedFirearm() and item:isAimedFirearm()) then
				result:attachWeaponPart(item:getWeaponPart("Scope"))
				result:attachWeaponPart(item:getWeaponPart("Canon"))
				result:attachWeaponPart(item:getWeaponPart("Clip"))
				result:attachWeaponPart(item:getWeaponPart("Stock"))
				result:attachWeaponPart(item:getWeaponPart("Sling"))
				result:attachWeaponPart(item:getWeaponPart("RecoilPad"))
			end
			return
		end
    end
end

function APSDetachStock(items, result, player)
	for i=0,items:size()-1 do
		player:getInventory():AddItems("Base.APSstock",1);
		local item = items:get(i)
		if item:getSubCategory() == "Firearm" then
			result:setCurrentAmmoCount(item:getCurrentAmmoCount())
			if	item:isContainsClip() == true then
				result:setContainsClip(true);
			end
			if result:haveChamber() and item:haveChamber() and item:isRoundChambered() then
				result:setRoundChambered(true)
			end
			local modData = result:getModData()
			for k,v in pairs(item:getModData()) do
				modData[k] = v
			end
			local parts = item:getAllWeaponParts()
			if (result:isAimedFirearm() and item:isAimedFirearm()) then
				result:attachWeaponPart(item:getWeaponPart("Scope"))
				result:attachWeaponPart(item:getWeaponPart("Canon"))
				result:attachWeaponPart(item:getWeaponPart("Clip"))
				result:attachWeaponPart(item:getWeaponPart("Stock"))
				result:attachWeaponPart(item:getWeaponPart("Sling"))
				result:attachWeaponPart(item:getWeaponPart("RecoilPad"))
			end
			return
		end
    end
end