LoD_PRC8/_module/nss/final_legend_inc.nss
Jaysyn904 94990edc60 Initial Upload
Initial Upload
2023-09-21 21:20:34 -04:00

111 lines
3.6 KiB
Plaintext

#include "sd_arrays"
int CheckExchangeItems(object oPC, int Exchange)
{
int iResult;
string sTAG_Chest1 = "FRFinalLegend________20_0_20_4_1";
string sTAG_Chest2 = "FI" + GetStringRight(sTAG_Chest1, GetStringLength(sTAG_Chest1)-2);
object oChest = GetObjectByTag(sTAG_Chest1);
object oItem = GetFirstItemInInventory(oChest);
int iItemCounter = 0;
int iTotalItems = 0;
string sResRef = "";
int iItemFound = 0;
int iStackItems = 0;
//build a local array of resrefs on the PC to run comparison against
while (oItem != OBJECT_INVALID)
{
iItemCounter++;
sResRef = GetResRef(oItem);
SetLocalArrayString(oPC, "ChestItem", iItemCounter, sResRef);
SetLocalArrayInt(oPC, "ChestItemStack", iItemCounter, GetNumStackedItems(oItem));
oItem = GetNextItemInInventory(oChest);
}
//set a local memory variable to the pc, with the information of how many items there were in the chest.
SetLocalInt(oPC, "ChestItemCount", iItemCounter);
//reset the counters for looping the memory variables and the PC's inventory
iTotalItems = iItemCounter;
iItemCounter = 0;
while (iItemCounter<iTotalItems)
{
iItemCounter++;
sResRef = GetLocalArrayString(oPC, "ChestItem", iItemCounter);
oItem = GetFirstItemInInventory(oPC);
iItemFound = 0;
while ((oItem != OBJECT_INVALID) && (iItemFound == 0))
{
if (GetResRef(oItem) == sResRef)
{
//check if the number of items stacked is equal
iStackItems = GetLocalArrayInt(oPC, "ChestItemStack", iItemCounter);
if (GetNumStackedItems(oItem) == iStackItems)
{
// so we found a matching entry in the pc's inventory
iItemFound = 1;
if (Exchange == 1)
{
//If exchange is '1', then we already know that the PC has all the items. Lets destroy it then
DestroyObject(oItem, 0.0f);
}
break;
}
}
oItem = GetNextItemInInventory(oPC);
}
// If the item is NOT found in the PC's inventory, then break the loop
if (iItemFound == 0)
{
FloatingTextStringOnCreature("Item "+sResRef+" missing",oPC);
break;
}
}
//NOW .. if exchange is '1' then all the items are destroyed, lets put the item in the pc's inventory
if (Exchange == 1)
{
oItem = GetFirstItemInInventory(GetObjectByTag(sTAG_Chest2));
iStackItems = GetNumStackedItems(oItem);
sResRef = GetResRef(oItem);
oItem = CreateItemOnObject(sResRef, oPC, iStackItems);
SetIdentified(oItem, TRUE);
}
//Think it may be safe to say that if iItemFound was found on the last item, PC got all items in inventory
iResult = iItemFound;
return iResult;
}
void PortTo (int iChoice, object oSpeaker)
{
object oWaypoint;
switch (iChoice)
{
case 1 : oWaypoint = GetWaypointByTag("WP_DEFAULT_SPAWN");
break;
case 2 : oWaypoint = GetWaypointByTag("forgottencity");
break;
case 3 : oWaypoint = GetWaypointByTag("WP_FreezingCity");
break;
case 4 : oWaypoint = GetWaypointByTag("rivendale");
break;
case 5 : oWaypoint = GetWaypointByTag("phoenix");
break;
case 6 : oWaypoint = GetWaypointByTag("clemmens");
break;
default : break;
}
AssignCommand(oSpeaker,ActionJumpToObject(oWaypoint,FALSE));
}
//void main() {}