Aschbourne_PRC8/_module/nss/pv_get_items_bak.nss

152 lines
4.2 KiB
Plaintext
Raw Normal View History

2024-06-14 10:48:20 -04:00
//::///////////////////////////////////////////////
//:: Name: pv_get_items_bak
//:://////////////////////////////////////////////
/*
Gets the items in the backpacks to display
in the conversation window
*/
//:://////////////////////////////////////////////
#include "pv_utils"
// Variables that will be used in the whole script
object oNPCMerchant = OBJECT_SELF;
object oPCOwner = GetLocalObject(oNPCMerchant, "PV_MERCHANT_OWNER");
object oPCSpeaker = GetPCSpeaker();
int iTokenName = 15003;
// Gets the items from all the backpacks currently available. These backpacks
// are set by the script 'pv_get_backpacks'
int GetItems();
// Sets some variables regarding conversation handling (page number, number of
// displayed items, etc...)
void SetVariables(int nItems);
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void main()
{
int nItems = 0;
nItems = GetItems();
SetVariables(nItems);
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
int GetItems()
{
int nBackpack = 0;
int iCountItems = 0;
int iCurrentItem = 1;
int iMaxItems = MAX_ITEMS_PER_PAGE * (GetLocalInt(oNPCMerchant, "PV_CURRENT_PAGE_NUMBER") - 1);
object oItem = OBJECT_INVALID;
object oBackpack = GetLocalObject(oNPCMerchant, "PV_BACKPACK_NUM_"+IntToString(nBackpack));
// Skip some items to display
oItem = GetFirstItemInInventory(oBackpack);
while(iCurrentItem <= iMaxItems)
{
// Last item?
if (!GetIsObjectValid(oItem))
{
// if so, switch backpacks
nBackpack++;
oBackpack = GetLocalObject(oNPCMerchant, "PV_BACKPACK_NUM_"+IntToString(nBackpack));
if (!GetIsObjectValid(oBackpack))
{
break;
}
else
{
oItem = GetFirstItemInInventory(oBackpack);
if (!GetIsObjectValid(oItem))
{
break;
}
}
}
if ( GetIdentified(oItem)
&& ( (oPCOwner == oPCSpeaker) || ( GetLocalInt(oNPCMerchant, "PV_ITEM_PRICE" + GetName(oItem)) > 0 && !GetLocalInt(oNPCMerchant, "PV_DONT_SHOW_BUYER" + GetName(oItem) ))))
{
iCurrentItem++;
}
oItem = GetNextItemInInventory(oBackpack);
}
// Display Current
iCurrentItem = 1;
while(iCurrentItem <= MAX_ITEMS_PER_PAGE)
{
if (!GetIsObjectValid(oItem))
{
nBackpack++;
oBackpack = GetLocalObject(oNPCMerchant, "PV_BACKPACK_NUM_"+IntToString(nBackpack));
if (!GetIsObjectValid(oBackpack))
{
break;
}
else
{
oItem = GetFirstItemInInventory(oBackpack);
if (!GetIsObjectValid(oItem))
{
break;
}
}
}
if ( GetIdentified(oItem)
&& ( (oPCOwner == oPCSpeaker) || ( GetLocalInt(oNPCMerchant, "PV_ITEM_PRICE" + GetName(oItem)) > 0 && !GetLocalInt(oNPCMerchant, "PV_DONT_SHOW_BUYER" + GetName(oItem) ))))
{
SetCustomToken(iTokenName, GetName(oItem));
SetLocalObject(oNPCMerchant, "PV_BACKPACK_ITEM_NUM_"+IntToString(iCurrentItem), oItem);
iTokenName++; iCountItems++; iCurrentItem++;
}
oItem = GetNextItemInInventory(oBackpack);
}
if (GetIsObjectValid(oItem) && iCountItems != 0)
{
iCountItems++;
}
return iCountItems;
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void SetVariables(int nItems)
{
if ( GetLocalInt (oNPCMerchant, "PV_CURRENT_PAGE_NUMBER") <= 1 )
{
SetLocalInt(oNPCMerchant, "PV_CURRENT_PAGE_NUMBER", 1);
}
SetLocalInt(oNPCMerchant, "PV_NUM_DISPLAY_ITEM", 1);
SetLocalInt(oNPCMerchant, "PV_TOTAL_NUM_ITEMS", nItems);
}