Jump to content

[LE] Multiple If Statements


Recommended Posts

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 by javaplaza
Link to comment
Share on other sites

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 by ReDragon2013
Link to comment
Share on other sites

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 / FormLists
Arrays are much faster but you need to convert FormList to Array first :x...
Link to comment
Share on other sites

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

  • Recently Browsing   0 members

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