Detect when a spell is charged and ready to fire

Post » Tue Nov 20, 2012 3:24 pm

I'm posting this in the hope that I'm making this more difficult than it needs to be.

I need to know when the player has a spell equipped, when the player is charging that spell for casting, and when the charging is complete and the spell is ready to fire.

There are multiple events for the first two... and none, not a single one that I can find, for the last.

I have registered for animation events on literally every single animation in 0_master-out, magicbehavior-out, 1hm_behavior-out, and idlebehavior-out. It takes nearly 20 seconds just to register that many events. Events fire when I move, when I equip, when I begin casting and when I finish casting, but NOTHING fires when the spell is charged and ready TO cast. The vast majority of the events that would seem relevant don't fire at all.

I have polled most of the animation variables from those files throughout casting, as well. Nothing gives me a definitive value that tells me that the spell is ready, though some can be used to find out that the spell is charging.

The only way I can apply a scripted effect when the spell is charged is by starting a timer when the BeginCastLeft (there doesn't appear to be a corresponding BeginCastRight) event fires, and trying to match the fully-charged script effect to the moment the spell is actually ready. As we all know, though, precise timing and Papyrus don't go well together.

What's so annoying about this is I know the game tracks this event, because certain magic art objects have "charged" animations that are linked to the spell being charged. That event just isn't exposed to the user anywhere.

Help?
User avatar
Sammie LM
 
Posts: 3424
Joined: Thu Nov 30, 2006 1:59 pm

Post » Tue Nov 20, 2012 6:55 am

I have worked with this alot. You can't detect it with animations variables. The GetCastTime() function can be unreliable and didn't work in my case (concentration spells).

The only way I have been able to do this, so that it works with any spell is by monitoring mana. When your mana stops draining the spell is ready to cast. Concentration spell work a little differently though so you have to account for them. Here's my autocast function. I stripped it down some for you.

bool GoCast = Truefloat magicka1 = player.GetAV("Magicka")float magicka2 = -1while GoCast && Gkey != JumpKey && (player.GetAnimationVariableBool("IsCastingDual") || player.GetAnimationVariableBool("IsCastingRight") || player.GetAnimationVariableBool("IsCastingLeft"))  ;;; Animation variables say you are currently casting  If player.GetAV("Magicka") < magicka1    magicka2 = player.GetAV("Magicka")    ;;; Your magicka started decreasing so fill magicka2  endif  utility.WaitMenuMode(0.1)  If magicka2 == player.GetAV("Magicka")    GoCast = False    ;;; Your magicka stopped decreasing so break the loop  endifendwhile


Note the JumpKey in the while loop is to break it early by pressing Jump, which is setup elsewhere.

So basically this loop will run until the spell is finished casting. Concentration spells will run the loop until you run out of mana or break the loop. You also need to check that GetMagickaCost() isn't 0 before you start the loop.

Honestly if I wasn't worried about concentration spells I would try GetCastTime() with an extra buffer wait time. Haven't tried it myself.

GL
User avatar
Jonathan Montero
 
Posts: 3487
Joined: Tue Aug 14, 2007 3:22 am

Post » Tue Nov 20, 2012 1:53 pm

That's pretty clever. Got to be more accurate than a simple timer... I'll give it a try!
User avatar
Eoh
 
Posts: 3378
Joined: Sun Mar 18, 2007 6:03 pm

Post » Tue Nov 20, 2012 3:09 pm

you both are clever.
User avatar
CHangohh BOyy
 
Posts: 3462
Joined: Mon Aug 20, 2007 12:12 pm


Return to V - Skyrim