candlepin Posted February 28, 2017 Author Share Posted February 28, 2017 Ok, found out what one of the issues was; the Magic Skill section of the Magic Effect must be set to something other than None. The spell now can be added via the console, but is not automatically added by the quest alias (at least as I have it set up now). Link to comment Share on other sites More sharing options...
candlepin Posted February 28, 2017 Author Share Posted February 28, 2017 (edited) My spell works now - kind of. I can get the spell to fire but it doesn't toggle. I tried to go with the GlobalVariable.Mod() route, but the only way I could think to do that with a toggle was to have one If statement use GlobalVariable.Mod(1) and the ElseIf use GlobalVariable.Mod(-1). Does this work? Or should I instead go with GlobalVariable.SetValue(0) instead of GlobalVariable.Mod(-1)? Â Also, the spell still isn't being added on startup yet. Edited February 28, 2017 by candlepin Link to comment Share on other sites More sharing options...
candlepin Posted March 1, 2017 Author Share Posted March 1, 2017 Update: the spell is now added automatically! Now I just have to fix this annoying lack of toggling. If engineer has advice on changing a global variable from 0 to 1 and back, I'm all ears. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 1, 2017 Share Posted March 1, 2017 You can go about it in two ways:Â A single script where you set or modify the global variable while also checking for the value of that variable. If MyGV.GetValue() = 0.0 ;do stuff MyGV.SetValue(1.0) Else ;do stuff MyGV.SetValue(0.0) EndIfTwo magic effects on the spellOne conditioned for the global variable to be at 0 while the other at 1. Then you have two separate scripts, one for each effect ;do stuff MyGV.SetValue(1.0) ;do stuff MyGV.SetValue(0.0)If you want to use ModValue instead of SetValue, you can. There is nothing wrong either way. So long as you can be sure that the values are what you want when you want them, it'll be fine. Link to comment Share on other sites More sharing options...
candlepin Posted March 1, 2017 Author Share Posted March 1, 2017 I'm slightly rethinking my approach to this mod. Previously I had two scripts attached to a quest via alias: one to give the player the spell (this is now working) and a second that should switch items as they are added to the inventory and also that swaps out the inventories. A third script is then added to a magic effect, which is added to the spell. The third script allows for the global variable to be switched (this is also working; checked by console). I'm thinking that it might be better to split my second script in two; keep the part of the script that switches OnItemAdded associated with the quest, but merge the OnInit part (swapping out inventory items) with the third script that is associated with the spell (should only need to switch out inventories when spell is cast - as long as the other scripts are working properly). Thoughts? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 1, 2017 Share Posted March 1, 2017 You can probably do that. Initial state of items will be whatever they are from all the other mods, but that should be fine. Link to comment Share on other sites More sharing options...
candlepin Posted March 3, 2017 Author Share Posted March 3, 2017 I have a good chunk of the mod working now. The spell is added to the player. The spell works properly (switches global variable). When global variable is switched, items picked up are the correct form (when GV = 0 items are "ingredient" form, when GV = 1 items are "vanilla" form). The only part of the mod that isn't working is the inventory switching. I started with IsharaMeradin's script (modified from FrankFamily) and swapped out variable/global variable names.  I'm not sure where the issue is, but I think there may be a problem either with the OnInit or the second function. Can't seem to put my finger on it.   Scriptname CP_MI_swap extends ReferenceAlias {script for swapping out items} FormList property CP_VanillaItems auto FormList property CP_MissingIngredients auto ObjectReference property PlayerRef auto GlobalVariable property CP_GV_swap auto Bool Swap = false Event OnInit() If CP_GV_swap.GetValue() == 0 && Swap == false Swap = true RemoveInventoryEventFilter(CP_MissingIngredients) AddInventoryEventFilter(CP_VanillaItems) SwapItemsInventory(CP_VanillaItems,CP_MissingIngredients) ElseIf CP_GV_swap.GetValue() == 1 && Swap == false Swap = true RemoveInventoryEventFilter(CP_VanillaItems) AddInventoryEventFilter(CP_MissingIngredients) SwapItemsInventory(CP_MissingIngredients,CP_VanillaItems) Else Debug.Notification("Something has gone wrong") EndIf EndEvent Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) If CP_GV_swap.GetValue() == 0 SwapItemsAdded(akBaseItem, aiItemCount, CP_VanillaItems, CP_MissingIngredients) ElseIf CP_GV_swap.GetValue() == 1 SwapItemsAdded(akBaseItem, aiItemCount, CP_MissingIngredients, CP_VanillaItems) EndIf EndEvent Function SwapItemsAdded(Form ItemA, Int Num, FormList ListA, FormList ListB) Int i = ListA.Find(ItemA) If i > -1 Form ItemB = ListB.GetAt(i) As Form PlayerRef.RemoveItem(ItemA, Num, true) PlayerRef.AddItem(ItemB, Num, true) Endif EndFunction Function SwapItemsInventory(FormList ListA, FormList ListB) If PlayerRef.GetItemCount(ListA) Int i = ListA.GetSize() while i i -= 1 Form ItemA = ListA.GetAt(i) As Form int Count = PlayerRef.GetItemCount(ItemA) If Count Form ItemB = ListB.GetAt(i) As Form PlayerRef.RemoveItem(ItemA, Count, True) PlayerRef.AddItem(ItemB, Count, True) Endif EndWhile EndIf EndFunction   Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 3, 2017 Share Posted March 3, 2017 (edited) The problem is indeed with the OnInit event. It only fires when the quest is first loaded, which is fine for an initial swap, and is what you initially talked about. But for swapping on demand, it fails. Since you are using a spell, break it down into two scripts. One on the player alias that adjusts items as added. One on a magic effect added to the spell which changes the inventory.  ;**************************** ;** reference alias script ** ;**************************** Scriptname CP_MI_swap extends ReferenceAlias {script for swapping out items} FormList property CP_VanillaItems auto FormList property CP_MissingIngredients auto GlobalVariable property CP_GV_swap auto Actor PlayerRef ;using a local ref - can use property if you prefer Event OnInit() PlayerRef = Self.GetReference() ;if using property remove this line AddInventoryEventFilter(CP_VanillaItems) AddInventoryEventFilter(CP_MissingIngredients) EndEvent Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) If CP_GV_swap.GetValue() == 0 SwapItemsAdded(akBaseItem, aiItemCount, CP_VanillaItems, CP_MissingIngredients) ElseIf CP_GV_swap.GetValue() == 1 SwapItemsAdded(akBaseItem, aiItemCount, CP_MissingIngredients, CP_VanillaItems) EndIf EndEvent Function SwapItemsAdded(Form ItemA, Int Num, FormList ListA, FormList ListB) Int i = ListA.Find(ItemA) If i > -1 Form ItemB = ListB.GetAt(i) As Form PlayerRef.RemoveItem(ItemA, Num, true) PlayerRef.AddItem(ItemB, Num, true) Endif EndFunction ;************************* ;** magic effect script ** ;************************* ScriptName SomeScript Extends MagicEffect FormList property CP_VanillaItems auto FormList property CP_MissingIngredients auto GlobalVariable property CP_GV_swap auto Actor PlayerRef ;using a local ref - can use property if you prefer Event OnEffectStart(Actor akTarget, Actor akCaster) If CP_GV_swap.GetValue() == 0 SwapItemsInventory(CP_VanillaItems,CP_MissingIngredients) ElseIf CP_GV_swap.GetValue() == 1 SwapItemsInventory(CP_MissingIngredients,CP_VanillaItems) Else Debug.Notification("Something has gone wrong") EndIf EndEvent Function SwapItemsInventory(FormList ListA, FormList ListB) PlayerRef = Game.GetPlayer() ; if you use a property for playerref delete this line If PlayerRef.GetItemCount(ListA) Int i = ListA.GetSize() while i i -= 1 Form ItemA = ListA.GetAt(i) As Form int Count = PlayerRef.GetItemCount(ItemA) If Count Form ItemB = ListB.GetAt(i) As Form PlayerRef.RemoveItem(ItemA, Count, True) PlayerRef.AddItem(ItemB, Count, True) Endif EndWhile EndIf EndFunction   EDIT: Forgot inventory event filters, added them in. Note that it just applies both filters. This makes coding easier but does cause the event to trigger twice per item. Once for the picked up version and again for the version it is transformed into. Should not be an issue with a small number of items. If it proves to be a problem, there is a way to swap the filters on demand. But lets only do that if necessary. Edited March 3, 2017 by IsharaMeradin Link to comment Share on other sites More sharing options...
candlepin Posted March 6, 2017 Author Share Posted March 6, 2017 I have a question about FormLists; can an item be on the same form list more than once? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 6, 2017 Share Posted March 6, 2017 I have a question about FormLists; can an item be on the same form list more than once? As I understand it, an item cannot be on the same form list multiple times. At least that is what the AddForm function indicates. You can test in the CK if manually adding the same object multiple times works or not. Link to comment Share on other sites More sharing options...
Recommended Posts