I'm trying to remove hidden entities when I mine a tile and can't figure it out, since the tile logic works a little different that the normal entity logic.
Here is my control. I'm not sure how to find the hidden entity when I mine the tile. Could someone please look at what I'm doing wrong here:
Remove Function
Code: Select all
---------------------------------------------
local function Tile_Remove(event)
local player = game.players[event.player_index]
local tile_name = event.item_stack.name
local tile = game.item_prototypes[tile_name].place_as_tile_result
--- Solar Map has been removed
if tile and player.mining_state.mining and tile_name == "bi-solar-mat" then
local tile_position = player.mining_state.position
writeDebug("Solar Mat Removed")
local robot = event.robot
local surface = player and player.surface or robot.surface
local radius = 0.15
local area = {{tile_position.x - radius, tile_position.y - radius}, {tile_position.x + radius, tile_position.y + radius}}
--- Remove the Hidden Pole
if surface.find_entity('bi_solar_pole', tile_position) then -- Does not find the hidden pole
--if surface.find_entities_filtered({area = area, name = "bi_solar_pole"}) then
for _, o in pairs(surface.find_entities_filtered({area = area, name = "bi_solar_pole"})) do o.destroy() end
for _, o in pairs(surface.find_entities_filtered({area = area, name = "bi_solar_pole"})) do o.die() end
writeDebug("bi_solar_pole Removed")
else
writeDebug("bi_solar_pole not found")
end
--- Remove the Hidden Pole
if surface.find_entities_filtered({area = area, name = "bi_solar-panel_for_Solar-Mat"}) then -- It says it finds the hidden panel, but you can actully type anything here and it will find it....
--if surface.find_entities_filtered({area = area, name = "BS!!!"}) then -- It said it found "BS"...
for _, o in pairs(surface.find_entities_filtered({area = area, name = "bi_solar-panel_for_Solar-Mat"})) do o.die() end
writeDebug("bi_solar-panel_for_Solar-Mat Removed")
else
writeDebug("bi_solar-panel_for_Solar-Mat not found")
end
end
end
Code: Select all
local function Player_Tile_Built(event)
local player = game.players[event.player_index]
local robot = event.robot
local surface = player and player.surface or robot.surface
local position = event.positions
for i, position in ipairs(position) do
local currentTilename = surface.get_tile(position.x,position.y).name
if currentTilename == "bi-solar-mat" then
writeDebug("Solar Mat has been built")
local force = event.force
local solar_mat = surface.get_tile(position.x,position.y)
local sm_pole_name = "bi_solar_pole"
local sm_panel_name = "bi_solar-panel_for_Solar-Mat"
local create_sm_pole = surface.create_entity({name = sm_pole_name, position = position, force = force})
local create_sm_panel = surface.create_entity({name = sm_panel_name, position = position, force = force})
--create_sm_pole.minable = false
--create_sm_pole.destructible = false
--create_sm_panel.minable = false
--create_sm_panel.destructible = false
end
end
end
local function Robot_Tile_Built(event)
local robot = event.robot
local surface = robot.surface
local position = event.positions
for i, position in ipairs(position) do
local currentTilename = surface.get_tile(position.x,position.y).name
if currentTilename == "bi-solar-mat" then
writeDebug("Solar Mat has been built")
local force = event.force
local solar_mat = surface.get_tile(position.x,position.y)
local sm_pole_name = "bi_solar_pole"
local sm_panel_name = "bi_solar-panel_for_Solar-Mat"
local create_sm_pole = surface.create_entity({name = sm_pole_name, position = position, force = force})
local create_sm_panel = surface.create_entity({name = sm_panel_name, position = position, force = force})
--create_sm_pole.minable = false
--create_sm_pole.destructible = false
--create_sm_panel.minable = false
--create_sm_panel.destructible = false
group_entities(cantor(position.x,position.y), { solar_mat, create_sm_pole, create_sm_panel })
end
end
end
Thanks.