Lua API

Item module

Functions for working with items.

Usage

local Item = ELONA.require("core.Item")

Functions

count () Returns the number of items on the ground.
has_enchantment (item, enchantment_id) Checks if an item has an enchantment.
itemname (item[, number][, use_article]) Returns the item's name.
create (position, id, number) Attempts to create an item of the given quantity at a position.
memory (type, id) Retrieves the player's memory of an item type.
trade_rate (item) Returns the trading rate of a cargo item.
find (item_id, location) Tries to find an item in the player's inventory, the ground, or both.
weight_string (weight) Returns the string representation of a weight value.

Functions

# count ()

Returns the number of items on the ground.

Returns:
  • (num) the item count
# has_enchantment (item, enchantment_id)

Checks if an item has an enchantment.

Parameters:
  • item : (LuaItem) (const) an item
  • enchantment_id : (num) the ID of the enchantment
Returns:
  • (bool) true if the item has the enchantment
# itemname (item[, number][, use_article])

Returns the item's name.

Parameters:
  • item : (LuaItem) (const) the item
  • number : (num) Overrides the item number (optional)
  • use_article : (bool) Prepend articles like "the" to the item name (optional)
Returns:
  • (string)
# create (position, id, number)

Attempts to create an item of the given quantity at a position.

Returns the item stack if it was created, nil otherwise.

Parameters:
  • position : (LuaPosition) (const) position to create the item at
  • id : (num) the item prototype ID
  • number : (num) the number of items to create
Returns:
Or
# memory (type, id)

Retrieves the player's memory of an item type.

Parameters:
  • type : (num)
  • id : (string)
# trade_rate (item)

Returns the trading rate of a cargo item.

Parameters: Returns:
  • (num)
# find (item_id, location)

Tries to find an item in the player's inventory, the ground, or both.

Parameters:
  • item_id : (string) The item ID to find.
  • location : (ItemFindLocation) Where to search for the item.
# weight_string (weight)

Returns the string representation of a weight value.

Parameters:
  • weight : (num) The weight value
Returns:
  • (string)