AnimationEvent, differenting player from NPC

Post » Tue Jun 19, 2012 9:42 pm

Hey there!

I have a small problem. I have a script which looks like this:

Event OnAnimationEvent(ObjectReference akSource, string asEventName)Debug.MessageBox(hasWornKeyword(keyword1))EndEventEvent OnLoad()RegisterForAnimationEvent(Self, "bowDrawStart")EndEvent

Where keyword is a keyword which is attached to an item which I (and Mjoll) are wearing. This works when attached to mjoll by opening her up in the object window and putting the script there. But it doesn't work when I attach it to a quest.

I want to have the same script for player and NPC, should I do something else than attaching it to a quest? Will self not refer to the player if I attach it to a quest?

EDIT: I realize the title isn't a very good one. Sorry about that
User avatar
Peter lopez
 
Posts: 3383
Joined: Mon Sep 10, 2007 5:55 pm

Post » Tue Jun 19, 2012 7:25 pm

Self will not refer to the player if its a quest, it will refer to the quest

The OnLoad event will also not fire for a quest. OnInit is probably what you want for a quest, it fire when the quest starts up.
User avatar
Danielle Brown
 
Posts: 3380
Joined: Wed Sep 27, 2006 6:03 am

Post » Tue Jun 19, 2012 12:11 pm

So then I'd have to use a different script for the player where I replace every reference to a self to Game.GetPlayer()? Or should I do this in some other way? It seems like quests are the best option

EDIT: I used OnInit instead.

How do I use akSource to know if it's the player who sent the event or something else? If I output akSource to a message box it'll say the script's name and its ID.

EDIT 2: Apparently OnInit doesn't fire. Do I need to use papyrus fragments? I just attached the script to the quest through the scripts tab. Do I need to do anything else before it'll work?
User avatar
Quick draw II
 
Posts: 3301
Joined: Thu Nov 08, 2007 4:11 pm

Post » Tue Jun 19, 2012 11:04 pm

You misunderstand the use of the "self" keyword.

Think of it as saying "The reference that this function was called on" - for example, if your script extended Actor, and was on the player, and was called like this:

(Game.GetPlayer() as MyScriptName).MyFunctionName()

Then "self" could refer to the player. (I doubt you could get that to work though, and since you can get Game.GetPlayer() at any time anyway, it's a bit redundant)

What you would probably want to do is look at the threads around where a certain item grants a spell to the user when worn (I've seen at least two) and similar code could work for your item...
User avatar
Emily Shackleton
 
Posts: 3535
Joined: Sun Feb 11, 2007 12:36 am


Return to V - Skyrim