If you happen to be in the vehicle you just summoned, the vehicle will be copied to the new position -- but the player will be "ejected" and left in the original position. This can be a problem if you're driving in a boat over deep water: The player would be stuck in the water without a chance to get into the boat again or moving anywhere (placing a landfill helps, but that is a dirty workaround!). Therefore, I check whether the summoned car has a driver (that will be the player because only he has the key to the car), and if it does, i copy the driver over to the new car:
Code: Select all
local driver = car.get_driver()
if driver then
debug("Driver: " .. tostring(driver.player.name))
debug("Driver position collides with player layer: " .. tostring(driver.player.surface.get_tile(entity.position).collides_with("player-layer")))
global.cars[index].set_driver(driver)
end