ff_i_item

Item functions.

Helpers for item identification, property manipulation, and tag-based item lookups.

int GetItemBaseAC(object oArmor)
Parameters:
  • oArmor – Armor item. Reads ACBONUS from parts_chest.2da via torso appearance.

Returns armor AC without bonuses.

int GetItemValue(object oItem)
Parameters:
  • oItem – An item.

Returns the true gold value of an item, temporarily clearing plot/cursed/stolen flags.

int GetLoreItemMaxValue(int nLore)
Parameters:
  • nLore – Lore value, must be positive

Get the maximum gold value possible for a successful lore check.

int GetItemRequiredLore(object oItem)
Parameters:
  • oItem – Item to check

Get the minimum lore value needed to identify object.

object CreateItemOnObjectEx(string sItemTemplate, object oTarget = OBJECT_SELF, int nStackSize = 1, string sNewTag = "")
Parameters:
  • sItemTemplate – Resref of the item blueprint.

  • oTarget – Object to place the item in. Defaults to OBJECT_SELF.

  • nStackSize – Stack size. Defaults to 1.

  • sNewTag – If non-empty, overrides the template tag. Defaults to “”.

Create an item with the template sItemTemplate in oTarget’s inventory. Sends a ON_ITEM_CREATED event Replaces the template resref if UTI override is active.

Create an item in oTarget’s inventory and fire ON_ITEM_CREATED.

int GetItemIsWeapon(object oItem)
Parameters:
  • oItem – Item to check

Checks if item is a weapon.

int GetItemDimensions(object oItem)
Parameters:
  • oItem – An item.

Return the inventory footprint of an item (InvSlotWidth * InvSlotHeight).

Source code

// @code

#include "ff_i_object"

// -----------------------------------------------------------------------------

//! @brief Returns armor AC without bonuses
//! @param oArmor Armor item. Reads ACBONUS from parts_chest.2da via torso appearance.
int GetItemBaseAC(object oArmor);
int GetItemBaseAC(object oArmor)
{
  // Get the appearance of the torso slot
  int nAppearance = GetItemAppearance(oArmor, ITEM_APPR_TYPE_ARMOR_MODEL, ITEM_APPR_ARMOR_MODEL_TORSO);

  // Look up in parts_chest.2da the relevant line, which links to the actual AC bonus of the armor
  return StringToInt(Get2DAString("parts_chest", "ACBONUS", nAppearance));
}


// -----------------------------------------------------------------------------

//! @brief Returns the true gold value of an item, temporarily clearing plot/cursed/stolen flags.
//! @param oItem An item.
int GetItemValue(object oItem);
int GetItemValue(object oItem)
{
  int nPlot = GetPlotFlag(oItem);
  int nStolen = GetStolenFlag(oItem);
  int nCursed = GetItemCursedFlag(oItem);
  int nIdentified = GetIdentified(oItem);

  SetPlotFlag(oItem, FALSE);
  SetIdentified(oItem, TRUE);
  SetStolenFlag(oItem, FALSE);
  SetItemCursedFlag(oItem, FALSE);

  int nValue = GetGoldPieceValue(oItem);

  SetPlotFlag(oItem, nPlot);
  SetStolenFlag(oItem, nStolen);
  SetItemCursedFlag(oItem, nCursed);
  SetIdentified(oItem, nIdentified);
  return nValue;
}


// -----------------------------------------------------------------------------

//! @brief Get the maximum gold value possible for a successful lore check
//! @param nLore Lore value, must be positive
int GetLoreItemMaxValue(int nLore);
int GetLoreItemMaxValue(int nLore)
{
  if (nLore <= 0)
    return 0;

  int nMaxValue = StringToInt(Get2DAString("SkillVsItemCost", "DeviceCostMax", nLore));
  if (nMaxValue == 0)
  {
    int nRows = Get2DARowCount("SkillVsItemCost");
    return GetLoreItemMaxValue(nRows - 1);
  }
  return nMaxValue;
}


// -----------------------------------------------------------------------------

//! @brief Get the minimum lore value needed to identify object
//! @param oItem Item to check
int GetItemRequiredLore(object oItem);
int GetItemRequiredLore(object oItem)
{
  int nValue = GetItemValue(oItem);
  int nLore = 1;

  if (nValue <= 5) // 5 is the smallest unit in the 2da
    return 0;

  while (nLore >= 1)
  {
    int nMinValue = GetLoreItemMaxValue(nLore - 1);
    int nMaxValue = GetLoreItemMaxValue(nLore);

    if (nValue > nMinValue && nValue <= nMaxValue)
      return nLore;
    nLore += 1;
  }
  return 0;
}


