Omega Crafter

Omega Crafter

Not enough ratings
Efficient Tree Farm Automation
By Kinor
This is an advanced script to take your Grammi's tree farming to the next level. It emphasizes prioritized task handling, prevention of ground drops, and effective multi-Grammi cooperation. Achieve truly smooth and uninterrupted forestry automation.
   
Award
Favorite
Favorited
Unfavorite
The Core Design Philosophy & Comparison to Default
This Grammi Script operates on two fundamental principles: Precise Task Prioritization and Real-time Re-evaluation.


Comparison to Game's Default Forestry Program:
The game's default forestry program typically uses only one box for wood storage, which often proves insufficient. Crucially, it continues cutting trees even when that box is full, leading to dropped wood and seeds accumulating on the ground, creating clutter and inefficiency.

This custom Grammi Script directly addresses these issues:
  • Smart Storage Management: It utilizes multiple dedicated storage containers for different items (e.g., a TreeSeedBox for seeds and several WoodBoxes for wood).
  • Preventing Clutter: Grammi will always check the available wood storage capacity before cutting down a tree. If wood storage is full, Grammi will not cut more trees, preventing unsightly and inefficient ground clutter.
  • Prioritized Collection: The script prioritizes picking up dropped items (like wood and seeds) and immediately storing them, ensuring resources are moved efficiently into your inventory system.
  • Dynamic Adaptation: By re-evaluating tasks after most actions, Grammi quickly adapts to changes, like an empty storage box becoming available or new items dropping.
The Automated Forestry Script (Phases 1-3)
This section details the sequential phases of the Grammi's script. Each phase contributes to an efficient and responsive forestry operation.

Phase 1: Planting Seeds
This is the absolute highest priority task. Grammi will first check if there's an available spot in your TreeFarm_001 to plant a new tree. This is prioritized because tree seeds take a long time to grow (480 seconds), so planting them quickly allows Grammi to move on to other tasks while the seeds grow automatically in the background.

Comment: 1. Plant Seed if can plant to TreeFarm_001 then // Check for tree seed source and attempt to plant if having Tree Seed then // Plant seed currently in hand plant seed in TreeFarm_001 restart process else // If holding other items, put them down first if having an item then put item on the ground end if // If tree seeds exist in around, pick one up if exists Tree Seed in around then search Tree Seed and pick up one restart process // Otherwise, if tree seeds are in the Tree Seed Box, pick one up else if in TreeSeedBox count number of Tree Seed > 0 then pick up item from TreeSeedBox restart process end if end if end if


Explanation:
  • Prioritize Planting: If a planting spot is free, Grammi's immediate goal is to plant a seed. It first checks if it already holds one, then looks on the ground, and finally in the TreeSeedBox.
  • Hand Clearing: If Grammi holds a non-seed item while a planting spot is available, it will drop that item to free its hand before trying to acquire a seed.
  • Immediate Re-evaluation: After successfully planting a seed, or successfully picking up a seed from the ground or the box, Grammi immediately triggers restart process.

Phase 2: Item Storage
This phase is crucial for managing Grammi's inventory. It will execute directly after Phase 1, or if Grammi has items to store from other phases.

Comment: 2. Storage Comment: Seed Container if having Tree Seed then try put item in TreeSeedBox if it fails then if having an item then put item on the ground end if print log Seed Container is Full end if // End of try/fail block end if Comment: Wood Containers if having Wood then // Update WoodStorageStatus and attempt to store wood in boxes 4 down to 1 to WoodStorageStatus write string in read string from WoodStorageStatus replace at the 3 index with 0 // For WoodBox_04 if WoodBox_04 has capacity for Wood then try put item in WoodBox_04 if it fails then restart process end if // End of try/fail block end if to WoodStorageStatus write string in read string from WoodStorageStatus replace at the 2 index with 0 // For WoodBox_03 if WoodBox_03 has capacity for Wood then try put item in WoodBox_03 if it fails then restart process end if end if to WoodStorageStatus write string in read string from WoodStorageStatus replace at the 1 index with 0 // For WoodBox_02 if WoodBox_02 has capacity for Wood then try put item in WoodBox_02 if it fails then restart process end if end if to WoodStorageStatus write string in read string from WoodStorageStatus replace at the 0 index with 0 // For WoodBox_01 if WoodBox_01 has capacity for Wood then try put item in WoodBox_01 if it fails then restart process end if else // All Wood Containers are Full to WoodStorageStatus write string in read string from WoodStorageStatus replace at the 0 index with 1 if having an item then put item on the ground end if print log Wood Containers are Full end if end if



Explanation:
  • Tree Seed Storage: If Grammi holds a Tree Seed, it will attempt to store it. If the box is full, Grammi will drop the seed and log a message.
  • Wood Storage (Reversed Order): If Grammi holds Wood, it initiates a sequential storage attempt, starting from WoodBox_04 and working its way down to WoodBox_01.
    • Before each try put item, the corresponding character in your WoodStorageStatus string board is set to '0' (indicating not full).
    • The try block ensures robust handling in multi-Grammi setups. If a storage attempt fails due to another Grammi filling the box, restart process ensures immediate re-evaluation.
    • If an item is successfully placed, Grammi continues to check the next box until all held wood is stored or all boxes are full.
    • If all wood containers are full after attempting to store, Grammi updates WoodStorageStatus, drops any remaining wood, and logs a message.

