ff_u_inv_limits
TODO.
Source code
// @code
#include "ff_i_core"
const string ENABLE__FF_U_INV_LIMITS = "ENABLE__FF_U_INV_LIMITS";
const string INVENTORY_MAX_ITEMS = "INVENTORY_MAX_ITEMS";
const string INVENTORY_MAX_SPACE = "INVENTORY_MAX_SPACE";
// -----------------------------------------------------------------------------
// 67724 => "This container is full."
// const string MESSAGE = "This container is full.";
//! @brief Skip the add-item event if oContainer has reached its item or space limit.
//! @param oContainer The container receiving the item.
void PreventAddingToContainer(object oContainer)
{
if (!GetHasInventory(oContainer))
return;
if (GetIsInventoryEmpty(oContainer))
return;
object oItem = StringToObject(NWNX_Events_GetEventData("ITEM"));
if (!GetIsPC(GetItemPossessor(oItem)))
return;
// Maximum number of items.
int nMaxItems = GetRecursiveInt(oContainer, INVENTORY_MAX_ITEMS, 0);
if (nMaxItems > 0)
{
int nItems = NWNX_Object_GetInventoryItemCount(oContainer) ;
if ((nItems + 1) > nMaxItems)
{
NWNX_Events_SkipEvent();
return;
}
}
int nMaxSpace = GetRecursiveInt(oContainer, INVENTORY_MAX_SPACE, 35);
if (nMaxSpace > 0)
{
int nSpace = GetItemDimensions(oItem);
oItem = GetFirstItemInInventory(oContainer);
while (GetIsObjectValid(oItem))
{
nSpace += GetItemDimensions(oItem);
if (nSpace > nMaxSpace)
{
NWNX_Events_SkipEvent();
return;
}
oItem = GetNextItemInInventory(oContainer);
}
}
}
void main()
{
object oModule = GetModule();
if (!GetModuleFlag(ENABLE__FF_U_INV_LIMITS, FALSE))
return;
string sEvent = GetCurrentEvent();
if (sEvent == ON_REGISTER)
SubscribeToEvent(ON_BEFORE_ADD_ITEM_INVENTORY, __FILE__);
else if (sEvent == ON_BEFORE_ADD_ITEM_INVENTORY)
PreventAddingToContainer(OBJECT_SELF);
}