The trading component is the top-level interface exposed by the trading upgrade. It discovers nearby merchant offers and returns them as Trade userdata objects.
- Repository:
opencomputers - Lua component name:
trading - Typical hosts: robots, drones, and other agents with the trading upgrade installed
- Scans for merchants such as villagers within the configured trading radius.
- Builds one
Tradeuserdata object per merchant recipe. - Assigns a stable per-scan merchant sort id so multiple offers from the same merchant can be grouped together.
- Only merchants inside the configured OpenComputers trading range are considered.
- The scan area is centered on the host.
- Only entities implementing
IMerchantare returned.
- Syntax:
trading.getTrades() - Returns:
table - Purpose: Returns all merchant offers currently in range as
Tradeuserdata objects.
The returned table is sorted by merchant identity, then by recipe order for that merchant.
Each entry in the returned array is a Trade userdata object documented on the companion page:
local component = require("component")
local trading = component.trading
for index, offer in ipairs(trading.getTrades()) do
local first, second = offer.getInput()
local output = offer.getOutput()
print(index, offer.getMerchantId(), output and output.name)
endopencomputers-traderobotdrone