Inventory module

What Lara is carrying, and what goes into it.

The module's functions ask about the inventory she holds now, so trx.inventory.count(object) asks about her. Any level's is a trx.inventory.Inventory, reached through trx.game.Level.inventory, which is what it will hand her when she arrives there rather than what she has this second.

Every function takes either the pickup lying in the world or the inventory icon it goes into. The engine maps one to the other, so a script names whichever it has.

Indexing

Indexing the module reaches an entry of Lara's inventory, and #trx.inventory is how many kinds of thing she carries. Entries are keyed by the order they are drawn in, and are built one at a time as they are asked for. pairs() walks them.

Example:

for _, entry in pairs(trx.inventory) do
  trx.log.info(("%d x %s"):format(entry.count, trx.catalog.objects[entry.object]))
end

Structures

  • trx.inventory.EntryNum

    Where an entry sits in the ring, in the order they are drawn. Counted from 1.

  • trx.inventory.Entry

    One kind of thing an inventory holds, and how many of it.

    An entry stands for the icon rather than for where it sits, so it goes on naming the same thing as what is drawn around it changes. A box of ammunition is an entry like any other, counting what its rounds come to.

    Handles are live references: if the underlying object is destroyed, using the handle raises an error rather than silently reading an unrelated one.

    Properties:

    • count: integer. How many of it there are. Writing 0 takes it away.
    • object: trx.catalog.objects. The inventory icon this entry is drawn as. (read-only)
  • trx.inventory.Inventory

    An inventory: what is in it, and how much ammunition goes with it.

    trx.inventory is the one Lara is carrying. A level's, reached as trx.game.Level.inventory, is what she will arrive there with, and holds only what travels between levels - a key or a puzzle piece belongs to the level it was found in.

    Giving something to Lara's does what walking over it would: a weapon arrives with its rounds, her meshes change, and the level's own guns turn into ammunition for it. Giving it to a level's only says what she will arrive carrying.

    Handles are live references: if the underlying object is destroyed, using the handle raises an error rather than silently reading an unrelated one.

    Methods:

    • inventory:ammo_kind(weapon)
      The kind of ammunition the weapon fires, one of trx.weapons.Weapon.ammo_objects. A weapon fires its first kind until another is set.

      Parameters:

      • weapon (trx.catalog.weapons). Which weapon. UNKNOWN and UNARMED raise, and so does anything outside the table; FLARE and SKIDOO are taken, being held the way a weapon is.

      Returns: trx.catalog.objects or nil. The kind, or nil where the weapon takes no ammunition.

    • inventory:can_add(object_id)
      Whether give would do anything in the level being played. The level has to carry the inventory model, which is not the same as the pickup being in it: a level with no shotgun lying about still draws one in the ring, which is what lets a cheat hand one over.

      This asks about the level being played whichever inventory it is called on.

      Parameters:

      Returns: boolean. True where the level carries the model to draw it with.

    • inventory:count(object_id)
      How many of something is in it. A box of ammunition counts what its rounds come to.

      Parameters:

      Returns: integer. 0 where there is none.

    • inventory:entry(object_id)
      The entry something is drawn as, or nil where there is none of it.

      Several pickups share one entry - the scion whether or not she holds it, a waterskin at each fill level - so this answers with the one thing they are drawn as.

      Parameters:

      Returns: trx.inventory.Entry or nil. The entry, or nil where there is none of it.

    • inventory:entry_at(entry_num)
      The entry at a position in the order they are drawn, or nil past the end.

      Parameters:

      Returns: trx.inventory.Entry or nil. The entry, or nil past the last one.

    • inventory:entry_count()
      How many entries there are. #trx.inventory is the same number for the one Lara carries.

      Returns: integer. Kinds of thing, not counts.

    • inventory:give(object_id, [count])
      Puts a pickup in. Lara's inventory takes it as walking over it would, so a weapon arrives with the rounds a pickup carries and a flare box with its flares; a level's simply gains it.

      Parameters:

      • object_id (trx.catalog.objects). The pickup, or the inventory icon it goes into.
      • count (integer, optional). How many. Defaults to 1; below 1 raises.

      Returns: integer. How many went in. 0 from Lara's means the level does not carry the icon for it - see can_add.

    • inventory:has(object_id)
      Whether there is any of it at all.

      Parameters:

      Returns: boolean. True for any count above 0.

    • inventory:has_attachment(weapon)
      Whether the weapon carries its attachment, such as the laser sight on the TR4 revolver. trx.weapons.Weapon.attachment says what the weapon takes.

      Parameters:

      • weapon (trx.catalog.weapons). Which weapon. UNKNOWN and UNARMED raise, and so does anything outside the table; FLARE and SKIDOO are taken, being held the way a weapon is.

      Returns: boolean. True where the weapon carries its attachment.

    • inventory:has_weapon(weapon)
      Whether the weapon itself is in it, which is not the same as having ammunition for it.

      Parameters:

      • weapon (trx.catalog.weapons). Which weapon. UNKNOWN and UNARMED raise, and so does anything outside the table; FLARE and SKIDOO are taken, being held the way a weapon is.

      Returns: boolean. True where the weapon itself is in it.

    • inventory:set_ammo_kind(weapon, kind)
      Sets the kind of ammunition the weapon fires. The weapon keeps the kind when it runs out of it.

      Parameters:

    • inventory:set_count(object_id, count)
      Sets how many of it there are. Zero takes it away.

      Parameters:

      • object_id (trx.catalog.objects). The pickup, or the inventory icon it goes into.
      • count (integer). How many. Below 0 raises.
    • inventory:set_shots(weapon, count, [kind])
      Sets how many shots there are for it.

      Parameters:

      • weapon (trx.catalog.weapons). Which weapon. UNKNOWN and UNARMED raise, and so does anything outside the table; FLARE and SKIDOO are taken, being held the way a weapon is.
      • count (integer). Shots. Below 0 raises.
      • kind (trx.catalog.objects, optional). The kind of ammunition, one of trx.weapons.Weapon.ammo_objects. Defaults to the kind the weapon fires; any other object raises.
    • inventory:shots(weapon, [kind])
      How many shots there are for the weapon. A shot is one pull of the trigger, which is what the counter shows the player; the shotgun spends six rounds on each.

      Parameters:

      Returns: integer. 0 where she carries no ammunition for it.

    • inventory:take(object_id, [count])
      Takes things back out, stopping when there are none left.

      This is not the exact opposite of give: a box of ammunition is rounds rather than an entry of its own, so taking one back takes the rounds a box is worth.

      Parameters:

      • object_id (trx.catalog.objects). The pickup, or the inventory icon it goes into.
      • count (integer, optional). How many. Defaults to 1; below 1 raises.

      Returns: integer. How many came out.

  • trx.inventory.Actions

    What the inventory ring offers for an entry.

    Properties:

    • combine: boolean. Whether Lara carries something it combines with, so that choosing it combines rather than uses it.
    • examine: boolean. Whether it can be examined, which the player's settings and its description decide.
    • separate: boolean. Whether it is a weapon that carries its attachment, which trx.inventory.separate takes off.
    • use: boolean. Whether choosing it uses it.

