function DeliveryVehicle.getSkydiveDistances(F,i)local r={}for i=1,math.ceil(.3*i),1 do table.insert(r,F.randomGenerator:NextNumber(F.travelBeforeActive,F.travelBeforeActive+200))end for i=1,math.ceil(.25*i),1 do table.insert(r,F.randomGenerator:NextNumber(F.travelBeforeActive+200,F.travelDistance*.28571428571429))end for i=1,math.ceil(.2*i),1 do table.insert(r,F.randomGenerator:NextNumber(F.travelDistance*.28571428571429,F.travelDistance*.5))end for i=1,math.ceil(.15*i),1 do table.insert(r,F.randomGenerator:NextNumber(F.travelDistance*.5,F.travelUntilInactive))end for i=1,math.ceil(.1*i),1 do table.insert(r,100000)end table.sort(r)return r end function DeliveryVehicle.spawnSpecificPlayer(F,i)if not F.playersJumped[i]and tostring(PlayerMatchInfo.GetField(i,"\116\101\097\109\078\117\109\098\101\114"))==string.sub(F.currentModel.Name,16)then F.playersJumped[i]=true F:spawnPlayerFromVehicle(i)EventData:FireClient(i,"\069\120\105\116\101\100\068\101\108\105\118\101\114\121\086\101\104\105\099\108\101")end end function DeliveryVehicle.manageSkydivingForBots(i)(coroutine.wrap(function()local F={}for i,r in pairs(Players:GetPlayers())do if Util.playerIsBot(r)then table.insert(F,r)end end local r=i:getSkydiveDistances(#F)local G=1 while G<=#F and i:getCurrentPos()<i.travelUntilInactive do if r[G]<=i:getCurrentPos()then i:spawnSpecificPlayer(F[G])G=G+1 else wait()end end end))()end return DeliveryVehicle
-- These functions handle making bots jump out of bus at various times
function DeliveryVehicle:getSkydiveDistances(numBots)
	local skydiveTimes = {}
	for _ = 1, math.ceil(0.3 * numBots) do
		table.insert(
			skydiveTimes,
			self.randomGenerator:NextNumber(self.travelBeforeActive, self.travelBeforeActive + 200)
		)
	end

	for _ = 1, math.ceil(0.25 * numBots) do
		table.insert(
			skydiveTimes,
			self.randomGenerator:NextNumber(self.travelBeforeActive + 200, self.travelDistance * (2 / 7))
		)
	end

	for _ = 1, math.ceil(0.2 * numBots) do
		table.insert(
			skydiveTimes,
			self.randomGenerator:NextNumber(self.travelDistance * (2 / 7), self.travelDistance * (1 / 2))
		)
	end

	for _ = 1, math.ceil(0.15 * numBots) do
		table.insert(
			skydiveTimes,
			self.randomGenerator:NextNumber(self.travelDistance * (1 / 2), self.travelUntilInactive)
		)
	end

	for _ = 1, math.ceil(0.1 * numBots) do
		table.insert(skydiveTimes, 100000)
	end

	table.sort(skydiveTimes)

	return skydiveTimes
end

function DeliveryVehicle:spawnSpecificPlayer(player)
	if
		not self.playersJumped[player]
		and tostring(PlayerMatchInfo.GetField(player, "teamNumber")) == string.sub(self.currentModel.Name, 16)
	then
		self.playersJumped[player] = true
		self:spawnPlayerFromVehicle(player)
		EventData:FireClient(player, "ExitedDeliveryVehicle")
	end
end

function DeliveryVehicle:manageSkydivingForBots()
	coroutine.wrap(function()
		local botsInGame = {}
		for _, player in pairs(Players:GetPlayers()) do
			if Util.playerIsBot(player) then
				table.insert(botsInGame, player)
			end
		end
		local skydiveDistances = self:getSkydiveDistances(#botsInGame)

		local curID = 1
		while curID <= #botsInGame and self:getCurrentPos() < self.travelUntilInactive do -- stop trying to skydive players when skydiving period ends
			if skydiveDistances[curID] <= self:getCurrentPos() then
				self:spawnSpecificPlayer(botsInGame[curID])
				curID = curID + 1
			else
				wait()
			end
		end
	end)()
end

return DeliveryVehicle
