Jump to content

[LE] OnSpellCast Event question


GSGlobe

Recommended Posts

Hi there!

 

I have a question.

 

Is it possible to have a spell as this;

EVENT OnEffectStart(Actor akTarget, Actor akCaster)

GotoState("Spell")

EndEvent

 

State Spell
EVENT OnSpellCast(Form akSpell)

 

spToCast = akSpell As Spell ;;;;<- store spell in variable

EndEvent

Endstate

 

Store the casted spell in a variable and then call this variable in another scripted spell?

 

On another scripted spell effect script;

If playerref.getactorvalue(Health) <= 50%

;;Use spToCast Variable to cast?

 

Is something like this possible?

 

I would greatly apperciate any help regarding this.
Thanks alot!

Link to comment
Share on other sites

It'd be possible, but I'm not sure of the point of the OnSpellCast catch. As you have it structured an effect will go on the actor that listens for them casting a spell, and if they do stores it, and then if their health drops below 50% (you can't use % signs, though; Papyrus will interpret that as a modulo division with no divisor and complain at you) casts it.

 

But that spell could be anything, including nothing; I don't think that'd be what you're going for? The OnSpellCast event will not catch whatever spell started the effect, so you are aware. It can only fire, in your structure, after the effect has started, which is necessarily after the casting event has already occurred.

 

If there's some specific spell you want to cast when the player's health drops below some percentage, you'd be better off feeding it into the script as a property.

Edited by foamyesque
Link to comment
Share on other sites

Hi there, thank you for your comment!

The reason why I want to store a spell (Event OnSpellCast) is that I may want to change the spell later on. My idea is simple really.

First Spell:
Store a spell using OnSpellCast event
Second Spell: With different conditions, using the stored spell.

If

cast stored spell
ElseIf

cast stored spell

ElseIf

cast stored spell

Else

Do something else.

 

I tried this:

Store Spell ME script

"myQuestScript property myScript auto"

Event OnSpellCast(Form akSpell)

myScript.StoreMySpell(akSpell)

EndEvent

This is what myQuestScript would have to store spells to a variable and return the spell for later on:

myQuestScript extends quest

Spell myStoredSpell

Function StoreMySpell(Spell akSpell)

akSpell = myStoredSpell

endfunction

Spell Function GetMySpell()

return myStoredSpell

endfunction

Release Spell ME Script:

If PlayerRef.getavpercentage(Health) <= 0.5

Spell mySpell = myScript.GetmySpell()

If mySpell ;because don't cast it if it's 'None'

PlayerRef.Cast(mySpell)

endif

endif

 

But I'm getting a error here: myScript.StoreMySpell(akSpell) D:\Steam\steamapps\common\Skyrim Special Edition\Data\Scripts\Source\temp\teststore_script.psc(6,9): type mismatch on parameter 1 (did you forget a cast?)

 

And Here: PlayerRef.Cast(Myspell) ;; cast is not a function or does not exist or something similar on my release script

 

 

 

Any ideas?

 

Thanks for the help so far and I truely appreciate any help given!

Link to comment
Share on other sites

You need to explicitly cast the akSpell from a Form type to a Spell type in order to clear the first compilation error: "myScript.StoreMySpell(akSpell as Spell)" should work.

Cast() is not a function of an ObjectReference (or Actor), but of a Spell, which is what's causing the second error. You want "mySpell.Cast(PlayerRef)" instead.

Link to comment
Share on other sites

Thank you very much for this information, couldn't find anything related to it or didn't understand how to use it properly, I'm a novice!

Would you know what the difference here is?
----------------------------
Spell Spell1

OnSpellCast

 

Spell1 = akSpell as Spell <- Here is without ()

 

-----------------------------------------

 

OnSpellCast
myScript.StoreMySpell(akSpell as Spell) <- Here akSpell as Spell is inside ()

-------------------------

If I wanted to use myScript.StoreMySpell(akSpell as Spell) variable in the same script aswell, would I have to use Spell myScript.StoremySpell above the event and then call that like this;

--- script magic ----

 

actorbase blabla = none
Spell myScript.StoremySpell

 

Event OnSpellCast (Form akSpell)

myScript.StoreMySpell(akSpell as Spell)

blabla = (Quest Property).Function(None, myScript.StoremySpell)

 

if this makes any sense to you?

 

Thanks for taking your time!

Link to comment
Share on other sites

Store Spell Script & Release Spell Script & Quest Script

 

Scriptname teststore_script extends activemagiceffectÃÂ ÃÂ

ÃÂ

auto_globalvar_script property myScript auto

ÃÂ

Event OnSpellCast(Form akSpell)

ÃÂ

debug.notification("stored your spell")

myscript.StoreMySpell(akSpell as Spell)

ÃÂ

EndEvent

----------------------------------------------------------------------------

Release Spell Magic Effect Script

----------------------------------------------------------------------------

Scriptname testrelease_script extends activemagiceffect

ÃÂ

Actor Property PlayerRef Auto

Auto_GlobalVar_Script Property myScript Auto

ÃÂ

ÃÂ

EVENT OnEffectStart(Actor akTarget, Actor akCaster)

ÃÂ

ÃÂ

Spell mySpell = myScript.GetmySpell()

myspell.cast(playerref)

Debug.Notification("Spell mySpell cast")

ÃÂ

ÃÂ

EndEvent

-------------------------------------------------------------------------------------

Quest Script

-------------------------------------------------------------------------------------

Scriptname Auto_GlobalVar_Script extends QuestÃÂ ÃÂ

ÃÂ

 

spell property test_release_spell auto

spell property test_store_spell auto

Spell myStoredSpell

ÃÂ

 

; ------------------------------------- Function to Store and Retrieve Spell ---------------------------------------

ÃÂ

Function StoreMySpell(Spell akSpell)

akSpell = myStoredSpell

endfunction

ÃÂ

Spell Function GetMySpell()

return myStoredSpell

endfunction

 

ÃÂ

The above doesn't work, any ideas?

 

It compiles but When I try IT ingame, storing a spell. The release spell doesnt cast the stored spell, nothing happens.

 

Theyre both set to fire and forget script & self

ÃÂ

Edited by GSGlobe
Link to comment
Share on other sites

Upon further testing and checking all scripts, no propeties were unset and the spell return as none so it doesnt store.

 

Edit: im out of ideas, anyone know what steps I can take or can see where the fault is or general improvements?

Edited by GSGlobe
Link to comment
Share on other sites

Upon further testing and checking all scripts, no propeties were unset and the spell return as none so it doesnt store.

 

Edit: im out of ideas, anyone know what steps I can take or can see where the fault is or general improvements?

 

You have a problem with your store function. Your code

Spell myStoredSpell
 
Function StoreMySpell(Spell akSpell)
 
    akSpell = myStoredSpell
 
endfunction
It doesn't store the spell into your local variable. It's trying to put your local variable into the passed spell variable. So try this

Spell myStoredSpell
 
Function StoreMySpell(Spell akSpell)
 
    myStoredSpell = akSpell ; the variables have swapped place
 
endfunction

Since you never properly set the local spell variable, when you retrieve it you in fact get a valid response of "None" since it was never set.

Edited by BigAndFlabby
Link to comment
Share on other sites

Thanks alot, that did wonders :)

