Jump to content

[LE] OnSpellCast not firing


javaplaza

Recommended Posts

 

 

Yes, the code looks like it should execute. Albeit it's wordy; I'd stick the spells in a FormList, use HasForm on that FormList, and then have just one if statement. Alternatively, if you want the explicit list in the properties instead (I don't think it's good practice, but whatever), I'd bundle the repeated

 

i dont know what that would look like, but i sure would love to try it out!

 

 

Functions are things like the SetStage() call you're making; you can define your own custom functions with whatever arguments you choose and up to one return value. In this case you'd want something like

 

 

Function AdvanceStage()
    debug.messagebox("Success!")
    Utility.Wait(0.2)
    targetNPC.ForceActorValue("Aggression", 0)
    targetNPC.StopCombat()
EndFunction

 

And then your if statements would just look like:

 

 

if spellCast
      if spellCast == SPELL001 || spellCast == SPELL002 || spellCast == SPELL003 (...etc)
              AdvanceStage()
       endif
endif

 

This structure of the if statements also avoids having to write your code again and again, so the function is redundant, but it's often good practice to subdivide tasks like this anyway. Further, and the reason I go back to the formlist, a formlist approach means any time you want to change the spells you're interested in, you don't need to alter your code nor to fill properties.

 

So you'd get the code down to

 

 

if spellCast
      if spellList.HasForm(spellCast)
              AdvanceStage()
       endif
endif

 

You want the check of whether you're in the correct stage of the quest to be done early, to avoid any of the other processing and avoid race conditions (e.g. a player fires off two spells more or less simultaneously), and you want it to be done only once, since it isn't going to change in any of the cases (which should probably be structured as if-elseifs in order to make the branches all mutually exclusive).

There are some more sophisticated ways to do this that have advantages, involving script states, but the simplest one is to add a property that stores the stage the quest the quest needs to be in when you care about this, and then go:

 

 

if myQuest.GetStage() != TargetStage
    return
endif

 

right at the very start of the OnSpellCast() event.

Link to comment
Share on other sites

you, sir... are.. amazing.

the script is firing once i added the debug.message to the top. no idea how that caused the REST of it to start working as well, but... on top of it, youve taught me how to simplify it further and this is going to be so useful later, for me.

 

So... Thank you.

Link to comment
Share on other sites

this might help explain further, what im trying to do.. but.. i tried it and it doesn't work. ill read over your post again , i must have missed something.


if spellCast && myQuest.GetStage()
      if spellList.HasForm(spellCast)
              AdvanceStage()
       endif
endif
Edited by javaplaza
Link to comment
Share on other sites

i did a little reading and got it working... but mostly thanks to you. I couldn't be happier

Thanks foamy! Heres the final code

Scriptname DFLTOSpellPass extends ReferenceAlias  

quest property myquest auto
formlist property spellList auto
actor property targetNPC auto


Function AdvanceStage()
    myQuest.setstage(20)
    debug.messagebox("Success!")
    Utility.Wait(0.2)
    targetNPC.ForceActorValue("Aggression", 0)
    targetNPC.StopCombat()
EndFunction


Event OnSpellCast(Form akSpell)
  Spell spellCast = akSpell as Spell
	if spellcast && (myQuest.Getstage() == 11)
      		if spellList.HasForm(spellCast)
              AdvanceStage()
       	endif
	endif
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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