Skip to main content

Incrementalproducer

Overview

This component enables an entity to produce items or resources incrementally over time. It supports dynamic configuration of production rate, maximum capacity, and custom production callbacks, making it suitable for entities like farms, forges, or automated generators that produce items in batches with delays between each unit.

Dependencies & Tags

None identified

Properties

PropertyTypeDefault ValueDescription
instEntitynilReference to the entity the component is attached to.
producefnfunctionnilCallback function invoked when an item is produced. Receives inst as argument.
countfnfunctionnilCallback function that returns the current count of produced items/resources.
maxcountnumber0Maximum number of items the entity can hold or produce at once. Dynamically updated via maxcountfn.
maxcountfnfunctionnilOptional callback to dynamically compute maxcount. Receives inst as argument.
incrementnumber1Number of items produced per production cycle. Can be overridden by incrementfn.
incrementfnfunctionnilOptional callback to dynamically compute increment. Receives inst as argument.
incrementdelaynumber1Minimum time (in seconds) between consecutive production events.
toproducenumber0Number of items remaining to be produced in the current batch.
lastproductionnumber0Timestamp (via GetTime()) of the last production event.

Main Functions

CanProduce()

  • Description: Evaluates whether production can occur right now based on time delay and current/max counts. Updates dynamic values (maxcount, increment, toproduce) if custom functions are defined. Sets toproduce to the number of items that can be produced in the next batch (capped by remaining space).
  • Parameters: None.

TryProduce()

  • Description: Attempts to produce one unit (or batch) if CanProduce() returns true. Calls DoProduce() internally if production is possible.
  • Parameters: None.

DoProduce()

  • Description: Executes the actual production by invoking producefn (if set), decrements toproduce, and updates lastproduction to the current time.
  • Parameters: None.

GetDebugString()

  • Description: Returns a formatted string for debugging purposes, showing current count, pending production, max count, and time remaining until next production.
  • Parameters: None.

Events & Listeners

None identified