Its working great now!

 

Now for a last question:

 

Is IT possible to also use the stored spell locally from the store spell script?

 

Event OnSpellCast(form akSpell)

 

Myscript.mystoredspell(akSpell as Spell)

 

;something like

Actor = questproperty.questfunction(none,mystoredspell) ?

 

Do I have to store a New variable?

Spell mySpell ?

Link to comment
Share on other sites

It would be so much easier to answer that if you posted actual code usage. But I think what you're asking the answer is yes. You can use the local script variable like this:

 

Spell mySavedSpell
SomeSampleQuestScript Property SomeQuest Auto
 
Function StoreTheSpell(Spell akSpell)
    mySavedSpell = akSpell
EndFunction
 
Spell Function GetStoredSpell()
    return mySavedSpell
EndFunction
 
Function DoSomethingWithSpell()
    SomeQuest.SomeQuestFunction(mySavedSpell)
EndFunction

 

If you're trying to do something from inside the OnSpellCast event you could just use akSpell as Spell. Otherwise you would need to call asking for the stored spell and need an appropriate function on the script that stores it like the GetStoredSpell() above. Then you would do it something like this

 

; not a valid code snippet. it would need to be run inside a function
SomeQuest.SomeQuestFunction(SomeValue, SpellScript.GetStoredSpell())
Link to comment
Share on other sites

  • Recently Browsing   0 members

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