Jump to content

Trigger a script when a spell is cast?


Nekoyoubi

Recommended Posts

Sorry if this isn't the right place for this, but I'm having a lot of trouble with the official Creation Kit forums (500s on anything uncached).

 

I'm trying to figure out how to trigger a script on the use of a lesser power. Namely, the mod that I'm currently working on consumes items instead of magicka, and I need to not only be able to do the conditional check of whether they have the items required (I think I have that working already), but I also need to take the actual items when it is time.

 

The first problem I'm running into with this is that the spell I'm trying to "cast" is a lesser power version of my Soul Trap Rune spell (http://skyrim.nexusmods.com/mods/37616/), but I'm hitting a snag in that the only place I know to hook the scripts is in the ActiveMagicEffect base, and in which case, the consumption effect is not happening on cast, but instead for each application (if there are any) of the Soul Trap effect.

 

Can anyone help guide me to a resource, or give me a jumping-off point in general for triggering a script at the beginning of a spell cast?

 

Thanks much in advance.

Link to comment
Share on other sites

I'm not sure what you mean by "for each application (if there are any) of the Soul Trap effect." Can you post what you already have that isn't working?

 

What I mean is that the script is getting run for all three mobs if they all are in the explosion radius of the trap (as is expected), but I do not know where to put a script to fire only once per cast (not per effected mob). As for posting what I have, I don't even know where to begin. The script itself isn't the problem; it's when the script is firing, which is set in the UI, so I don't know what to post that would help. Thanks for taking the time to read through though.

Link to comment
Share on other sites

Post inside the code & spoiler tags the scripts that you are referring to. The scripts may work, but there might be places to interrupt the action after the first process.

 

I know that I was able to interrupt and/or modify the soul trap process with my mod: http://skyrim.nexusmods.com/mods/28487 Perhaps you could do something similar?

Link to comment
Share on other sites

Post inside the code & spoiler tags the scripts that you are referring to. The scripts may work, but there might be places to interrupt the action after the first process.

 

I know that I was able to interrupt and/or modify the soul trap process with my mod: http://skyrim.nexusmods.com/mods/28487 Perhaps you could do something similar?

 

This, unfortunately, wouldn't work for me as I need to remove an item as soon as the "spell" (lesser power) is cast regardless of whether it actually gets an enemy or not. The whole point is that there is an "item cost" to using the power, not a magicka cost for casting a spell. ;(

 

For all intents and purposes, let's just say my script does nothing more than GetCasterActor().RemoveItem(SoulGemPetty) in the OnEffectStart of the ActiveMagicEffect base script. That's probably the wrong script to have it in anyway, but that's what my question was trying to solve.

Link to comment
Share on other sites

Wait, so instead of inheriting from ActiveMagicEffect like the others all seem to, I can attach a script in the "magic effect" script box that derives from ObjectReference? Checking this out now. You're a life saver! :wink: Thanks so much.

 

** EDIT **

 

;(

 

I must have missed something here. Something big. Can anyone direct me to a tutorial that involves basic "real" scripting concepts in CK. All I could ever find were tutorials on how to build a cell. I don't want to build cells; not at the moment at least. It's gameplay alteration that seems to elude my tutorial space. Save me. Please.

Edited by Nekoyoubi
Link to comment
Share on other sites

http://www.creationkit.com/Category:Papyrus -- read the pages linked on the right hand side to get an understanding of the individual parts that make up scripts.

 

There is no specific walkthrough tutorial that is only about scripting. Since scripts have to be applied to an object, most tutorials will have you create the associated object(s) first and then discuss the script part (and only within the confines of that situation).

 

Papyrus scripting has a basic structure which you can learn (see link above) but each situation is different and usually requires a different approach.

 

At any rate, you misunderstood what I stated. You wanted an item to be taken from the player when the player casts a spell. Normally for a single target spell you could apply a script to the effect as you have tried. Since your spell is an AOE, the effect is triggered once for each affected actor. That is undesirable (which you have stated). While it might be possible to interrupt the effect process as I originally suggested, it may be better to use the OnSpellCast event.

 

Since OnSpellCast is on the ObjectReference script that means that actors inherit the ability to use this event. The event has to be called on an object that does the casting (i.e. an actor, a trap, etc) rather than the effect of the spell. Therefore an alias for the player character needs to be created on a dummy quest (see quote below)

 

Excerpt from: http://www.creationkit.com/Dynamically_Attaching_Scripts

 

 

In the Object Window, navigate to Quest under the Character category. Create a new quest by right-clicking on the list and choosing 'New'. For this tutorial we will be naming the quest mymodQuest. Make sure that Start Game Enabled in the Quest Data tab is checked. Click on the Quest Alias tab, then right-click in the empty list and choose 'New Reference Alias'. We will name this alias PlayerAlias. In the Reference Alias window, under Fill Type, select the Specific Reference option and click the 'Select Forced Reference' button. Under Cell choose (any), and Ref should default to PlayerRef (Player). If not, select it from the dropdown menu.

 

 

Your script may end up being something as follows.

Scriptname SomeScript Extends ReferenceAlias

Spell Property SpellCasted Auto
SoulGem Property GemToTake Auto
Actor Property PlayerRef Auto
Int Property QtyToTake Auto

Event OnSpellCast(Form akSpell)
If akSpell == SpellCasted
PlayerRef.RemoveItem(GemToTake,QtyToTake)
EndIf
EndEvent

The only concern is: Preventing the spell from being cast when player does not have the appropriate quantity of the item. I do not know if spells can have conditions on them that prevent casting. If they can, then that is great. If not, then you are back to the drawing board as the script above removes the item when the spell has been cast. Any checks in this script would not prevent the spell from being cast as it is the casting of the spell that triggers it.

 

I suppose you could do a "chain cast"... where the player casts a spell which is caught by the script. If the player has the necessary items, then the real spell is cast. If the player does not have the items, then notification of failure is displayed.

Link to comment
Share on other sites

Wow! With your help I got it working perfectly save for the conditional casting you mentioned. I thought that the conditions that were baked into the spell "effects" would accommodate, as I have the ability to set it up to require that one or more of the items needed are present, but alas, even with the conditions set I can cast away even after eating through all of my gems. Thank you so much for the help on getting that "quest" set up, though. I really didn't know that things like that were controlled by quests, so I have a lot to look into; that's for sure.

 

Either way, thanks again. I couldn't have done it without your support. Now to look into the chain-casting concept. ;)

Link to comment
Share on other sites

  • 1 month later...

I've been able to do this by creating two spells. SPELL2 is the eventual effect that I want cast, and I give it a 0 mana cost.

 

The SPELL1 contains only a single MagicEffect, which is a script:

 

MiscObject property ITEMCOST auto ;THIS IS THE ITEM THAT GETS REMOVED

Spell property SPELL2 auto ;THIS IS THE SPELL THAT I ACTUALLY WANT CAST

 

Event OnEffectStart(Actor myTarget, Actor myCaster)

If(Game.GetPlayer().GetItemCount(ITEMCOST) >= 5)

Game.GetPlayer().RemoveItem(ITEMCOST, 5)

SPELL2.Cast(myCaster, myTarget)

Else

Debug.Notification("You don't have the items required to cast this spell")

EndIf

EndEvent

Link to comment
Share on other sites

  • Recently Browsing   0 members

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