ff_u_identify
Automatically identify on object acquire.
Variables
ENABLE__FF_U_OBJ_IDENTIFY: (string) (opt-out) Set to “N” on module to disable unit.
Source code
// @code
#include "ff_i_core"
const string ENABLE__FF_U_OBJ_IDENTIFY = "ENABLE__FF_U_OBJ_IDENTIFY";
// -----------------------------------------------------------------------------
void OnOpen();
void OnOpen()
{
object oObject = OBJECT_SELF;
if (!GetHasInventory(oObject))
return;
if (GetObjectType(oObject) != OBJECT_TYPE_PLACEABLE)
return;
object oPC = GetLastOpenedBy(oObject);
if (!GetIsPC(oPC))
return;
int nLore = GetSkillRank(SKILL_LORE, oPC);
object oItem = GetFirstItemInInventory(oObject);
while (GetIsObjectValid(oItem))
{
if (nLore >= GetItemRequiredLore(oItem))
SetIdentified(oItem, TRUE);
oItem = GetNextItemInInventory(oObject);
}
}
// -----------------------------------------------------------------------------
void OnAcquire();
void OnAcquire()
{
object oItem = GetModuleItemAcquired();
object oPC = GetModuleItemAcquiredBy();
if (!GetIsPC(oPC))
return;
if (GetIdentified(oItem))
return;
int nLore = GetItemRequiredLore(oItem);
if (nLore <= 0)
{
SetIdentified(oItem, TRUE);
return;
}
int nSkill = GetSkillRank(SKILL_LORE, oPC);
if (nSkill >= nLore)
SetIdentified(oItem, TRUE);
}
// -----------------------------------------------------------------------------
//! @brief Return TRUE if oObject is a placeable with inventory.
//! @param oObject An object.
int IsEligible(object oObject);
int IsEligible(object oObject)
{
if (!GetHasInventory(oObject))
return FALSE;
if (GetObjectType(oObject) != OBJECT_TYPE_PLACEABLE)
return FALSE;
return TRUE;
}
// -----------------------------------------------------------------------------
void main()
{
object oModule = GetModule();
if (!GetModuleFlag(ENABLE__FF_U_OBJ_IDENTIFY, TRUE))
return;
string sEvent = GetCurrentEvent();
if (sEvent == ON_REGISTER)
{
SubscribeToEvent(ON_DEFAULT_ITEM_ACQUIRE, __FILE__);
SubscribeToEvent(ON_OBJECT_CREATED, __FILE__);
}
else if (sEvent == ON_OBJECT_CREATED && IsEligible(OBJECT_SELF))
SubscribeToEvent(ON_DEFAULT_OBJECT_OPENED, __FILE__, OBJECT_SELF);
else if (sEvent == ON_DEFAULT_ITEM_ACQUIRE)
OnAcquire();
else if (sEvent == ON_DEFAULT_OBJECT_OPENED)
OnOpen();
}