jbfilms1 Posted February 21, 2017 Share Posted February 21, 2017 Is there a way to add items/spells/perks/etc. via a MCM menu, if so could I get an example of the code? Thanks Link to comment Share on other sites More sharing options...
IsharaMeradin Posted February 21, 2017 Share Posted February 21, 2017 One solution I have seen is to add the items when the option is turned on and take them away when the option is turned off. Both within the OnOptionSelect event. However, that can cause issues with the MCM menu system if some of those commands are latent. Ever have a MCM menu that stops showing options in one mod after you have been in menus for other mods? Its an issue that is related to calling certain commands within the MCM system. It is better therefore to keep track of the user's choices and perform such tasks when the menu closes. Even so, it is still a good idea to suggest that users set options and then fully exit the MCM system back to the game. The following bit of code that I am sharing uses this approach. Without the full script it may not be clear what is going on. Basically, I used arrays to store user choices and then cycle those arrays after the menu closes and perform various tasks as needed. Event OnUpdate() Debug.Notification("$Inventory Management System: Processing Data") UnRegisterForAllKeys() Int MAK = abim_IMS_ModActKeyGV.GetValue() as Int If MAK != -1.0 RegisterForKey(MAK) EndIf Int ix = abim_IMS_SupplyQuestList.GetSize() - 1 While ix >= 0 Float svi = ComponentChoice[ix] as Float (abim_IMS_ComponentGVList.GetAt(ix) as GlobalVariable).SetValue(svi) If ComponentChoice[ix] != 0 If (abim_IMS_SupplyQuestList.GetAt(ix) as Quest).IsRunning() == false (abim_IMS_SupplyQuestList.GetAt(ix) as Quest).Start() EndIf Else If (abim_IMS_SupplyQuestList.GetAt(ix) as Quest).IsRunning() == true (abim_IMS_SupplyQuestList.GetAt(ix) as Quest).Stop() (abim_IMS_ModContainers.GetAt(ix) as ObjectReference).RemoveAllItems(PlayerRef) Form TheRepItem = abim_IMS_RepItemList.GetAt(ix) PlayerRef.RemoveItem(TheRepItem,1,true) EndIf EndIf Float svx = AutoStoreChoice[ix] as float (abim_IMS_AutoStoreGVList.GetAt(ix) as GlobalVariable).SetValue(svx) If WeightlesActive[ix] == false (abim_IMS_WeightlessGVList.GetAt(ix) as GlobalVariable).SetValue(0.0) Else (abim_IMS_WeightlessGVList.GetAt(ix) as GlobalVariable).SetValue(1.0) EndIf If MerchExclActive[ix] == false (abim_IMS_MerchExcludeGVLIst.GetAt(ix) as GlobalVariable).SetValue(0.0) Else (abim_IMS_MerchExcludeGVLIst.GetAt(ix) as GlobalVariable).SetValue(1.0) EndIf If RedoItemsActive[ix] == true RedoItemsActive[ix] = false RebuildFormList((abim_IMS_MasterItemList.GetAt(ix) as FormList),(abim_IMS_ModContainers.GetAt(ix) as ObjectReference)) EndIf ix -= 1 EndWhile If ComponentChoice[9] != 0 && AutoStoreChoice[9] == 2 abim_IMS_OrderedArrowList.Revert() Int z = 0 While z < ArrowMaster.GetSize() Int y = -1 If z < ArrowArrayIndex.length y = ArrowArrayIndex[z] - 1 EndIf If y != -1 Form Entry = ArrowMaster.GetAt(y) If Entry as Ammo If !(abim_IMS_OrderedArrowList.HasForm(Entry)) abim_IMS_OrderedArrowList.AddForm(Entry) EndIf If !(PlayerRef.IsEquipped(Entry)) PlayerRef.RemoveItem(Entry,PlayerRef.GetItemCount(Entry),true,(abim_IMS_ModContainers.GetAt(9) as ObjectReference)) EndIf EndIf EndIf z += 1 EndWhile EndIf If ComponentChoice[10] != 0 && AutoStoreChoice[10] == 2 abim_IMS_OrderedBoltList.Revert() Int x = 0 While x < BoltMaster.GetSize() Int y = -1 If x < BoltArrayIndex.length y = BoltArrayIndex[x] - 1 EndIf If y != -1 Form Entry = BoltMaster.GetAt(y) If Entry as Ammo If !(abim_IMS_OrderedBoltList.HasForm(Entry)) abim_IMS_OrderedBoltList.AddForm(Entry) EndIf If !(PlayerRef.IsEquipped(Entry)) PlayerRef.RemoveItem(Entry,PlayerRef.GetItemCount(Entry),true,(abim_IMS_ModContainers.GetAt(10) as ObjectReference)) EndIf EndIf EndIf x += 1 EndWhile EndIf Debug.Notification("$Inventory Management System: Processing Complete") EndEvent Event OnConfigClose() RegisterForSingleUpdate(0.1) EndEvent Link to comment Share on other sites More sharing options...
Recommended Posts