Jump to content

Detecting Spell Cast


Recommended Posts

Hi there,

 

So I need to be able to do something when I detect that a spell has been cast (could be any spell, it doesn't matter), and I have been looking at the OnSpellCast Event in the CK documentation:

https://www.creationkit.com/index.php?title=OnSpellCast_-_ObjectReference

 

I'm following the example pretty closely -- it seems like it's just returning a true/false, but doesn't seem to be registering in game. Is there a step that's missing -- should I be doing a bool Event?

 

Event OnSpellCast(Form akSpell)
Spell spellCast = akSpell as Spell
if spellCast
_debug("Spell was cast")
endif
EndEvent

Link to comment
Share on other sites

Is that _ a typo in the post or the script? It should catch any casts, though I like to listen to specific ones. If the form cast isn't a spell, it will return none.

Spell property thisSpell auto
 
Event OnSpellCast(Form akSpell)
    Spell spellCast = akSpell as Spell
    if spellCast == thisSpell
       ; do fun stuff
    endif
EndEvent

Edited by AnishaDawn
Link to comment
Share on other sites

Thanks for replying -- that's just a shorthand way for debugging in the script -- it's handled via a debug mode function....

 

Doh! I foolishly forgot to add the Spell property up top, but even once added still doesn't seem to be calling the notification. I should have specified that I am trying to detect any spell cast by the player, not any spell in general.... I am guessing that may change some things. This particular script is set up as:

Scriptname ModName Main extends Quest

There's a handler for events in another file using the below, and I notice all "ak" references (akBaseItem, akItemReference) are changed to simple references (item, ref)

Scriptname ModNamePlayerAlias extends ReferenceAlias Conditional

ModNameMain Property main Auto

Event OnItemAdded(Form item, int count, ObjectReference ref, ObjectReference src)
    main.handle_added_item(item, count, ref, src)
EndEvent

Could it be I need to use another name for akSpell instead?

Link to comment
Share on other sites

The compiler doesn't care about the names of the arguments, it just cares that the order and name of the types aren't changed.

I've just gone in the game and tested this to see if I could reproduce your situation. All of these worked as expected:

Event OnSpellCast(Form akSpell)
    if akSpell
        debug.notification("Spell cast.")
    endif
EndEvent
 
;=== test 2====
Event OnSpellCast(Form akSpell)
    if (akSpell as Spell)
        debug.notification("Spell cast.")
   endif
EndEvent
 
;=== test 3====
Event OnSpellCast(Form akSpell)
    if (akSpell as Spell) != none
        debug.notification("Spell cast.")
    endif
EndEvent
Edited by AnishaDawn
Link to comment
Share on other sites

Yeah, the playeralias script is where all the other Event calls are housed, and they pass on to a handler function in the main Quest script -- that's probably where the rub is. I'll keep playing and see if I can just get the dang debug notification to show. Thanks Anisha! :)

Link to comment
Share on other sites

  • Recently Browsing   0 members

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