dcmn Posted August 26, 2020 Share Posted August 26, 2020 Hi all. I'm trying to create a script that casts something whenever the player uses a scroll: Scriptname dinCastOnScrollCast extends ReferenceAlias event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer) if akBaseItem.HasKeyword(VendorItemScroll) && !akDestContainer && !akItemReference && aiItemCount == 1 dinSpell.Cast(PlayerRef as objectreference, none) endif endEvent spell property dinSpell auto actor property PlayerRef auto keyword property VendorItemScroll auto It works just fine except for the fact that it only triggers when the scroll used is the last scroll of its type in the player's inventory. If I have 5 scrolls of the same type, the first four casts do nothing, but the final cast will have the desired effect. How can I ensure that the effect will trigger for each scroll in a stack, not just the last? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted August 26, 2020 Share Posted August 26, 2020 Have you tested without using the aiItemCount in the condition statement? After all, you can only cast one scroll at a time from each hand. The check kinda seems pointless. Link to comment Share on other sites More sharing options...
dcmn Posted August 26, 2020 Author Share Posted August 26, 2020 I have, yes. I've tried just about every configuration I could think of. Another thing is that I'm able to get the event to trigger correctly if I remove the scrolls by dropping them on the ground individually.It seems that casting the scrolls doesn't necessarily "remove" them in the same way that dropping them does. Link to comment Share on other sites More sharing options...
testiger2 Posted August 26, 2020 Share Posted August 26, 2020 (edited) Instead of OnItemRemoved() you could just use OnSpellCast() this event will fire for scrolls something like this could work for you Keyword Property VendorItemScroll Auto int iScrollCount = 0 Event OnObjectEquipped(Form akBase, ObjectReference akRef) if akBase.HasKeyword(VendorItemScroll) iScrollCount += 1 if iScrollCount > 0 && GetState() == "" GoToState("ScrollState") endif endif EndEvent Event OnObjectUnequipped(Form akBase, ObjectReference akRef) if akBase.HasKeyword(VendorItemScroll) iScrollCount -= 1 if iScrollCount == 0 && GetState() == "ScrollState" GoToState("") endif endif EndEvent State ScrollState Event OnSpellCast(Form akSpell) if akSpell.HasKeyword(VendorItemScroll) ;do stuff here endif EndEvent EndState Note that you could just use OnSpellCast() alone but i added in some state tracking so you don't overrun the papyrus engine by checking everey spell cast but only when the player has actually equipped a scroll.The OnObjectUnequipped() event will fire when the player used up all spells/scrolls in the equipped slot Edited August 26, 2020 by testiger2 Link to comment Share on other sites More sharing options...
dcmn Posted August 26, 2020 Author Share Posted August 26, 2020 I would never have known to do all that with the state tracking, thank you! Regarding the OnSpellCast() event, that's what I tried to use at first, but to no avail. I am able to trigger the OnSpellCast() event with spells, but not with scrolls. When I use event OnSpellCast(Form akSpell) if akSpell.HasKeyword(MagicInfluence) ;do stuff here endif endeventI am able to trigger the event with a spell like Fury which has the "MagicInfluence" keyword. If I then use the Fury scroll which has the same keyword, it ceases to work. Typing player.SpellHasKeyword right MagicInfluence in the console with the scroll equipped returns 1, as does player.SpellHasKeyword right VendorItemScroll. When the OnSpellCast() event is properly triggered by a spell with the "MagicInfluence" keyword, but not by the scroll with the same keyword, I reasoned that OnSpellCast() does not check scrolls. I hope I'm wrong, but I've knocked my head against this problem for hours. The wiki page on OnSpellCast() says: "Can be Spell, Enchantment, Potion, or Ingredient" After that I tried using OnItemRemoved() to minimal success. Link to comment Share on other sites More sharing options...
testiger2 Posted August 27, 2020 Share Posted August 27, 2020 (edited) Well i found out that even though OnSpellCast() fires from using scrolls it will always receive a 'none' as the argument.So you can't just use it the regular way. i created a workaround using GetItemCount(). Its an unelegant solution , dirty, i would dare to call it filthy, but it should work (not tested it though) [spoiler] Actor Property PlayerRef Auto Formlist Property usedScrollsFLST Auto ; create this and give unique name in the CK Form[] usedScrollsArr int[] usedScrollCount int iCurrScrollCount = 0 Event OnInit() usedScrollsArr = new Form[4] ;4possible quip types usedScrollCount = new int[4] EndEvent Event OnObjectEquipped(Form akBase, ObjectReference akRef) if akBase as scroll int i = usedScrollsArr.Find(akBase) if i < 0 i = usedScrollsArr.Find(none) endif usedScrollsArr[i] = akBase usedScrollCount[i] = usedScrollCount[i] + 1 usedScrollsFLST.AddForm(akBase) iCurrScrollCount = PlayerRef.GetItemCount(usedScrollsFLST) if usedScrollsFLST.GetSize() > 0 && GetState() == "" GoToState("ScrollState") endif endif EndEvent Event OnObjectUnequipped(Form akBase, ObjectReference akRef) if akBase as scroll Utility.Wait(0.1) ;give OnSpellCast() time to fire int i = usedScrollsArr.Find(akBase) if i >= 0 usedScrollCount[i] = usedScrollCount[i] - 1 if usedScrollCount[i] == 0 usedScrollsArr[i] = none usedScrollsFLST.RemoveAddedForm(akBase) endif endif if usedScrollsFLST.GetSize() == 0 && GetState() == "ScrollState" GoToState("") endif endif EndEvent State ScrollState Event OnSpellCast(Form akSpell) int iOldCnt = iCurrScrollCount iCurrScrollCount = PlayerRef.GetItemCount(usedScrollsFLST) if iOldCnt > iCurrScrollCount ; we casted a scroll ;do stuff here endif EndEvent EndState [/spoiler] Because of DualWiedling and because of a bug in IsEquipped() that doesn't let you track items in the off hand properly(yeah why would anything work like its supoosed to...) i created this array setup that should in theory respect and track dualwielding the same or different kind of scrolls properly Edited August 27, 2020 by testiger2 Link to comment Share on other sites More sharing options...
dcmn Posted August 27, 2020 Author Share Posted August 27, 2020 That worked 100%, thank you. It's the solution I needed, which is as elegant as it ever needs to be. Link to comment Share on other sites More sharing options...
Recommended Posts