Jump to content

Help with dynamically-populated FormLists


HunterZ

Recommended Posts

So I'm working on my Bag of Holding mod, and I'm having trouble getting a new feature to work. What I'm trying to do is use the NVSE functions GetHotkeyItem and player.GetEquippedObject to build a FormList of the base IDs of all hotkeyed and player-equipped items, which I'm then trying to use an exclusion list for player.RemoveAllTypedItems calls.

 

Unfortunately, it's not working as expected. Specifically, I'm seeing the following problems:

  • If the player chooses to protect just equipped items, then all items get deposited - including equipped ones.
  • If the player chooses to protect hotkeyed items (or both hotkeyed and equipped items), then no items get deposited - including non-hotkeyed, non-equipped items.

 

Anyone know what the heck is going on? I've pasted my script into the spoiler tag below. Look under the "3 - NEW VALUE" comment for the most relevant section of code.

 

 

ScriptName HZBagOfHoldingScript

short iMaster
short iMouseover
short iOption
short iProtectHotkeyItems
short iProtectEquipItems
short iSubMenu
short iTemp
float fTemp
float fValue
int iItemIndex
int nCaps
int nListIndex
int nListSize
reference rList
reference rItem

begin GameMode
if GetGameRestarted
	if IsModLoaded "The Mod Configuration Menu.esp"
		set iMaster to GetModIndex "The Mod Configuration Menu.esp"
		set rList to BuildRef iMaster 2790
		ListAddForm rList HZBagOfHoldingMiscItem
	endif
endif
end

begin MenuMode 1013
if IsModLoaded "The Mod Configuration Menu.esp"
else
	Return
endif

