Jaysyn904 22947ad4b6 Initial Upload
Initial Upload
2023-08-08 16:22:17 -04:00

549 lines
18 KiB
Plaintext

//::///////////////////////////////////////////////
//:: bank_inc.nss
//:: Bank Vault include file
//:: Version 1.7
//:://////////////////////////////////////////////
/*
1.0 Orginal Version
1.1 Fixed problem with multiple opens where items from
First opener where assign to Second, third, etc PC.
OnDisturb checks to see if PC Adding/Removing items
is the orginal Opener. Returns items if not.
1.2 Made workaround for Blank Template Problem. OnDistrub returns
any items or Containers that have or contain a blank Template
returned by GetResRef() function back to original PC.
Made workaround for Multiple PC problem. Any PC opening Chest
other then original PC will be teleported to the closest waypoint
(WP_BankLobby) and told to wait their turn. :)
1.3 Fixed Blank Template Bug. Items that are split or bought from
Merchants can now be placed into the Bank Vault.
Fixed problem where item were being listed as unidentified even though
they were list as ID when placed into Bank Vault.
1.4 Added a Storage Limit variable to limit items per PC that can be stored
into Bank Chest. Currently set to 20. Change the iStorageLimit variable
in the bank_inc.nss file to increase/decrease.
1.5 Fixed problem where gold was duplicating or dissapearing when adding more
then 50000 gold pieces to the Bank Chest. Changed Bank Chest so that you
don't need a WayPoint to transport any additonal PC's trying to access chest
after the first.
1.6 Added the ability to switch the Bank Chest(s) to be either Module wide Chests
(the same items appear no matter what Area you are in the Module), or Local
Chests (Items are stored in a Area can only be retrieved in that Area). These
options are controled by the "BankModule" variable in the Bank_inc.nss file.
Added a switch that will store all PC Bank Vault data into a single database,
(default "BankVault"), or create a seperate database for each Players's PC.
This should help in Persistent Worlds with cleaningup character data.
This is controlled with the "iSingleCamp" variable in the Bank_inc.nss file.
1.7 Added ablility to store unique objects that are not in the Module Pallette (aka no ResRef).
PC's can now store items from other modules into the BankVault. Added a
Anti-spam fixed to prevent users from duplicating items in BankVault.
*/
//:://////////////////////////////////////////////
//:: Created By: Clayten Gillis (a.k.a DragonsWake)
//:: Created On: December 17, 2002
//:://////////////////////////////////////////////
// Variable Declarations
// Print Debug Statements. Set to '1' to Print Debug statements to PC
int Debug = 1;
// Set BanksModule = 1 for Module wide Bank. Set BankModule = 0 for Local Banks.
int BankModule = 1;
// Set the Chest to being opened for the first time (Do Not Modify)
int FirstTime = 1;
int iCurUse;
int iLastUse;
// Storage Limit for Bank Chest. This limits how many items per PC that can be stored.
int iStorageLimit = 20;
// Campaign Name for Bank Vault. Default is BankVault
string sCampName = "BankVault";
string sDataName = "";
// Single Campaign Database. If set to 1 it will open a single Database called
// "BankVault". If set to 0 it will open a database for each individual PC.
int iSingleCamp = 1;
// Internal Identifiers of storage variables. (Do Not Modify)
string sBankBP = "BankItemBP";
string sBankUQ = "BankItemUQ";
string sBankItemID = "BankItemID";
string sBankGold = "BankGold";
string sBankStack = "BankStkAmt";
int iHeaderCount = 0;
int iStackAmt = 0;
object oCurInvObj;
string sBankKey = "";
string sEventTime = "BankEvent";
int iUnique = 0;
// GetKey() Taken from PWDB Include written by Valerio Santinelli - tanis@mediacom.it
// Determine an Object's key.
string GetKey(object oTarget)
{
string sKey;
if (GetIsPC(oTarget))
{
sKey = GetPCPlayerName(oTarget) + "_" + GetName(oTarget);
}
else
{
//location lLoc = GetLocation(oTarget);
//vector vLoc = GetPositionFromLocation(lLoc);
//int iVec1 = FloatToInt(vLoc.x);
//int iVec2 = FloatToInt(vLoc.y);
//int iVec3 = FloatToInt(vLoc.z);
object oArea = GetArea(oTarget);
string sAreaName = GetName(oArea);
//string sLoc = IntToString(iVec1) + IntToString(iVec2) + IntToString(iVec3);
sKey = GetTag(oTarget) + sAreaName;
// + GetName(oTarget)
}
return sKey;
}
int EncodeGold (object oPC, object oCurItem, int iItemCount, string sItemName, string sCampName, string sAreaKey)
{
iStackAmt = GetNumStackedItems(oCurItem);
if (iStackAmt > 50000)
{
int i;
int iDivision = iStackAmt / 50000;
int iModulo = iStackAmt % 50000;
for (i = 0; i < iDivision; i++)
{
SetCampaignInt(sCampName, sBankGold + IntToString(iItemCount) + sAreaKey, 50000, oPC);
SetCampaignString(sCampName, sBankBP + IntToString(iItemCount) + sAreaKey, sItemName, oPC);
iItemCount = iItemCount + 1;
if (Debug)
{
SendMessageToPC(oPC, "Item#: "+IntToString(iItemCount));
SendMessageToPC(oPC, "This is Gold. StackSize "+IntToString(50000));
SendMessageToPC(oPC, "Valid Object:" + IntToString(GetIsObjectValid(oCurItem)) );
SendMessageToPC(oPC, "ResRef: "+sItemName);
SendMessageToPC(oPC, "----------");
}
}
SetCampaignInt(sCampName, sBankGold + IntToString(iItemCount) + sAreaKey, iModulo, oPC);
SetCampaignString(sCampName, sBankBP + IntToString(iItemCount) + sAreaKey, sItemName, oPC);
if (Debug)
{
SendMessageToPC(oPC, "Item#: "+IntToString(iItemCount));
SendMessageToPC(oPC, "This is Gold. StackSize "+IntToString(iModulo));
SendMessageToPC(oPC, "Valid Object:" + IntToString(GetIsObjectValid(oCurItem)) );
SendMessageToPC(oPC, "ResRef: "+sItemName);
SendMessageToPC(oPC, "----------");
}
}
else
{
SetCampaignInt(sCampName, sBankGold + IntToString(iItemCount) + sAreaKey, iStackAmt, oPC);
SetCampaignString(sCampName, sBankBP + IntToString(iItemCount) + sAreaKey, sItemName, oPC);
// Debug Statements
if (Debug)
{
SendMessageToPC(oPC, "Item#: "+IntToString(iItemCount));
SendMessageToPC(oPC, "This is Gold. StackSize "+IntToString(iStackAmt));
SendMessageToPC(oPC, "Valid Object:" + IntToString(GetIsObjectValid(oCurItem)) );
SendMessageToPC(oPC, "ResRef: "+sItemName);
SendMessageToPC(oPC, "----------");
}
}
return iItemCount;
}
void EncodeItem (object oPC, object oCurItem, int iItemCount, string sItemName, string sCampName, string sAreaKey, int iItemUnq)
{
SetCampaignString(sCampName, sBankBP + IntToString(iItemCount) + sAreaKey, sItemName, oPC);
if ( GetIdentified(oCurItem) )
{
SetCampaignInt(sCampName, sBankItemID + IntToString(iItemCount) + sAreaKey, 1, oPC);
}
else
{
SetCampaignInt(sCampName, sBankItemID + IntToString(iItemCount) + sAreaKey, 0, oPC);
}
if (iItemUnq)
{
StoreCampaignObject(sCampName, sBankUQ + IntToString(iItemCount) + sAreaKey, oCurItem, oPC);
}
//Debug Statements
if (Debug)
{
SendMessageToPC(oPC, "Item#: "+IntToString(iItemCount));
SendMessageToPC(oPC, "This is an Item.");
SendMessageToPC(oPC, "Valid Object: " + IntToString(GetIsObjectValid(oCurItem)) );
if ( !iItemUnq )
{
SendMessageToPC(oPC, "ResRef: "+sItemName);
}
else
{
SendMessageToPC(oPC, "ResRef: Unique");
}
SendMessageToPC(oPC, "Identified?: " + IntToString(GetIdentified(oCurItem)));
SendMessageToPC(oPC, "----------");
}
return;
}
int EncodeStackItem (object oPC, object oCurItem, int iItemCount, string sCampName, string sAreaKey, int iItemUnq)
{
string sItemName;
if (!iItemUnq)
{
iStackAmt = GetNumStackedItems(oCurItem);
SetCampaignString(sCampName, sBankBP + IntToString(iItemCount) + sAreaKey, "STACK", oPC);
iItemCount = iItemCount + 1;
SetCampaignInt(sCampName, sBankStack + IntToString(iItemCount) + sAreaKey, iStackAmt, oPC);
string sItemName = GetResRef(oCurItem);
if ( sItemName == "" )
{
sItemName = GetTag(oCurItem);
}
SetCampaignString(sCampName, sBankBP + IntToString(iItemCount) + sAreaKey, sItemName, oPC);
}
else
{
SetCampaignString(sCampName, sBankBP + IntToString(iItemCount) + sAreaKey, "STACKUNQ", oPC);
iItemCount = iItemCount + 1;
sItemName = "UNIQUE";
SetCampaignString(sCampName, sBankBP + IntToString(iItemCount) + sAreaKey, sItemName, oPC);
StoreCampaignObject(sCampName, sBankUQ + IntToString(iItemCount) + sAreaKey, oCurItem, oPC);
}
if ( GetIdentified(oCurItem) )
{
SetCampaignInt(sCampName, sBankItemID + IntToString(iItemCount) + sAreaKey, 1, oPC);
}
else
{
SetCampaignInt(sCampName, sBankItemID + IntToString(iItemCount) + sAreaKey, 0, oPC);
}
//Debug Statements
if (Debug)
{
SendMessageToPC(oPC, "Item#: "+IntToString(iItemCount));
SendMessageToPC(oPC, "Stack Item. StackSize: "+IntToString(iStackAmt));
SendMessageToPC(oPC, "Valid Object:" + IntToString(GetIsObjectValid(oCurItem)) );
SendMessageToPC(oPC, "ResRef: "+ sItemName );
SendMessageToPC(oPC, "Identified?: " + IntToString(GetIdentified(oCurItem)));
SendMessageToPC(oPC, "----------");
}
return iItemCount;
}
int EncodeContainer (object oPC, object oCurItem, int iItemCount, string sItemName, string sCampName, string sAreaKey, int iItemUnq)
{
iHeaderCount = 0;
//Debug
if (Debug)
{
SendMessageToPC(oPC, "Encode Container ROUTINE");
}
if (!iItemUnq)
{
SetCampaignString(sCampName, sBankBP + IntToString(iItemCount) + sAreaKey, "CONTAIN", oPC);
}
else
{
SetCampaignString(sCampName, sBankBP + IntToString(iItemCount) + sAreaKey, "CONTAINUNQ", oPC);
}
iHeaderCount = iHeaderCount + 1;
iItemCount = iItemCount + 1;
EncodeItem(oPC, oCurItem, iItemCount, sItemName, sCampName, sAreaKey, iItemUnq);
oCurInvObj = GetFirstItemInInventory(oCurItem);
while ( GetIsObjectValid(oCurInvObj) == TRUE || GetResRef(oCurInvObj) == "nw_it_gold001") //Begin Processing Item in Inventory
{
iItemCount = iItemCount + 1;
sItemName = GetResRef(oCurInvObj);
if ( sItemName == "" )
{
//sItemName = GetTag(oCurInvObj);
//if (sItemName == "")
//{
iUnique = 1;
sItemName = "UNIQUE";
//}
//else
//{
// iUnique = 0;
//}
}
else
{
iUnique = 0;
}
if ( sItemName == "nw_it_gold001")
{
EncodeGold(oPC, oCurInvObj, iItemCount, sItemName, sCampName, sAreaKey);
}
else
{
//Debug
if (Debug)
{
SendMessageToPC(oPC, "----------");
SendMessageToPC(oPC, "StackNum: "+IntToString(GetNumStackedItems(oCurInvObj)));
SendMessageToPC(oPC, "----------");
}
if (GetHasInventory(oCurInvObj) == TRUE )
{
iItemCount = EncodeContainer(oPC, oCurInvObj, iItemCount, sItemName, sCampName, sAreaKey, iUnique);
}
else if (GetNumStackedItems(oCurInvObj) > 1)
{
iHeaderCount = iHeaderCount + 1;
iItemCount = EncodeStackItem( oPC, oCurInvObj, iItemCount, sCampName, sAreaKey, iUnique);
}
else
{
EncodeItem(oPC, oCurInvObj, iItemCount, sItemName, sCampName, sAreaKey, iUnique);
}
}
oCurInvObj = GetNextItemInInventory(oCurItem);
}
iItemCount = iItemCount + 1;
SetCampaignString(sCampName, sBankBP + IntToString(iItemCount) + sAreaKey, "END", oPC);
iHeaderCount = iHeaderCount + 1;
//Debug
if (Debug)
{
SendMessageToPC(oPC, "END Encode Container ROUTINE");
}
return iItemCount;
}
void DecodeGold (object oPC, object oCurContainer, int iItemCount, string sItemName, string sCampName, string sAreaKey)
{
iStackAmt = GetCampaignInt(sCampName, sBankGold + IntToString(iItemCount) + sAreaKey, oPC);
object oCurItem = CreateItemOnObject(sItemName, oCurContainer, iStackAmt);
// Debug Statements
if (Debug)
{
SendMessageToPC(oPC, "Item#: "+IntToString(iItemCount));
SendMessageToPC(oPC, "This Gold. StackSize "+IntToString(iStackAmt));
SendMessageToPC(oPC, "Valid Object:" + IntToString(GetIsObjectValid(oCurItem)) );
SendMessageToPC(oPC, "ResRef: "+sItemName);
SendMessageToPC(oPC, "----------");
}
return;
}
object DecodeItem (object oPC, object oCurContainer, int iItemCount, string sItemName, string sCampName, string sAreaKey, int iItemUnq)
{
object oCurItem;
if (!iItemUnq)
{
oCurItem = CreateItemOnObject(sItemName, oCurContainer, 1);
}
else
{
oCurItem = RetrieveCampaignObject(sCampName, sBankUQ + IntToString(iItemCount) + sAreaKey, GetLocation(OBJECT_SELF), OBJECT_SELF, oPC); //,
}
if ( GetCampaignInt(sCampName, sBankItemID + IntToString(iItemCount) + sAreaKey, oPC) )
{
SetIdentified(oCurItem, TRUE);
}
else
{
SetIdentified(oCurItem, FALSE);
}
//Debug Statements
if (Debug)
{
SendMessageToPC(oPC, "Item#: "+IntToString(iItemCount));
SendMessageToPC(oPC, "This is an Item.");
SendMessageToPC(oPC, "Valid Object:" + IntToString(GetIsObjectValid(oCurItem)) );
SendMessageToPC(oPC, "ResRef: "+sItemName);
SendMessageToPC(oPC, "Identified?: " + IntToString(GetCampaignInt(sCampName, sBankItemID + IntToString(iItemCount) + sAreaKey, oPC)) );
SendMessageToPC(oPC, "----------");
}
//DeletePersistentInt(oPC, sBankItemID + IntToString(iItemCount) );
return oCurItem;
}
int DecodeStackItem (object oPC, object oCurContainer, int iItemCount, string sItemName, string sCampName, string sAreaKey, int iItemUnq)
{
object oCurItem;
//DeletePersistentString(oPC, sBankBP + IntToString(iItemCount) );
iItemCount = iItemCount + 1;
if (!iItemUnq)
{
iStackAmt = GetCampaignInt(sCampName, sBankStack + IntToString(iItemCount) + sAreaKey, oPC);
sItemName = GetCampaignString(sCampName, sBankBP + IntToString(iItemCount) + sAreaKey, oPC);
oCurItem = CreateItemOnObject(sItemName, oCurContainer, iStackAmt);
}
else
{
oCurItem = RetrieveCampaignObject(sCampName, sBankUQ + IntToString(iItemCount) + sAreaKey, GetLocation(OBJECT_SELF), OBJECT_SELF, oPC); //,
}
if ( GetCampaignInt(sCampName, sBankItemID + IntToString(iItemCount) + sAreaKey, oPC) )
{
SetIdentified(oCurItem, TRUE);
}
else
{
SetIdentified(oCurItem, FALSE);
}
//DeletePersistentInt(oPC, sBankStack + IntToString(iItemCount) );
//DeletePersistentInt(oPC, sBankItemID + IntToString(iItemCount) );
//Debug Statements
if (Debug)
{
SendMessageToPC(oPC, "Item#: "+IntToString(iItemCount));
SendMessageToPC(oPC, "Stack Item. StackSize: "+IntToString(iStackAmt));
SendMessageToPC(oPC, "Valid Object:" + IntToString(GetIsObjectValid(oCurItem)) );
SendMessageToPC(oPC, "ResRef: "+sItemName);
SendMessageToPC(oPC, "Identified?: " + IntToString(GetCampaignInt(sCampName, sBankItemID + IntToString(iItemCount)+ sAreaKey, oPC)) );
SendMessageToPC(oPC, "----------");
}
return iItemCount;
}
int DecodeContainer (object oPC, object oCurContainer, string sItemName, int iItemCount, string sCampName, string sAreaKey, int iItemUnq)
{
//Debug
if (Debug)
{
SendMessageToPC(oPC, "Decode Container ROUTINE");
}
// DeletePersistentString(oPC, sBankBP + IntToString(iItemCount) );
iItemCount = iItemCount +1;
//Debug
if (Debug)
{
SendMessageToPC(oPC, "Item#: "+IntToString(iItemCount) );
}
sItemName = GetCampaignString(sCampName, sBankBP + IntToString(iItemCount) + sAreaKey, oPC );
oCurContainer = DecodeItem(oPC, OBJECT_SELF, iItemCount, sItemName, sCampName, sAreaKey, iItemUnq);
sItemName = GetCampaignString(sCampName, sBankBP + IntToString(iItemCount + 1) + sAreaKey, oPC );
while ( sItemName != "END")
{
iItemCount = iItemCount + 1;
//Debug
if (Debug)
{
SendMessageToPC(oPC, "Item#: "+IntToString(iItemCount) );
}
sItemName = GetCampaignString(sCampName, sBankBP + IntToString(iItemCount) + sAreaKey, oPC );
if ( sItemName != "nw_it_gold001" )
{
if ( sItemName == "STACK")
{
iItemCount = DecodeStackItem(oPC, oCurContainer, iItemCount, sItemName, sCampName, sAreaKey, 0);
}
else
{
if ( sItemName == "STACKUNQ")
{
iItemCount = DecodeStackItem(oPC, oCurContainer, iItemCount, sItemName, sCampName, sAreaKey, 1);
}
else
{
if ( sItemName == "UNIQUE" )
{
DecodeItem(oPC, oCurContainer, iItemCount, sItemName, sCampName, sAreaKey, 1);
}
else
{
DecodeItem(oPC, oCurContainer, iItemCount, sItemName, sCampName, sAreaKey, 0);
}
}
}
}
else
{
DecodeGold(oPC, oCurContainer, iItemCount, sItemName, sCampName, sAreaKey);
// DeletePersistentInt(oPC, sBankGold );
}
// DeletePersistentString(oPC, sBankBP + IntToString(iItemCount) );
}
return iItemCount;
}
void ResetBank (object oBank)
{
DestroyObject(oBank);
CreateObject(GetObjectType(oBank),GetResRef(oBank),GetLocation(oBank));
return;
}