Scripting Question: Merchant Inventories

Post » Wed Sep 29, 2010 10:34 pm

Hi all,

I am new here, so I apologize if scripting questions would be better placed in another subforum. I am wrestling with merchant inventories while bartering, and I am having particular trouble with OBSE function "GetMerchantContainer." I am trying to sort through the merchant's container to see what alchemical ingredients he/she has. In numerous tests, however, I find that GetNumItems does not match the total amount of items in the merchants container. Furthermore, when I try to put every alchemical ingredient into the player's inventory, I find that only a random number of items get added, which has no bearing on what the merchant's container actually contains. My initial suspicion would be that adding/removing multiple items with the same script is known to be buggy (see http://cs.elderscrolls.com/constwiki/index.php/Common_Bugs#Remove_Item_and_Selling_Stackable_Items_with_Extra_Data). But this would not explain the bizarre GetNumItems and inventory-walkthrough bugs I am having.

Here is the part of the script that I am talking about--if anyone notices anything erroneous, please let me know! Or if there is a well-known bug that I am unaware, I would like to know that too.

;-----------------------------------------------------------------------

. . .
. . .
. . .
If (Activated == 0)
If (IsBarterMenuActive) && (GetNumKeysPressed != 0)
If (IsKeyPressed3 54) || (IsKeyPressed3 42) ; {Left or Right Shift}
If (IsKeyPressed3 25) ; {"P"}
Set Merchant to GetActiveMenuRef
Set MerchantInventory to Merchant.GetMerchantContainer
Set X to MerchantInventory.GetNumItems

If (Merchant.OffersIngredients)
SaveIP 1
Set X to X - 1
If (X >= 0)
Set Ingredient to MerchantInventory.GetInventoryObject X
If (MerchantInventory.GetObjectType Ingredient == 25)
Set Count to MerchantInventory.GetItemCount Ingredient
Set Cost to Cost + (MerchantInventory.GetGoldValue Ingredient) * Count
RestoreIP 1
Else
RestoreIP 1
Endif
Else

. . .
. . .
. . .
;---------------------------------------------------------------------
Thanks in advance!

PS: Possible sidenote. I notice that some merchants, like TheGildedCarafe, have actually a few chests that all seem to contribute to what the player sees in the barter menu. Does GetMerchantContainer only return one of those chests? I tried indexing that function (adding an integer at the end of the command), but the script would not run in-game even though the CS compiled it.


Underground
User avatar
Carlos Vazquez
 
Posts: 3407
Joined: Sat Aug 25, 2007 10:19 am

Return to IV - Oblivion