Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global.flycar = {{},{}}
- local function build (ent)
- if ent.name =="raven-1" then
- table.insert(global.flycar[1], ent)
- end
- end
- local function car_flying ()
- local cars = global.flycar
- for i,j in pairs(cars[1]) do
- if j.valid then
- if j.speed >= 0.3 then
- local fly = {position = j.position, speed = j.speed, orientation = j.orientation, health = j.health, itemburn = j.burner.currently_burning, fuel = j.burner.remaining_burning_fuel}
- local idx = j.passenger
- local surface = j.surface
- local inv = j.get_inventory(1).get_contents()
- local inv2 = j.get_inventory(2).get_contents()
- local grid = {}
- for _, equipment in pairs(j.grid.equipment) do
- table.insert(grid, {name = equipment.name, position = equipment.position, shield = equipment.shield, energy = equipment.energy})
- end
- j.destroy()
- j = surface.create_entity{name = "raven-2", position = fly.position, force = game.forces.player}
- for y,u in pairs(inv) do
- j.insert({name = y, count = u})
- end
- for y,u in pairs(inv2) do
- j.insert({name = y, count = u})
- end
- j.orientation = fly.orientation
- j.speed = fly.speed
- j.health = fly.health
- j.burner.currently_burning = fly.itemburn
- j.burner.remaining_burning_fuel = fly.fuel
- for _, eqm in pairs(grid) do
- local current_equipment = j.grid.put({name = eqm.name, position = eqm.position})
- if current_equipment and current_equipment.valid then
- if current_equipment.max_shield > 0 then current_equipment.shield = eqm.shield end
- if current_equipment.max_energy > 0 then current_equipment.energy = eqm.energy end
- end
- end
- j.passenger = idx
- local shadow = surface.create_entity{name = "raven-shadow", position = fly.position, force = game.forces.neutral}
- shadow.insert({name = "solid-fuel", count = 50})
- shadow.orientation = fly.orientation
- shadow.speed = fly.speed
- table.insert(cars[2], {j,shadow,0.1})
- end
- else table.remove(cars[1], i)
- end
- end
- for i,j in pairs(cars[2]) do
- if j[1].valid then
- if j[1].speed <= 0.27 then
- local idx = j[1].passenger
- local surface = j[1].surface
- local tilename = surface.get_tile(math.floor(j[1].position.x), math.floor(j[1].position.y)).name
- if tilename == "deepwater" or tilename == "water" then
- j[1].die()
- j[2].destroy()
- if idx ~= nil then
- if idx.valid then
- local position = idx.position
- tilename = surface.get_tile(math.floor(position.x), math.floor(position.y)).name
- if tilename == "deepwater" or tilename == "water" then idx.die() return
- else idx.health = idx.health - math.random(1,52)
- if idx.health == 0 then idx.die() return end
- end
- end
- end
- else
- local fly = {position = j[1].position, speed = j[1].speed, orientation = j[1].orientation, health = j[1].health, itemburn = j[1].burner.currently_burning, fuel = j[1].burner.remaining_burning_fuel}
- local inv = j[1].get_inventory(1).get_contents()
- local inv2 = j[1].get_inventory(2).get_contents()
- local grid = {}
- for _, equipment in pairs(j[1].grid.equipment) do
- table.insert(grid, {name = equipment.name, position = equipment.position, shield = equipment.shield, energy = equipment.energy})
- end
- j[1].destroy()
- j[2].destroy()
- j = surface.create_entity{name = "raven-1", position = fly.position, force = game.forces.player}
- for y,u in pairs(inv) do
- j.insert({name = y, count = u})
- end
- for y,u in pairs(inv2) do
- j.insert({name = y, count = u})
- end
- j.orientation = fly.orientation
- j.speed = fly.speed
- j.health = fly.health
- j.burner.currently_burning = fly.itemburn
- j.burner.remaining_burning_fuel = fly.fuel
- if tilename == "sand" or tilename == "sand-dark" then j.health = j.health - math.random(1,12) end
- for _, eqm in pairs(grid) do
- local current_equipment = j.grid.put({name = eqm.name, position = eqm.position})
- if current_equipment and current_equipment.valid then
- if current_equipment.max_shield > 0 then current_equipment.shield = eqm.shield end
- if current_equipment.max_energy > 0 then current_equipment.energy = eqm.energy end
- end
- end
- j.passenger = idx
- table.insert(cars[1], j)
- end
- else
- local chight = (j[1].speed - 0.29)*10 - j[3]
- j[3] = j[3] + chight
- j[1].teleport({j[1].position.x, j[1].position.y - chight})
- j[2].teleport({j[1].position.x + j[3], j[1].position.y + j[3]})
- j[2].orientation = j[1].orientation
- j[2].speed = j[1].speed
- end
- else
- if j[2].valid then j[2].destroy() end
- table.remove(cars[2], i)
- end
- end
- end
- --[[ Кусок кода для версии factorio, когда можно было покинуть транспорт на воде и не помереть.
- local function drive_control(idx)
- local player = game.players[idx]
- if not player.driving then
- local tilename = player.surface.get_tile(math.floor(player.position.x), math.floor(player.position.y)).name
- if tilename == "deepwater" or tilename == "water" then player.character.die() return end
- end
- end
- script.on_event(defines.events.on_player_driving_changed_state, function(event)
- drive_control(event.player_index)
- end)]]
- script.on_event(defines.events.on_built_entity, function(event)
- build(event.created_entity)
- end)
- script.on_event(defines.events.on_robot_built_entity, function(event)
- build(event.created_entity)
- end)
- script.on_event(defines.events.on_tick, function()
- car_flying()
- end)
Advertisement
Add Comment
Please, Sign In to add comment