i fixed with 2.1
script.on_event(defines.events.on_tick, function(event)
if event.tick % 2 == 0 then
return
end
local playerDictionary = game.connected_players
-- set if diagonal entrances to underground belts is allowed (Default: On)
local diff
local allowedDiff;
if settings.global["tunneler-diagonal-checking"].value then
allowedDiff = 2
else
allowedDiff = 0
end
-- guard against nils, then if the player has belt immunity equipment and has the setting turned on skip all the tunneler logic
for var, player in pairs(playerDictionary) do
if player.character ~= nil and settings.global["tunneler-equipment-immunity"].value
and player.character.grid ~= nil
and player.character.grid.find("belt-immunity-equipment")
then
if settings.global["tunneler-debug"].value then
player.print("Player collided with belt but has belt immunity.", { color = { 225, 0, 0 } })
end
goto skipPoint
end
local walkState = player.walking_state
-- if player is walking, check for underground belts within the set radius
if walkState.walking then
local localEntities = player.surface.find_entities_filtered {
position = player.position,
radius = settings.global["tunneler-radius"].value,
type = "underground-belt",
}
for var, belt in pairs(localEntities) do
-- for each underground belt calculate if the player is facing it, if it's an input belt, and if so
-- teleport to other end of the belt
diff = math.abs(walkState.direction - belt.direction)
diff = math.min(diff, 16 - diff)
if belt.belt_to_ground_type == "input" and diff <= allowedDiff then
if settings.global["tunneler-debug"].value then player.print(
"Player collided with " .. belt.name .. "!", { color = { 225, 225, 0 } }) end
-- `neighbours` was removed in Factorio 2.1. This property is
-- the underground belt endpoint, or nil when it is unconnected.
local outputBelt = belt.underground_belt_neighbour
if outputBelt ~= nil then
player.teleport(outputBelt.position, player.surface)
player.play_sound { path = "whoosh", volume_modifier = settings.global["tunneler-volume"].value }
if settings.global["tunneler-debug"].value then player.print(
"Teleported player to " .. outputBelt.position.x .. ", " .. outputBelt.position.y .. ".",
{ color = { 225, 225, 0 } }) end
else
if settings.global["tunneler-debug"].value then
player.print(
"Couldn't teleport due to unconnected belt!", { color = { 225, 0, 0 } })
end
end
end
end
end
::skipPoint::
end
end)