javaplaza Posted July 18, 2019 Share Posted July 18, 2019 (edited) So I'm writing a quest where the stage will only advance if you can perform a certain few spells. 7 to be exact. I have this script attached to the target's alias in the quest, and it functions properly, but only for one of the seven spells needed. Can someone please guide me on how I can add the other 6 into the script? int property myStage auto quest property myQuest auto magiceffect property myEffect auto Event OnMagicEffectApply(ObjectReference akCaster, MagicEffect akEffect) if akCaster == Game.GetPlayer() if akEffect == myEffect myQuest.setStage(myStage) endif endif endEvent What I'm trying to avoid doing is this:(unless it looks correct, id really appreciate it if someone would let me know if it does.. thanks) int property myStage auto quest property myQuest auto magiceffect property Effect001 auto magiceffect property Effect002 auto magiceffect property Effect003 auto magiceffect property Effect004 auto magiceffect property Effect005 auto magiceffect property Effect006 auto magiceffect property Effect007 auto Event OnMagicEffectApply(ObjectReference akCaster, MagicEffect akEffect) if akCaster == Game.GetPlayer() if akEffect == Effect001 myQuest.setStage(myStage) endif if akEffect == Effect002 myQuest.setStage(myStage) endif if akEffect == Effect003 myQuest.setStage(myStage) endif if akEffect == Effect004 myQuest.setStage(myStage) endif if akEffect == Effect005 myQuest.setStage(myStage) endif if akEffect == Effect006 myQuest.setStage(myStage) endif if akEffect == Effect007 myQuest.setStage(myStage) endif endif endEvent Edited July 18, 2019 by javaplaza Link to comment Share on other sites More sharing options...
ReDragon2013 Posted July 18, 2019 Share Posted July 18, 2019 (edited) maybe next is working for you xyzSampleAliasScript Scriptname xyzSampleAliasScript extends ReferenceAlias ; https://forums.nexusmods.com/index.php?/topic/7826293-multiple-if-statements/ ; https://www.creationkit.com/index.php?title=GetOwningQuest_-_Alias Quest PROPERTY myQuest auto ; the quest, maybe not needed Int PROPERTY myStage auto ; the stage you like to set MagicEffect[] PROPERTY myList auto ; pre-filled array of magicEffects Bool[] PROPERTY myEffect auto ; pre-filled with False, has to be the same length as array from above ; -- EVENT -- EVENT OnInit() Debug.Trace(" OnInit() - has been reached.. " +self) ; info only for papyrus log ENDEVENT EVENT OnMagicEffectApply(ObjectReference akCaster, MagicEffect akEffect) IF (akCaster == Game.GetPlayer() as ObjectReference) myF_TryStage(akEffect) ENDIF ENDEVENT ; -- FUNCTION -- ;------------------------------------------ FUNCTION myF_TryStage(MagicEffect akEffect) ;------------------------------------------ ; "where the stage will only advance if you can perform a certain few spells. 7 to be exact." IF (myQuest) && myQuest.IsRunning() && (myList) && (myEffect.Length == myList.Length) ELSE RETURN ; - STOP - missing quest property OR quest is not running OR different array lengths ENDIF ;--------------------- int i = myList.Length WHILE (i) ; (i > 0) i = i - 1 IF (myList[i] == akEffect) myEffect[i] = TRUE ; set TRUE for matching effect i = -1 ; edit 21.07.2019 ENDIF ENDWHILE IF (i == 0) ELSE RETURN ; - STOP - current effect is not desired for monitoring ENDIF ;--------------------- WHILE (i < myEffect.Length) IF myEffect[i] ELSE RETURN ; - STOP - at least one effect is currently not applied ENDIF ; ---------------------- i = i + 1 ENDWHILE myQuest.setStage(myStage) ; set stage, if all effects were found ENDFUNCTION There is another way with changing a GlobalVariable, but I would like to prefer above. Edited July 21, 2019 by ReDragon2013 Link to comment Share on other sites More sharing options...
javaplaza Posted July 18, 2019 Author Share Posted July 18, 2019 thank you so much but some of this is pretty over my head currently. can i do this without using an array? Link to comment Share on other sites More sharing options...
TobiaszPL Posted July 18, 2019 Share Posted July 18, 2019 Scriptname QLG_Script_Tests extends ObjectReference FormList Property QEffectList Auto int Property QStage auto Quest Property QQuest auto Event OnMagicEffectApply( ObjectReference QCaster, MagicEffect QEffect ) If( EffectFC() ) QQuest.SetStage( QStage ) EndIf EndEvent Bool Function EffectFC() int i = 0 int Size = QEffectList.GetSize() While( i < Size ) If( QEffect == QEffectList.GetAt( i ) ) Return true EndIf i += 1 EndWhile Return False EndFunction NOT TESTED !... Bad because:- Form List are slow- anything more? Good because:- in any time you can expand Form List with new effects- less code... but who cares about how long code is :x... if you don't want many lines of If If If If If you can use loop and Arrays / FormListsArrays are much faster but you need to convert FormList to Array first :x... Link to comment Share on other sites More sharing options...
javaplaza Posted July 18, 2019 Author Share Posted July 18, 2019 Tobiaz your code helps me understand the list a lot better.. that is where I'm a little nervous. But if I read what you said after correctly, do you think my long code above would run? I also haven't tested it. Link to comment Share on other sites More sharing options...
javaplaza Posted July 18, 2019 Author Share Posted July 18, 2019 Tobiaz : your code came back with: (6,28): required (...)+ loop did not match anything at input 'auto'(6,32): mismatched input '\\r\\n' expecting STATENo output generated for DFLShoutTrigger, compilation failed. Link to comment Share on other sites More sharing options...
TobiaszPL Posted July 18, 2019 Share Posted July 18, 2019 Fixed: Scriptname QLG_Script_Tests extends MagicEffect FormList Property QEffectList Auto int Property QStage auto Quest Property QQuest auto Event OnMagicEffectApply( ObjectReference QCaster, MagicEffect QEffect ) If( EffectFC( QEffect ) ) QQuest.SetStage( QStage ) EndIf EndEvent Bool Function EffectFC( MagicEffect QEffect) int i = 0 int Size = QEffectList.GetSize() While( i < Size ) If( QEffect == QEffectList.GetAt( i ) ) Return true EndIf i += 1 EndWhile Return False EndFunction This code compile for me fine... Show full code that you try to compile... Link to comment Share on other sites More sharing options...
javaplaza Posted July 18, 2019 Author Share Posted July 18, 2019 first error was because QEffect isn't defined. Link to comment Share on other sites More sharing options...
TobiaszPL Posted July 18, 2019 Share Posted July 18, 2019 Y i know :Pnow it is defined :) Bool Function EffectFC( MagicEffect QEffect) Link to comment Share on other sites More sharing options...
javaplaza Posted July 18, 2019 Author Share Posted July 18, 2019 my code at the top actually seems to run so far. i hadn't felt confident enough to test it. Link to comment Share on other sites More sharing options...
Recommended Posts