Script to trigger when a weapon is drawnsheathed?

Post » Mon Jun 18, 2012 7:54 am

Hi all,

I've been going through the Papyrus tutorial stuff on the CK site. I'm still a little unclear on where to attach scripts in order to get the effect I want.

What I'm looking to do is trigger a script when the player draws or sheaths certain weapons: I want to alter the orientation of them, if this is possible.

I've found ObjectReference.setAngle, and I've found Actor.isWeaponDrawn. I'm unclear how to place the script to work the way I want.

If you'll forgive the pseudo-code, something like:
ObjectReference thisWeapon = thisActor player = Game.GetPlayer()if(player.isWeaponDrawn())   thisWeapon.setAngle(90,0,0)else  thisWeapon.setAngle(-90,0,0)endif

If it's attached to the weapon in question, is there a way to trigger that on weapon draw/sheath? If not, can it be attached to the player to do something similar?

Thanks!
User avatar
Inol Wakhid
 
Posts: 3403
Joined: Wed Jun 27, 2007 5:47 am

Post » Mon Jun 18, 2012 8:04 am

Ok, so I've attached the following script to the player actor:

Spoiler
Scriptname combatStateTest extends ObjectReference  Actor Property playerActor  Auto  WEAPON Property HandyMan_ClothesIronRef  Auto ;reference to a custom weaponEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference)int equippedID = akBaseObject.getFormID()int hmClothesIronID = HandyMan_ClothesIronRef.getFormID()string anim = "ActionSheath"if(equippedID == hmClothesIronID ) ;only perform this for our custom weaponDebug.Notification("Equipped Clothes Iron! Registering event: "+anim)if(RegisterForAnimationEvent(playerActor, anim))Debug.Notification("Registered!")elseDebug.Notification("Failed to register!")endIfendIfendEventEvent OnAnimationEvent(ObjectReference akSource, string asEventName)  Debug.Notification("Animation event!")  if (akSource == self) && (asEventName == "ActionSheath")    Debug.Notification("Sheath!")  endIfendEvent

I've tried a number of things for the animation event name: "ActionDraw", "ActionSheath" (found by searching in the object window), "DrawSheathRoot", "DefaultDrawWeapon" (found in Gameplay>Animations under Actors\Characer\Behaviours\0_Master), but the notifications never pop up when drawing & sheathing the weapon. I do see "Registered!", so RegisterForAnimationEvent seems to be returning a success value. So, questions:

Am I totally misunderstanding how to use OnAnimationEvent?

Is there no inheritance of events? (OnAnimationEvent belongs to Form Script rather than Actor Script)

Should I just resort to polling, or setting up a quest that monitors the current status of the player via isWeaponDrawn()?
User avatar
Kahli St Dennis
 
Posts: 3517
Joined: Tue Jun 13, 2006 1:57 am

Post » Mon Jun 18, 2012 8:11 pm

No, the way you using OnAnimationEvent seems fine. It just not every Anim can be registered. You can check the following thread of mine, and the wiki for more details

http://www.gamesas.com/topic/1348473-onanimationevent-doesnt-trigger-even-after-successful-registerforanimationevent/page__fromsearch__1
User avatar
Hussnein Amin
 
Posts: 3557
Joined: Sun Aug 05, 2007 2:15 am

Post » Mon Jun 18, 2012 4:57 pm

Ah. Thanks for the heads-up.
User avatar
katie TWAVA
 
Posts: 3452
Joined: Tue Jul 04, 2006 3:32 am


Return to V - Skyrim