Called from the on_player_mined_entity event,
Code: Select all
function unregister_hab (event)
	for i in pairs (storage.hab_index) do
		if storage.hab_index [i] == event.entity.unit_number then
		
			table.remove(storage.hab_index,i)--removing the primary entity from the index table
			local energy_control = game.get_entity_by_unit_number(storage.hab_energy_control[i]) -- getting the second by unit number
			if energy_control.valid then
				energy_control.destroy()
			end
			
			table.remove(storage.hab_energy_control,i)--removing the second entity from the index table
		end	
	end
end
