//::///////////////////////////////////////////////// //:: Name: pv_db_functions //::///////////////////////////////////////////////// /* Contains code related to the database part of the Player Vendor */ //::///////////////////////////////////////////////// #include "pv_config_param" // Loads the items prices in the database to local variables set in the // NPC merchant void LoadItemPricesFromDatabase(object oPCOwner, object oNPCMerchant); // Saves a certain item price in the database void SaveItemPriceToDatabase(object oPC, int iItemPrice, string strItemName); // Loads the items prices in the database to local variables set in the // NPC merchant void LoadItemPricesFromDatabase_NWNX(object oPCOwner, object oNPCMerchant); // Saves a certain item price in the database void SaveItemPriceToDatabase_NWNX(object oPC, int iItemPrice, string strItemName); /* Example for the parsing: sword?120|armor?100|shield?200| */ void LoadItemPricesFromDatabase(object oPCOwner, object oNPCMerchant) { // If we are using NWNX2 call the appropriate function //if (USE_NWNX2) { LoadItemPricesFromDatabase_NWNX(oPCOwner, oNPCMerchant); return; } // Variables for the normal string string strDatabaseString = GetCampaignString("PlayerVendor__PriceInfo", "PriceInfo", oPCOwner); int iStringPosition = 0; // Variables for the substring we will find string strSubString1 = ""; string strSubString2 = ""; int iSubStringPos = 0; int iSubStringLength = 0; if (GetStringLength(strDatabaseString) > 0) { // Loop while the string we are looking for exists // The comments below are only for the first item. :P while(iStringPosition != -1) { // Get the position of the first ocurrence of '|' // We would get 9 in the example iStringPosition = FindSubString(strDatabaseString, "|"); if (iStringPosition == -1) { break; } // Get the first (iStringPosition - 1) characters in the string // In the example >> sword?120 strSubString1 = GetSubString(strDatabaseString, 0, iStringPosition); // Find the '?' // it would return 5 iSubStringPos = FindSubString(strSubString1, "?"); // Get the first five characters // In the example >> sword // We now have the item name strSubString2 = GetSubString(strSubString1, 0, iSubStringPos); // With the other SubString position value we now get the characters in front // of it. // In the example >> 120 // We now have the item price strSubString1 = GetSubString(strSubString1, iSubStringPos + 1, GetStringLength(strSubString1)); // Now we set the Price in a local variable in the NPCMerchant SetLocalInt(oNPCMerchant, "PV_ITEM_PRICE" + strSubString2, StringToInt(strSubString1)); // Restore the database string minus the item information we just retrieved strDatabaseString = GetSubString(strDatabaseString, iStringPosition + 1, GetStringLength(strDatabaseString)); } } } void SaveItemPriceToDatabase(object oPC, int iItemPrice, string strItemName) { // If we are using NWNX2 call the appropriate function //if (USE_NWNX2) { SaveItemPriceToDatabase_NWNX(oPC, iItemPrice, strItemName); return; } string strDatabaseString = GetCampaignString("PlayerVendor__PriceInfo", "PriceInfo", oPC); string strSubStringLeft = ""; int iStringPosition = 0; // Search if the item already exists iStringPosition = FindSubString(strDatabaseString, strItemName); // If it already exists we are going to remove it from the main string and // then place it in the end. if (iStringPosition != -1) { // Store the left half of the string strSubStringLeft = GetSubString(strDatabaseString, 0, iStringPosition); // Get the first ocurrence of '|' iStringPosition = FindSubString(strSubStringLeft, "|"); // Restore the database string minus the information at the left of the '|' // and including the left half that we removed strDatabaseString = strSubStringLeft + GetSubString(strDatabaseString, iStringPosition + 1, GetStringLength(strDatabaseString)); } // Include the new item info in the end of the string strDatabaseString = strDatabaseString + strItemName + "?" + IntToString(iItemPrice) + "|"; // Put it in the database SetCampaignString("PlayerVendor__PriceInfo", "PriceInfo", strDatabaseString, oPC); } void LoadItemPricesFromDatabase_NWNX(object oPCOwner, object oNPCMerchant) { } void SaveItemPriceToDatabase_NWNX(object oPC, int iItemPrice, string strItemName) { }