Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Inserter tool
- local inserter_tool_selected = {}
- local inserter_tool_status = 0
- script.on_event(defines.events.on_player_selected_area, function(event)
- if event.item == "picker-ore-eraser" then
- local player = game.players[event.player_index]
- local loc = event.area.left_top
- local entities = event.entities
- local d
- local reach = 2.5
- reach = reach * reach
- if (inserter_tool_status == 0) then
- inserter_tool_selected = {}
- for _,entity in ipairs(entities) do
- if entity.type == "inserter" then
- table.insert(inserter_tool_selected, entity)
- end
- end
- if (#inserter_tool_selected > 0) then
- player.print("Selected " .. #inserter_tool_selected .. " inserters. Please select the drop location.")
- inserter_tool_status = 1
- end
- else if (inserter_tool_status == 1) then
- inserter_tool_status = 2
- for _,entity in ipairs(inserter_tool_selected) do
- d = (entity.position.x - loc.x)*(entity.position.x - loc.x)+(entity.position.y - loc.y)*(entity.position.y - loc.y)
- if (d > reach) then
- player.print("Too far! "..math.sqrt(d))
- inserter_tool_status = 0
- break
- else
- entity.drop_position = loc
- entity.direction = entity.direction -- set direction to force update
- end
- end
- else if (inserter_tool_status == 2) then
- inserter_tool_status = 0
- for _,entity in ipairs(inserter_tool_selected) do
- d = (entity.position.x - loc.x)*(entity.position.x - loc.x)+(entity.position.y - loc.y)*(entity.position.y - loc.y)
- if (d > reach) then
- player.print("Too far! "..math.sqrt(d))
- break
- else
- entity.pickup_position = loc
- entity.direction = entity.direction -- set direction to force update
- end
- end
- end end end --if (inserter_tool_status == 0) then
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement