ff_u_itm_inspect
Debug inspection tool.
Debug-only unit: it does nothing unless debug mode is on (see
ff_i_debug).
When a player enters, an inspection tool (resref and tag itm_inspect) is
given to them one second later if they do not have one already.
Activating the tool on a target identifies it, along with its inventory, and prints to the server console its name, object type, tag, resref, hit points and gold value (when not 0), hardness (doors and placeables) and local variables.
Variables
NWN_DEBUG: (string) Environment variable. The unit is enabled only when it is set to a true value.
Source code
// @code
#include "ff_i_core"
const string INSPECT_TAG = "itm_inspect"; //!< Tag of the inspection tool.
const string INSPECT_RESREF = "itm_inspect"; //!< Resref of the inspection tool.
// -----------------------------------------------------------------------------
//! @brief Void wrapper of CreateItemOnObject, for use with DelayCommand.
//! @param sItemTemplate Resref of the item to create.
//! @param oTarget Object receiving the item. Defaults to OBJECT_SELF.
//! @param nStackSize Ignored: a stack of 1 is always created.
//! @param sNewTag Ignored: the blueprint tag is kept.
void _CreateItemOnObject(string sItemTemplate, object oTarget=OBJECT_SELF, int nStackSize=1, string sNewTag="")
{
CreateItemOnObject(sItemTemplate, oTarget);
}
// -----------------------------------------------------------------------------
//! @brief Identify the activation target and print its details to the server console.
void OnToolActivate();
void OnToolActivate()
{
object oObject = GetItemActivatedTarget();
if (!GetIsObjectValid(oObject))
return;
int nObjectType = GetObjectType(oObject);
SetIdentified(oObject, TRUE);
if (GetHasInventory(oObject))
IdentifyInventory(oObject);
NWNX_Util_RawPrint("");
NWNX_Util_RawPrint(GetName(oObject));
NWNX_Util_RawPrint(". " + GetObjectTypeString(oObject));
NWNX_Util_RawPrint(". tag: " + GetTag(oObject) + ", resref: " + GetResRef(oObject));
if (GetCurrentHitPoints(oObject))
NWNX_Util_RawPrint(". hp: " + IntToString(GetCurrentHitPoints(oObject)));
if (GetGoldPieceValue(oObject))
NWNX_Util_RawPrint(". cost: " + IntToString(GetGoldPieceValue(oObject)));
if (nObjectType == OBJECT_TYPE_DOOR || nObjectType == OBJECT_TYPE_PLACEABLE)
NWNX_Util_RawPrint(". hardness: " + IntToString(GetHardness(oObject)));
LogLocalVars(oObject, ". ");
NWNX_Util_RawPrint("");
}
// =============================================================================
void main()
{
// Do not register anything if not in debug mode
if (!GetIsDebug())
return;
string sEvent = NWNX_Events_GetCurrentEvent();
if (sEvent == ON_REGISTER)
SubscribeToEvent(ON_DEFAULT_CLIENT_ENTER, __FILE__);
else if (sEvent == ON_DEFAULT_CLIENT_ENTER)
{
object oPC = GetEnteringObject();
object oItem = GetItemPossessedBy(oPC, INSPECT_TAG);
if (GetIsObjectValid(oItem))
return;
DelayCommand(1.0f, _CreateItemOnObject(INSPECT_RESREF, oPC));
}
else if (sEvent == NWNX_ON_RUN_EVENT_SCRIPT_BEFORE)
{
if (GetCurrentlyRunningEvent() != EVENT_SCRIPT_MODULE_ON_ACTIVATE_ITEM)
return;
OnToolActivate();
}
}