ff_u_plc_ident
Automatically identify items with the Lore skill.
Items are automatically identified:
when a PC or DM acquires an item,
when a PC or DM opens a placeable with an inventory: every item inside is tried.
An item is identified when its required Lore (see GetItemRequiredLore())
is 0, or is less than or equal to the character’s Lore skill rank plus its level.
Variables
ENABLE__FF_U_PLC_IDENT: (string) (opt-out) Set to "N" on module to disable the unit.
Source code
// @code
#include "ff_i_core"
const string ENABLE__FF_U_PLC_IDENT = "ENABLE__FF_U_PLC_IDENT";
// -----------------------------------------------------------------------------
//! @brief Return the identification skill of oPC: Lore skill rank plus PC level.
//! @param oPC A player character.
int GetIdentifySkill(object oPC);
int GetIdentifySkill(object oPC)
{
return GetSkillRank(SKILL_LORE, oPC) + GetPCLevel(oPC);
}
// -----------------------------------------------------------------------------
//! @brief Identify oItem for oPC if nSkill is high enough.
//! @param oPC The player character.
//! @param oItem An item.
//! @param nSkill Identification skill of oPC, see GetIdentifySkill().
//! @return TRUE if the item was identified by this call.
int TryIdentify(object oPC, object oItem, int nSkill);
int TryIdentify(object oPC, object oItem, int nSkill)
{
if (GetIdentified(oItem))
return FALSE;
if (GetBaseItemType(oItem) == BASE_ITEM_GOLD)
return FALSE;
// A required lore of 0 is always identified
int nRequired = GetItemRequiredLore(oItem);
if (nRequired <= 0)
{ }
else if (nSkill < nRequired)
return FALSE;
SetIdentified(oItem, TRUE);
SendMessage(oPC, GetName(oItem) + " has been identified");
return TRUE;
}
// -----------------------------------------------------------------------------
//! @brief Try to identify the item acquired by a PC or DM.
void OnAcquire();
void OnAcquire()
{
object oPC = GetModuleItemAcquiredBy();
if (!GetIsPCorDM(oPC))
return;
TryIdentify(oPC, GetModuleItemAcquired(), GetIdentifySkill(oPC));
}
// -----------------------------------------------------------------------------
//! @brief Try to identify every item of the placeable opened by a PC or DM.
//! @param oPlaceable The opened placeable.
void OnOpen(object oPlaceable);
void OnOpen(object oPlaceable)
{
if (!GetHasInventory(oPlaceable))
return;
object oPC = GetLastOpenedBy(oPlaceable);
if (!GetIsPCorDM(oPC))
return;
int nSkill = GetIdentifySkill(oPC);
object oItem = GetFirstItemInInventory(oPlaceable);
while (GetIsObjectValid(oItem))
{
TryIdentify(oPC, oItem, nSkill);
oItem = GetNextItemInInventory(oPlaceable);
}
}
// -----------------------------------------------------------------------------
void main()
{
string sEvent = NWNX_Events_GetCurrentEvent();
if (sEvent == ON_REGISTER)
{
if (!GetModuleFlag(ENABLE__FF_U_PLC_IDENT, TRUE))
return;
SubscribeToEvent(ON_DEFAULT_PLACEABLE_OPEN, __FILE__);
SubscribeToEvent(ON_DELAYED_REGISTER, __FILE__);
}
// Avoid ON_DEFAULT_ITEM_ACQUIRE events during startup
else if (sEvent == ON_DELAYED_REGISTER)
SubscribeToEvent(ON_DEFAULT_ITEM_ACQUIRE, __FILE__);
else if (sEvent == ON_DEFAULT_ITEM_ACQUIRE)
OnAcquire();
else if (sEvent == ON_DEFAULT_PLACEABLE_OPEN)
OnOpen(OBJECT_SELF);
}