Phase 3: Picking Up Wood
If Grammi isn't handling planting or actively storing items, its next priority is to clear any dropped wood from the ground.

Comment: 3. Pick Wood if exists Wood in around then // Clear hand before picking up wood if having an item then put item on the ground end if search Wood and pick up one restart process end if



Explanation:
  • Clear Hand: Before attempting to pick up wood, Grammi ensures its hand is empty by dropping any currently held item.
  • Pick Up & Re-evaluate: Grammi then searches for and picks up one piece of wood. Upon successful pickup, it immediately triggers restart process.
The Automated Forestry Script (Phases 4-6)
Phase 4: Cutting Trees
Only when wood storage is not completely full will Grammi proceed to cut down trees. This prevents over-accumulation of wood that cannot be stored.

Comment: 4. Cut Tree if not read string from WoodStorageStatus == 1111 then // Check if wood storage is NOT full if can cut tree in TreeFarm_001 then // Clear hand before cutting the tree if having an item then put item on the ground end if cut tree in TreeFarm_001 wait 1 sec restart process // Re-evaluate all tasks after cutting end if end if



Explanation:
  • Storage Check: Grammi first checks if all four wood containers are marked as full ("1111" on WoodStorageStatus). It will only cut trees if there's still space to store the new wood.
  • Can Cut Check: If storage capacity allows, Grammi then checks if there's a tree ready to be cut in TreeFarm_001.
  • Clear Hand & Cut: Before cutting, Grammi drops any item it's holding to ensure the cut action isn't hindered. It then proceeds to cut the tree.
  • Wait & Re-evaluate: After cutting, Grammi waits for 1 second (to allow items to drop onto the ground), then immediately triggers restart process.

Phase 5: Picking Up Seeds
This phase handles any excess Tree Seeds that might be on the ground, but only if there's space for them in the Seed Box.

Comment: 5. Pick Seed if exists Tree Seed in around and TreeSeedBox has capacity for Tree Seed then // Clear hand before picking up seeds if having an item then put item on the ground end if search Tree Seed and pick up one restart process end if



Explanation:
  • Conditional Pickup: Grammi will only look for seeds if there are seeds on the ground AND if the TreeSeedBox has available capacity for them.
  • Clear Hand & Pick Up: Grammi drops any held item first to clear its hand. It then searches for and picks up one Tree Seed.
  • Re-evaluate: Upon successful pickup, Grammi immediately triggers restart process.

Phase 6: Idle State
This is the lowest priority state. Grammi enters this state only if all higher-priority tasks are either complete or cannot be performed.

Comment: 6. Idle // Move to a designated idle point move to TreeFarmTorch



Explanation:
  • Grammi will move to your designated TreeFarmTorch location. This acts as a central waiting point, strategically positioning Grammi for quick access to various parts of your farm when new tasks arise.
  • This also prevents issues where wood might drop too far from boxes to be searched by Grammi, as the central search range can cover most of the forest area. Of course, if the forest area is too large, the problem might still occur.
  • After moving, Grammi begins a new round of priority checks from the very top.
How to Import This Script
To use this highly efficient Grammi script in your game, you will need to import the provided Export Data string and set up your environment correctly.

Required Environmental Setup:
Before importing, please ensure you have the following entities built and configured in your world:
  • Tree Farm Field: Designate a planting area. For example, a 5x5 field. Name it TreeFarm_001.
  • Seed Container: A container (e.g., a chest or storage box) where Grammi will store/retrieve Tree Seeds. Name it TreeSeedBox.
  • Wood Containers: Four separate containers for storing Wood. You should name them WoodBox_01, WoodBox_02, WoodBox_03, and WoodBox_04. The script prioritizes filling them from _highest number_ (04) down to _lowest number_ (01).
  • String Board: A String Board entity to track the fill status of your wood containers. Name it WoodStorageStatus. It is CRUCIAL that you initialize this String Board with a 4-digit binary string, e.g., "0000", immediately after placing it. Without an initial 4-digit string, the 'replace at index' operations will cause errors. The script uses '0' for a box with capacity and '1' for a full box. So, '0000' means all boxes have capacity, and '1111' means all boxes are full.
  • Location Marker (Torch): A Location Marker (e.g., a Torch placed on the ground) to serve as Grammi's idle point. Name it TreeFarmTorch.

Import Steps:
  • In-game, open your Grammi's programming interface.
  • Look for "Program List (City Grammi)" in the top-left area. Select "Custom".
  • Next to the "Custom" selection, you will see a button (often resembling [ ]<- or a load icon). This is the Import button.
  • Click the Import button. A new window will pop up.
  • Paste the complete Export Data content (including the curly braces {}) into the designated text field within this new window.
  • Click the "OK" button to confirm.
  • The imported script should now appear in your "Custom" program list on the left side.


Export Data Link:
You can access the full script's Export Data from the following Google Doc:
Forestry Overseer AI Script (Full Export Data)[docs.google.com]