// -----------------------------------------------------------------------------

//! @brief Create an item with the template sItemTemplate in oTarget's inventory.
//! Sends a ON_ITEM_CREATED event
//! Replaces the template resref if UTI override is active.
//! @brief Create an item in oTarget's inventory and fire ON_ITEM_CREATED.
//! @param sItemTemplate Resref of the item blueprint.
//! @param oTarget Object to place the item in. Defaults to OBJECT_SELF.
//! @param nStackSize Stack size. Defaults to 1.
//! @param sNewTag If non-empty, overrides the template tag. Defaults to "".
object CreateItemOnObjectEx(string sItemTemplate, object oTarget=OBJECT_SELF, int nStackSize=1, string sNewTag="");
object CreateItemOnObjectEx(string sItemTemplate, object oTarget=OBJECT_SELF, int nStackSize=1, string sNewTag="")
{
  object oObject = CreateItemOnObject(sItemTemplate, oTarget, nStackSize, sNewTag);
  if (GetIsObjectValid(oObject))
    SendEvent(ON_ITEM_CREATED, oObject);

  return oObject;
}


// -----------------------------------------------------------------------------

//! @brief Checks if item is a weapon
//! @param oItem Item to check
int GetItemIsWeapon(object oItem);
int GetItemIsWeapon(object oItem)
{
  int nItemType = GetBaseItemType(oItem);
  switch (nItemType)
  {
    case BASE_ITEM_BASTARDSWORD:
    case BASE_ITEM_BATTLEAXE:
    case BASE_ITEM_CBLUDGWEAPON:
    case BASE_ITEM_CLUB:
    case BASE_ITEM_CPIERCWEAPON:
    case BASE_ITEM_CSLASHWEAPON:
    case BASE_ITEM_CSLSHPRCWEAP:
    case BASE_ITEM_DAGGER:
    case BASE_ITEM_DART:
    case BASE_ITEM_DIREMACE:
    case BASE_ITEM_DOUBLEAXE:
    case BASE_ITEM_DWARVENWARAXE:
    case BASE_ITEM_GREATAXE:
    case BASE_ITEM_GREATSWORD:
    case BASE_ITEM_HALBERD:
    case BASE_ITEM_HANDAXE:
    case BASE_ITEM_HEAVYCROSSBOW:
    case BASE_ITEM_HEAVYFLAIL:
    case BASE_ITEM_KAMA:
    case BASE_ITEM_KATANA:
    case BASE_ITEM_KUKRI:
    case BASE_ITEM_LIGHTCROSSBOW:
    case BASE_ITEM_LIGHTFLAIL:
    case BASE_ITEM_LIGHTHAMMER:
    case BASE_ITEM_LIGHTMACE:
    case BASE_ITEM_LONGBOW:
    case BASE_ITEM_LONGSWORD:
    case BASE_ITEM_MORNINGSTAR:
    case BASE_ITEM_QUARTERSTAFF:
    case BASE_ITEM_RAPIER:
    case BASE_ITEM_SCIMITAR:
    case BASE_ITEM_SCYTHE:
    case BASE_ITEM_SHORTBOW:
    case BASE_ITEM_SHORTSPEAR:
    case BASE_ITEM_SHORTSWORD:
    case BASE_ITEM_SHURIKEN:
    case BASE_ITEM_SICKLE:
    case BASE_ITEM_SLING:
    case BASE_ITEM_THROWINGAXE:
    case BASE_ITEM_TRIDENT:
    case BASE_ITEM_TWOBLADEDSWORD:
    case BASE_ITEM_WARHAMMER:
    case BASE_ITEM_WHIP:
      return TRUE;
  }
  return FALSE;
}



// -----------------------------------------------------------------------------

//! @brief Return the inventory footprint of an item (InvSlotWidth * InvSlotHeight).
//! @param oItem An item.
int GetItemDimensions(object oItem);
int GetItemDimensions(object oItem)
{
  int nWidth = StringToInt(Get2DAString("baseitems", "InvSlotWidth", GetBaseItemType(oItem)));
  int nHeight = StringToInt(Get2DAString("baseitems", "InvSlotHeight", GetBaseItemType(oItem)));
  return nWidth * nHeight;
}