Naev

Module commodity

Lua bindings to interact with commodities.

This will allow you to create and manipulate commodities in-game.

An example would be:

 c = commodity.get( "Food" ) -- Gets the commodity by name
 if c:price() > 500 then
    -- Do something with high price
 end
 

Functions

__eq (o1, o2) Checks to see if two commodities are the same.
get (s) Gets a commodity.
getStandard () Gets the list of standard commodities.
name (c) Gets the translated name of the commodity.
nameRaw (c) Gets the raw (untranslated) name of the commodity.
price (c) Gets the base price of an commodity.
priceAt (c, p) Gets the base price of an commodity on a certain spob.
priceAtTime (c, p, t) Gets the price of an commodity on a certain spob at a certain time.
icon (c) Gets the store icon of a commodity if it exists.
description (c) Gets the description of a commodity if it exists.
new (cargo, decription[, params=nil]) Creates a new temporary commodity.
illegalto (c, f) Makes a temporary commodity illegal to a faction.
illegality (Commodity) Gets the factions to which the commodity is illegal to.


Functions

__eq (o1, o2)
Checks to see if two commodities are the same.

Parameters:

  • o1 Commodity First commodity to compare.
  • o2 Commodity Second commodity to compare.

Returns:

    boolean true if both commodities are the same.

Usage:

    if o1 == o2 then -- Checks to see if commodity o1 and o2 are the same
    
get (s)
Gets a commodity.

Parameters:

  • s string Raw (untranslated) name of the commodity to get.

Returns:

    Commodity or nil The commodity matching name or nil if error.

Usage:

    s = commodity.get( "Food" ) -- Gets the food commodity
    
getStandard ()
Gets the list of standard commodities.

Returns:

    table A table containing commodity objects, namely those which are standard (buyable/sellable anywhere).
name (c)
Gets the translated name of the commodity.

This translated name should be used for display purposes (e.g. messages). It cannot be used as an identifier for the commodity; for that, use commodity.nameRaw() instead.

Parameters:

  • c Commodity Commodity to get the translated name of.

Returns:

    string The translated name of the commodity.

Usage:

    commodityname = c:name() -- Equivalent to `_(c:nameRaw())`
    
nameRaw (c)
Gets the raw (untranslated) name of the commodity.

This untranslated name should be used for identification purposes (e.g. can be passed to commodity.get()). It should not be used directly for display purposes without manually translating it with _().

Parameters:

  • c Commodity Commodity to get the raw name of.

Returns:

    string The raw name of the commodity.

Usage:

    commodityrawname = c:nameRaw()
    
price (c)
Gets the base price of an commodity.

Parameters:

  • c Commodity Commodity to get information of.

Returns:

    number The base price of the commodity.

Usage:

    print( c:price() ) -- Prints the base price of the commodity
    
priceAt (c, p)
Gets the base price of an commodity on a certain spob.

Parameters:

  • c Commodity Commodity to get information of.
  • p Spob Spob to get price at.

Returns:

    number The price of the commodity at the spob.

Usage:

    if c:priceAt( spob.get("Polaris Prime") ) > 100 then -- Checks price of a commodity at polaris prime
    
priceAtTime (c, p, t)
Gets the price of an commodity on a certain spob at a certain time.

Parameters:

  • c Commodity Commodity to get information of.
  • p Spob Spob to get price at.
  • t Time Time to get the price at.

Returns:

    number The price of the commodity at the spob.

Usage:

    if c:priceAtTime( spob.get("Polaris Prime"), time ) > 100 then -- Checks price of a commodity at polaris prime
    
icon (c)
Gets the store icon of a commodity if it exists.

Parameters:

  • c Commodity Commodity to get icon of.

Returns:

    Texture or nil Texture of the store icon if exists, otherwise nil.
description (c)
Gets the description of a commodity if it exists.

Parameters:

  • c Commodity Commodity to get decription of

Returns:

    string or nil Description of the commodity if exists, otherwise nil.
new (cargo, decription[, params=nil])
Creates a new temporary commodity. If a temporary commodity with the same name exists, that gets returned instead. "Temporary" is a relative term. The returned commodity object may be saved to a mission's/event's "mem" table, or used as a mission cargo (see misn.cargoAdd), and in those cases it will persist in saved games. Caution: Usage as a regular commodity in the player's cargo holds is not yet supported.

Parameters:

  • cargo string Name of the cargo to add. This must not match a cargo name defined in commodity.xml.
  • decription string Description of the cargo to add.
  • params table Table of named parameters. Currently supported is "gfx_space". (default nil)

Returns:

    Commodity The newly created commodity or an existing temporary commodity with the same name.
illegalto (c, f)
Makes a temporary commodity illegal to a faction.

Parameters:

  • c Commodity Temporary commodity to make illegal to factions.
  • f Faction or table Faction or table of factions to make illegal to.
illegality (Commodity)
Gets the factions to which the commodity is illegal to.

Parameters:

  • Commodity c to get illegality status of.

Returns:

    table Table of all the factions the commodity is illegal to.
generated by LDoc 1.4.6 Last updated 2022-05-26 02:36:04