if GetUIFloat "StartMenu/MCM/_ActiveMod" == GetModIndex "HZBagOfHolding.esp"
	set iOption to GetUIFloat "StartMenu/MCM/_ActiveOption"
	set fValue to GetUIFloat "StartMenu/MCM/_Value"

	if GetUIFloat "StartMenu/MCM/*:5/SubMenu1/_enable" == 0
		SetUIFloat "StartMenu/MCM/_ActiveSubMenu" 1
		SetUIFloat "StartMenu/MCM/*:5/SubMenu1/_enable" 1
		SetUIString "StartMenu/MCM/*:5/SubMenu1/text/string" "View"
		SetUIString "StartMenu/MCM/*:8/SubTitle1/string" "View Contents"

		SetUIFloat "StartMenu/MCM/*:5/SubMenu2/_enable" 1
		SetUIString "StartMenu/MCM/*:5/SubMenu2/text/string" "Deposit"
		SetUIString "StartMenu/MCM/*:8/SubTitle2/string" "Bulk Item Deposit"

		SetUIFloat "StartMenu/MCM/*:5/SubMenu3/_enable" 1
		SetUIString "StartMenu/MCM/*:5/SubMenu3/text/string" "Withdraw"
		SetUIString "StartMenu/MCM/*:8/SubTitle3/string" "Bulk Item Withdrawal"

		SetUIFloat "StartMenu/MCM/*:5/SubMenu4/_enable" 1
		SetUIString "StartMenu/MCM/*:5/SubMenu4/text/string" "Options"
		SetUIString "StartMenu/MCM/*:8/SubTitle4/string" "Miscellaneous Options"
	endif

	set iSubMenu to GetUIFloat "StartMenu/MCM/_ActiveSubMenu"

	if GetUIFloat "StartMenu/MCM/_Reset"			;1 - RESET
		SetUIFloat "StartMenu/MCM/_Reset" 0

		SetUIFloat "StartMenu/MCM/*:1/_columns" 1

		if iSubMenu == 1
			SetUIFloat "StartMenu/MCM/*:1/*:1/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:1/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:1/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:1/_title" "View/exchange specific items"
			SetUIFloat "StartMenu/MCM/*:1/*:1/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:1/_value" 0
		elseif iSubMenu == 2
			SetUIFloat "StartMenu/MCM/*:1/*:1/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:1/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:1/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:1/_title" "Deposit ALL items"
			SetUIFloat "StartMenu/MCM/*:1/*:1/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:1/_value" 0

			SetUIFloat "StartMenu/MCM/*:1/*:2/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:2/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:2/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:2/_title" "Deposit all caps"
			SetUIFloat "StartMenu/MCM/*:1/*:2/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:2/_value" 0

			SetUIFloat "StartMenu/MCM/*:1/*:3/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:3/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:3/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:3/_title" "Deposit all armor"
			SetUIFloat "StartMenu/MCM/*:1/*:3/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:3/_value" 0

			SetUIFloat "StartMenu/MCM/*:1/*:4/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:4/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:4/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:4/_title" "Deposit all skill books"
			SetUIFloat "StartMenu/MCM/*:1/*:4/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:4/_value" 0

			SetUIFloat "StartMenu/MCM/*:1/*:5/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:5/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:5/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:5/_title" "Deposit all miscellaneous items"
			SetUIFloat "StartMenu/MCM/*:1/*:5/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:5/_value" 0

			SetUIFloat "StartMenu/MCM/*:1/*:6/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:6/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:6/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:6/_title" "Deposit all weapons"
			SetUIFloat "StartMenu/MCM/*:1/*:6/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:6/_value" 0

			SetUIFloat "StartMenu/MCM/*:1/*:7/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:7/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:7/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:7/_title" "Deposit all ammunition"
			SetUIFloat "StartMenu/MCM/*:1/*:7/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:7/_value" 0

			SetUIFloat "StartMenu/MCM/*:1/*:8/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:8/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:8/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:8/_title" "Deposit all non-skill-book consumables"
			SetUIFloat "StartMenu/MCM/*:1/*:8/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:8/_value" 0
		elseif iSubMenu == 3
			SetUIFloat "StartMenu/MCM/*:1/*:1/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:1/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:1/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:1/_title" "Withdraw ALL items"
			SetUIFloat "StartMenu/MCM/*:1/*:1/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:1/_value" 0

			SetUIFloat "StartMenu/MCM/*:1/*:2/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:2/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:2/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:2/_title" "Withdraw all caps"
			SetUIFloat "StartMenu/MCM/*:1/*:2/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:2/_value" 0

			SetUIFloat "StartMenu/MCM/*:1/*:3/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:3/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:3/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:3/_title" "Withdraw all armor"
			SetUIFloat "StartMenu/MCM/*:1/*:3/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:3/_value" 0

			SetUIFloat "StartMenu/MCM/*:1/*:4/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:4/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:4/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:4/_title" "Withdraw all skill books"
			SetUIFloat "StartMenu/MCM/*:1/*:4/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:4/_value" 0

			SetUIFloat "StartMenu/MCM/*:1/*:5/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:5/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:5/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:5/_title" "Withdraw all miscellaneous items"
			SetUIFloat "StartMenu/MCM/*:1/*:5/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:5/_value" 0

			SetUIFloat "StartMenu/MCM/*:1/*:6/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:6/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:6/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:6/_title" "Withdraw all weapons"
			SetUIFloat "StartMenu/MCM/*:1/*:6/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:6/_value" 0

			SetUIFloat "StartMenu/MCM/*:1/*:7/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:7/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:7/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:7/_title" "Withdraw all ammunition"
			SetUIFloat "StartMenu/MCM/*:1/*:7/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:7/_value" 0

			SetUIFloat "StartMenu/MCM/*:1/*:8/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:8/_textOff" " "
			SetUIString "StartMenu/MCM/*:1/*:8/_textOn" " "
			SetUIString "StartMenu/MCM/*:1/*:8/_title" "Withdraw all non-skill-book consumables"
			SetUIFloat "StartMenu/MCM/*:1/*:8/_type" 6
			SetUIFloat "StartMenu/MCM/*:1/*:8/_value" 0
		elseif iSubMenu == 4
			SetUIFloat "StartMenu/MCM/*:1/*:1/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:1/_title" "Protect hotkeyed items"
			SetUIFloat "StartMenu/MCM/*:1/*:1/_type" 5
			SetUIFloat "StartMenu/MCM/*:1/*:1/_value" iProtectHotkeyItems

			SetUIFloat "StartMenu/MCM/*:1/*:2/_enable" 1
			SetUIString "StartMenu/MCM/*:1/*:2/_title" "Protect equipped items"
			SetUIFloat "StartMenu/MCM/*:1/*:2/_type" 5
			SetUIFloat "StartMenu/MCM/*:1/*:2/_value" iProtectEquipItems
		endif

	elseif GetUIFloat "StartMenu/MCM/_Default"		;2 - DEFAULT
		SetUIFloat "StartMenu/MCM/_Default" 0
		SetUIFloat "StartMenu/MCM/_Reset" 1

		set iProtectHotkeyItems to 1
		set iProtectEquipItems to 1

	elseif GetUIFloat "StartMenu/MCM/_NewValue"		;3 - NEW VALUE
		SetUIFloat "StartMenu/MCM/_NewValue" 0
		SetUIFloat "StartMenu/MCM/_Reset" 1

		if iSubMenu == 1
			if iOption == 1
				HZBagOfHoldingContainerREF.Activate player
			endif
		elseif iSubMenu == 2
			; build formlist for category-based bulk withdrawal options

			; first, clear list of old items if it isn't empty
			Label 320
				set nListSize to ListGetCount HZBagOfHoldingFormList
				if nListSize > 0
					; remove last item from list
					set nListIndex to nListSize - 1
					ListRemoveNthForm HZBagOfHoldingFormList nListIndex

					; if this isn't the last remaining item, loop
					if nListIndex > 0
						goto 320
					endif
				endif
			; end Label 320

			; now re-add current items to list
			; add hotkeyed items
			if iProtectHotkeyItems
				set iItemIndex to 1
				Label 321
					set rItem to GetHotkeyItem iItemIndex
					if rItem
						rItem.ListAddRef HZBagOfHoldingFormList
					endif

					set iItemIndex to iItemIndex + 1
					if iItemIndex <= 8
						goto 321
					endif
				; end Label 321
			endif

			; add equipped items
			if iProtectEquipItems
				set iItemIndex to 0
				Label 322
					set rItem to player.GetEquippedObject iItemIndex
					if rItem
						rItem.ListAddRef HZBagOfHoldingFormList
					endif

					set iItemIndex to iItemIndex + 1
					if iItemIndex <= 19
						goto 322
					endif
				; end Label 322
			endif

			set nListSize to ListGetCount HZBagOfHoldingFormList

			; now handle menu selection
			if iOption == 1
				player.RemoveAllItems HZBagOfHoldingContainerREF 1
			elseif iOption == 2
				; move caps from player to container
				set nCaps to player.GetItemCount Caps001
				player.RemoveItem Caps001 nCaps 1
				HZBagOfHoldingContainerREF.AddItem Caps001 nCaps 1
			elseif iOption == 3
				player.RemoveAllTypedItems HZBagOfHoldingContainerREF 1 1 24 HZBagOfHoldingFormList
			elseif iOption == 4
				player.RemoveAllTypedItems HZBagOfHoldingContainerREF 1 1 25 HZBagOfHoldingFormList
			elseif iOption == 5
				player.RemoveAllTypedItems HZBagOfHoldingContainerREF 1 1 31 HZBagOfHoldingFormList
			elseif iOption == 6
				player.RemoveAllTypedItems HZBagOfHoldingContainerREF 1 1 40 HZBagOfHoldingFormList
			elseif iOption == 7
				player.RemoveAllTypedItems HZBagOfHoldingContainerREF 1 1 41 HZBagOfHoldingFormList
			elseif iOption == 8
				player.RemoveAllTypedItems HZBagOfHoldingContainerREF 1 1 47 HZBagOfHoldingFormList
			endif
		elseif iSubMenu == 3
			if iOption == 1
				HZBagOfHoldingContainerREF.RemoveAllItems player 0
			elseif iOption == 2
				; move caps from container to player
				set nCaps to HZBagOfHoldingContainerREF.GetItemCount Caps001
				HZBagOfHoldingContainerREF.RemoveItem Caps001 nCaps 1
				player.AddItem Caps001 nCaps 1
			elseif iOption == 3
				HZBagOfHoldingContainerREF.RemoveAllTypedItems player 0 1 24
			elseif iOption == 4
				HZBagOfHoldingContainerREF.RemoveAllTypedItems player 0 1 25
			elseif iOption == 5
				HZBagOfHoldingContainerREF.RemoveAllTypedItems player 0 1 31
			elseif iOption == 6
				HZBagOfHoldingContainerREF.RemoveAllTypedItems player 0 1 40
			elseif iOption == 7
				HZBagOfHoldingContainerREF.RemoveAllTypedItems player 0 1 41
			elseif iOption == 8
				HZBagOfHoldingContainerREF.RemoveAllTypedItems player 0 1 47
			endif
		elseif iSubMenu == 4
			if iOption == 1
				set iProtectHotkeyItems to fValue
			elseif iOption == 2
				set iProtectEquipItems to fValue
			endif
		endif

	elseif GetUIFloat "StartMenu/MCM/_ShowList" == 1		;4 - SHOW LIST
		SetUIFloat "StartMenu/MCM/_ShowList" 2

	elseif GetUIFloat "StartMenu/MCM/_ShowScale" == 1		;5 - SHOW SCALE
		SetUIFloat "StartMenu/MCM/_ShowScale" 2

	elseif GetUIFloat "StartMenu/MCM/_DefaultScale"		;6 - DEFAULT SCALE
		SetUIFloat "StartMenu/MCM/_DefaultScale" 0
		SetUIFloat "StartMenu/MCM/_ShowScale" 2

	endif

	if iMouseover != GetUIFloat "StartMenu/MCM/*:1/_optionID"		;7 - MOUSE-OVER
		set iMouseover to GetUIFloat "StartMenu/MCM/*:1/_optionID"
		if iMouseover
			SetUIFloat "StartMenu/MCM/MCM_Info/visible" 1

			; "StartMenu/MCM/*:9" is short for "StartMenu/MCM/MCM_Info"
			if iSubMenu == 1
				if iMouseover == 1
					SetUIString "StartMenu/MCM/*:9/string" "Click this to access the Bag of Holding in order to view its contents and/or exchange specific items."
				else
					SetUIFloat "StartMenu/MCM/MCM_Info/visible" 0
				endif
			elseif iSubMenu == 2
				if iMouseover == 1
					SetUIString "StartMenu/MCM/*:9/string" "Click this to deposit ALL caps and non-quest items from your inventory into the Bag of Holding."
				elseif iMouseover == 2
					SetUIString "StartMenu/MCM/*:9/string" "Click this to deposit all caps from your inventory into the Bag of Holding."
				elseif iMouseover == 3
					SetUIString "StartMenu/MCM/*:9/string" "Click this to deposit all armor from your inventory into the Bag of Holding."
				elseif iMouseover == 4
					SetUIString "StartMenu/MCM/*:9/string" "Click this to deposit all skill books from your inventory into the Bag of Holding."
				elseif iMouseover == 5
					SetUIString "StartMenu/MCM/*:9/string" "Click this to deposit all miscellaneous items from your inventory into the Bag of Holding."
				elseif iMouseover == 6
					SetUIString "StartMenu/MCM/*:9/string" "Click this to deposit all weapons from your inventory into the Bag of Holding."
				elseif iMouseover == 7
					SetUIString "StartMenu/MCM/*:9/string" "Click this to deposit all ammunition from your inventory into the Bag of Holding."
				elseif iMouseover == 8
					SetUIString "StartMenu/MCM/*:9/string" "Click this to deposit all consumable/aid items (except for skill books and quest items) from your inventory into the Bag of Holding."
				else
					SetUIFloat "StartMenu/MCM/MCM_Info/visible" 0
				endif
			elseif iSubMenu == 3
				if iMouseover == 1
					SetUIString "StartMenu/MCM/*:9/string" "Click this to withdraw ALL caps and non-quest items from the Bag of Holding into your inventory."
				elseif iMouseover == 2
					SetUIString "StartMenu/MCM/*:9/string" "Click this to withdraw all caps from the Bag of Holding into your inventory."
				elseif iMouseover == 3
					SetUIString "StartMenu/MCM/*:9/string" "Click this to withdraw all armor from the Bag of Holding into your inventory."
				elseif iMouseover == 4
					SetUIString "StartMenu/MCM/*:9/string" "Click this to withdraw all skill books from the Bag of Holding into your inventory."
				elseif iMouseover == 5
					SetUIString "StartMenu/MCM/*:9/string" "Click this to withdraw all miscellaneous items from the Bag of Holding into your inventory."
				elseif iMouseover == 6
					SetUIString "StartMenu/MCM/*:9/string" "Click this to withdraw all weapons from the Bag of Holding into your inventory."
				elseif iMouseover == 7
					SetUIString "StartMenu/MCM/*:9/string" "Click this to withdraw all ammunition from the Bag of Holding into your inventory."
				elseif iMouseover == 8
					SetUIString "StartMenu/MCM/*:9/string" "Click this to withdraw all consumable/aid items (except for skill books and quest items) from the Bag of Holding into your inventory."
				else
					SetUIFloat "StartMenu/MCM/MCM_Info/visible" 0
				endif
			elseif iSubMenu == 4
				if iMouseover == 1
					SetUIString "StartMenu/MCM/*:9/string" "Activate this to prevent the category-based bulk deposit features from removing hotkeyed items from your inventory."
				elseif iMouseover == 2
					SetUIString "StartMenu/MCM/*:9/string" "Activate this to prevent the category-based bulk deposit features from removing equipped items from your inventory."
				else
					SetUIFloat "StartMenu/MCM/MCM_Info/visible" 0
				endif
			else
				SetUIFloat "StartMenu/MCM/MCM_Info/visible" 0
			endif
		else
			SetUIFloat "StartMenu/MCM/MCM_Info/visible" 0
		endif

	endif
endif
end

 

 

I've tried commenting out the checks relating to whether or not hotkeyed and/or equipped items should be protected, so I know there's no problem there. It has to be something I'm doing with the FormList.

Link to comment
Share on other sites

The only thing I can think of is that the exception formlist parameter to RemoveAlltypedItems is required to be a formlist containing only base forms. Before adding anything to that list, I'd check if it's a base form and if not, gets its base and then add that.
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...