Jump to content

Papyrus - RegisterForAnimationEvent and OnAnimationEvent - Help me!


Matth85

Recommended Posts

heya!

 

So. I am stuck on a little something. I have spent the better part of a weekend trying to solve it, and I run blank every time. The issue is, *gasp*, in Event onAnimationEvent.

Now, some backstory; Sparing you all the details of this little experiment of mine, I am effectively trying to recreate the Bloodskaal effect of sorts. At the barest, I need to detect when the player uses a power attack, fire off a projectile and reset a global variable (That part is covered).

 

First I tried putting the script on the weapon itself, extending objectreference. Here is a quick image of it: https://gyazo.com/e55f4d02d7f4c5ced44c67a414daa300 .

Now, I made sure the animations were registered and unregistered correctly. That's all good in this example. I ran into two issues though:

 

1) Smaller issue; The animations did not unregister if the player drops the weapon directly from equip. I am assuming the animations unregister when this happen, though, since the script is running on the object itself.

 

2) The OnAnimationEvent is not playing. At all. It doesn't register the power attacks.

 

So, I was lead to believe this was because this sort of script would not work if I extend ObjectReference. Fair enough; I made it a hidden perk, which links up to an enchantment which links up to a magic effect with the script: https://gyazo.com/fc5f1af10e8026d70abe351a7a9d2f7a

Much the same script, but with some added changes to take into account the magical part of it. Then I simply added a game.getplayer().AddPerk(PerkName) on an equip event, and remove perk on a unequip event, which I link up to the sword itself. I got confirmation the Perk is added and removed, and the animations get registered. (Afaik, animations unregister after the magic effect is over automatically.)

Same issue as before; nothing happen.

 

Lastly I tried using a Reference Alias to the player and extend the script to ReferenceAlias., in a seemingly empty quest. This time nothing happens - the quest didn't start it seem.

 

So, yeah. Any ideas?

For reference; I have been studying the Bloodskaal script + setup, as well as the mod Imbued Weapon. They do this in a different way, Bloodskaal referes the weapon directly and do some weird stuff.

The registering is rather straight forward, and so is the misille firing at the EventOnAnimateEvent. This part, however, leaves me confused.

It checks if the player is the container(aka: inventory). It then sets the player as a weapon(?). Then it.. checks if the new variable is equipped, at which it does.. what?

Then it forverefs the alias to objself, which Is defined as

objectReference Property ObjSelf auto hidden
Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
	if akNewContainer as Actor
		selfWeapon = (self.getReference().getBaseObject() as weapon)
		utility.wait(0.1)
		if (akNewContainer as Actor).isEquipped(selfWeapon)
			OnEquipped(akNewContainer as Actor)
		endif
	endif
	BloodskalBlade.ForceRefTo(objSelf)
endEvent

Anyways. They get the Event OnAnimationEvent to work via alias references. For some reason I don't. I assume I am doing something wrong, so the quest doesn't fire in that case.

For the other example, I am doing the same setup with a perk. The only difference is that I am adding and removing that perk via the weapon. It works there, it does not work for me. . (Script from the mod, showing the relevant parts) https://gyazo.com/46f7aef1906c1d5c9a0b0d89a6408ccc

 

TL;DR: I am able to register the animations via 2 different method, but I am not getting the actual animation event to start. I am also not able to get the reference alias method to work; mostly because I don't get the quest to actually start. Any help would be nice!

Edited by Matth85
Link to comment
Share on other sites

The problem with OnAnimationEvent is that it only works for certain types of AnimEvents registered/caught in certain script types.

 

AnimEvents (for characters/creatures) are created/sent in 3 situations:

  1. From a script (PlayIdle, SendAnimationEvent, ...) or as Idle from the CK (e.g. IdleMArker)
  2. From the behaviors sent by notifications
  3. From the behaviors sent by triggers (hkbClipTriggerArray)

What I can definitely say that only AnimEvents of the 3rd kind can be caught. Your "AttackPowerxxx_FXStart" are all triggered, so that should work.

 

I also can say that On AnimEvent doesn't work for all script types. Although here I cannot be totally sure. I tried many things, but stopped testing when I had everyting working the way I wanted.

- I know it works in Actor scripts, and I think it works in ReferenceAlias scripts

- It does not work in MagicEffect scripts, and I think it doesn't work in quest scripts.

 

Since you are doing everything in an ObjectReference script, I think that could be your problem.

Link to comment
Share on other sites

I test if the registered animations are true(as bool) and it sends me a debug message.

So that should be okay. Unless they are always true, at which I get very confused :p

 

-------

 

Thus far I have tried via ObjectRefernce and Magic effect. My last bet is ReferenceAlias.

Edited by Matth85
Link to comment
Share on other sites

You are confused when something doesn't work as expected and described? :tongue:

 

From the CK Wiki:

The game will allow you to register ANY animation event, valid or invalid. Though they may register successfully, not all of them will necessarily generate events.

Link to comment
Share on other sites

Aye. That part had be concerned for a while. I have, however, seen 3 cases of these events working. Bloodskal being the most prominent. Imbued Weapon( Bloodskal effect for any weapon) uses them, although in a ActiveMagicEffect (Which I am not getting to work, ugh). And I saw a throwing knife mod which used them on Object Reference.

 

Event OnAnimationEvent really is a tricky thing. There doesn't seem to be any good way to track whether it starts, or what it fires off of, without actually knowing beforehand. Though I get a feeling if I simply register the events via the perk/ObjectReference script, I could try to call the Event OnAnimationEvent via the Alias. I know Bloodskal calls(the sword) via the alias and extends ReferenceAlias. I also know Imbued weapon do use a menu system and refers the player alias, though I see no connection to the perk working via that. I could've missed something though.

 

So, my confusion is not with the registration working, but nothing happens. That much I read up on. My confusion is why events that does work, doesn't work. By all accounts, as soon as these events are registered, it should be as simple as adding the event and it should print out the debug message. Alas, it does not. If I am to go by Bloodskal - then it's because it should be done via ReferenceAlias. Going by Imbued Weapons mod, then adding it via a perk should work fine as well (Extend ActiveMagicEffect). Alas, it does not work for me.

Edited by Matth85
Link to comment
Share on other sites

It works. You just need to find the proper way. Once you have it, it's totally reliable.

 

I'm using animevent registration exclusively in actor scripts. I use them for example to check if certain FNIS animations have been executed. For that I register custom trigger events generated by FNIS, and that always work.

 

I now checked the Imbued Weapons Bloodskal, and I was totally surprised that the registration is done in an MagicEffect script. But there are 2 differences to the MagicEffect scripts I was making:

- it registers for the caster, while I did for the target

- it registers for the player, while I did for NPCs.

 

So maybe it's the NPC which didn't make it work "for me".

Link to comment
Share on other sites

I tried by setting the player as persistent, the alias of the player as persistent and the sword as persistent. (by calling them into the script)

The only thing I have no tried, is to the set the alias of the sword persistent. Though I don't think that should have any effect at all; The sword merely gives you the perk. The perk is registering the animations and has everything happening.

 

Question, though: Can I register the animation in the magic effect, but call the "Event OnAnimationEvent" Via the Reference Alias? I am unsure if the registration would work cross-script.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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