Artifact Deconstuctor


Alien artifacts are really irritating to pickup. This mod automatically marks the artifacts to be picked up by construction bots.

Utilities
7 years ago
0.14
7

g Why not only mark for deconstruction in the roboport range?

7 years ago

Here is an example from something I started the same day you posted your mod :) This will mark all items-on-ground for deconstruction in the construction zone of the player's roboport, with available robots

local function are_bots_ready(character)
return (character.logistic_cell and character.logistic_cell.mobile
and character.logistic_cell.stationed_construction_robot_count > 0) or false
end

local function get_build_area(pos, rad)
return {top_left={x=pos.x-rad, y=pos.y-rad}, bottom_right={x=pos.x+rad, y=pos.y+rad}}
end

local function gobble_items_on_ground(player)
local rad = player.character.logistic_cell.construction_radius
local area = get_build_area(player.position, rad)
if not player.surface.find_nearest_enemy{position=player.position ,max_distance=rad+20,force=player.force} then
for _, item in pairs(player.surface.find_entities_filtered{area=area, name="item-on-ground"}) do
if not item.to_be_deconstructed(player.force) then
item.order_deconstruction(player.force)
end
end
end
end

The on tick handler is every 2.5 seconds loop through players and executes

if are_bots_ready(player.character) then
gobble_items_on_ground(player)
end

7 years ago

Also to speed up things allPlayers already contains the "player" not allPlayers
All of your game.players===== can be replaced with allPlayers.code Doing this will use your local copy of the player versus accessing the global game table.

Also you can eek out more speed in multiplayer by just running the code on connected, non-afk, players with characters

local function is_player_ready(player)
return (player.connected and player.afk_time < TICK_MOD * 1.5 and player.character) or false
end

New response