Functions

  • trx.inventory.count(object_id)
    Asks trx.inventory.Inventory:count of what Lara carries.

    Parameters:

    Returns: integer. 0 where there is none.

  • trx.inventory.set_count(object_id, count)
    Asks trx.inventory.Inventory:set_count of what Lara carries.

    Parameters:

    • object_id (trx.catalog.objects). The pickup, or the inventory icon it goes into.
    • count (integer). How many. Below 0 raises.
  • trx.inventory.has(object_id)
    Asks trx.inventory.Inventory:has of what Lara carries.

    Parameters:

    Returns: boolean. True for any count above 0.

  • trx.inventory.give(object_id, [count])
    Asks trx.inventory.Inventory:give of what Lara carries.

    Parameters:

    • object_id (trx.catalog.objects). The pickup, or the inventory icon it goes into.
    • count (integer, optional). How many. Defaults to 1; below 1 raises.

    Returns: integer. How many went in. 0 from Lara's means the level does not carry the icon for it - see trx.inventory.Inventory:can_add.

    Example:

    trx.inventory.give(trx.catalog.objects.uzi_item, 2)
    
  • trx.inventory.take(object_id, [count])
    Asks trx.inventory.Inventory:take of what Lara carries.

    Parameters:

    • object_id (trx.catalog.objects). The pickup, or the inventory icon it goes into.
    • count (integer, optional). How many. Defaults to 1; below 1 raises.

    Returns: integer. How many came out.

  • trx.inventory.shots(weapon, [kind])
    Asks trx.inventory.Inventory:shots of what Lara carries.

    Parameters:

    Returns: integer. 0 where she carries no ammunition for it.

  • trx.inventory.ammo_kind(weapon)
    Asks trx.inventory.Inventory:ammo_kind of what Lara carries.

    Parameters:

    • weapon (trx.catalog.weapons). Which weapon. UNKNOWN and UNARMED raise, and so does anything outside the table; FLARE and SKIDOO are taken, being held the way a weapon is.

    Returns: trx.catalog.objects or nil. The kind, or nil where the weapon takes no ammunition.

  • trx.inventory.set_ammo_kind(weapon, kind)
    Asks trx.inventory.Inventory:set_ammo_kind of what Lara carries.

    Parameters:

    Example:

    trx.inventory.set_ammo_kind(
      trx.catalog.weapons.SHOTGUN,
      trx.catalog.objects.SHOTGUN_AMMO_2_ITEM
    )
    
  • trx.inventory.set_shots(weapon, count, [kind])
    Asks trx.inventory.Inventory:set_shots of what Lara carries.

    Parameters:

    • weapon (trx.catalog.weapons). Which weapon. UNKNOWN and UNARMED raise, and so does anything outside the table; FLARE and SKIDOO are taken, being held the way a weapon is.
    • count (integer). Shots. Below 0 raises.
    • kind (trx.catalog.objects, optional). The kind of ammunition, one of trx.weapons.Weapon.ammo_objects. Defaults to the kind the weapon fires; any other object raises.

    Example:

    trx.inventory.set_shots(trx.catalog.weapons.UZIS, 2000)
    
  • trx.inventory.has_weapon(weapon)
    Asks trx.inventory.Inventory:has_weapon of what Lara carries.

    Parameters:

    • weapon (trx.catalog.weapons). Which weapon. UNKNOWN and UNARMED raise, and so does anything outside the table; FLARE and SKIDOO are taken, being held the way a weapon is.

    Returns: boolean. True where the weapon itself is in it.

  • trx.inventory.has_attachment(weapon)
    Asks trx.inventory.Inventory:has_attachment of what Lara carries.

    Parameters:

    • weapon (trx.catalog.weapons). Which weapon. UNKNOWN and UNARMED raise, and so does anything outside the table; FLARE and SKIDOO are taken, being held the way a weapon is.

    Returns: boolean. True where the weapon carries its attachment.

  • trx.inventory.entry(object_id)
    Asks trx.inventory.Inventory:entry of what Lara carries.

    Parameters:

    Returns: trx.inventory.Entry or nil. The entry, or nil where there is none of it.

  • trx.inventory.entry_at(entry_num)
    Asks trx.inventory.Inventory:entry_at of what Lara carries.

    Parameters:

    Returns: trx.inventory.Entry or nil. The entry, or nil past the last one.

  • trx.inventory.entry_count()
    Asks trx.inventory.Inventory:entry_count of what Lara carries.

    Returns: integer. Kinds of thing, not counts.

  • trx.inventory.can_add(object_id)
    Asks trx.inventory.Inventory:can_add of what Lara carries.

    Parameters:

    Returns: boolean. True where the level carries the model to draw it with.

  • trx.inventory.combine_partners(object_id)
    What an inventory icon combines with, among the things Lara carries.

    Parameters:

    Returns: a list of trx.catalog.objects. The icons of what it combines with.

    Example:

    for _, partner in ipairs(trx.inventory.combine_partners(item)) do
      trx.log.info(trx.catalog.objects[partner])
    end
    
  • trx.inventory.combine(object_id, partner_id)
    Combines two things Lara carries into what they make, taking one of each, as combining them in the inventory ring does.

    Parameters:

    Returns: trx.catalog.objects or nil. What they made, or nil, changing nothing, where the two do not combine or Lara lacks either.

    Example:

    local made = trx.inventory.combine(item, partner)
    
  • trx.inventory.separate(object_id)
    Takes the attachment off a weapon Lara carries, such as the laser sight off the TR4 revolver, and gives it back to her.

    Parameters:

    Returns: trx.catalog.objects or nil. The icon the attachment went into, or nil, changing nothing, where the weapon carries none.

    Example:

    trx.inventory.separate(trx.catalog.objects.REVOLVER_OPTION)
    
  • trx.inventory.icon_of(object)
    Returns the inventory icon for a pickup, whether or not Lara has one.

    Parameters:

    Returns: trx.catalog.objects or nil. The icon's object id, or nil for a pickup that has none.

  • trx.inventory.use(object_id)
    Uses something Lara carries, as choosing it in the inventory ring does: she draws a weapon, takes a medipack, lights a flare, or uses a key on what she stands at. Something that has no use does nothing.

    Parameters:

    Example:

    trx.inventory.use(trx.catalog.objects.SMALL_MEDIPACK_OPTION)
    
  • trx.inventory.actions(object_id)
    What the inventory ring offers for an entry: using, examining, combining or separating it.

    Parameters:

    Returns: trx.inventory.Actions. What it offers.

    Example:

    if trx.inventory.actions(object).examine then
      trx.log.info("it can be examined")
    end