Detecting when a specific item is added to your inventory

Post » Sun Mar 30, 2014 1:46 pm

Hello - I am trying to create a weapon, that does a variety of things based upon your action with it. I am attempting to do this by attaching a script to the weapon in question.

I am trying to accomplish:

1) detect when the weapon is added to your inventory <-- this is not working

2) detect when the weapon is removed from your inventory <-- this is also not working

3) detect when the weapon is grabbed (works just fine)

4) detect when the weapon is equipped and unequipped (works just fine)

The goal is to ultimately do some various cool magic effects depending on the events above. I assume I am using the events incorrectly - or maybe the wrong events?

My current script code is:

Scriptname GBobMagicItemWeapMystery extends ObjectReference  ;===============================================import utilityimport form;===============================================Weapon  Property ItemDiscovered autoMagicEffect Property EffectWhenAdded autoMagicEffect Property EffectWhenRemoved autoMagicEffect Property EffectWhenEquipped autoMagicEffect Property EffectWhenHit autoEvent OnGrab()  Debug.Notification("Grabbing item")endEventEvent OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)    Debug.Notification("Item added")  if !akSourceContainer    Debug.Notification("I picked up " + aiItemCount + "x " + akBaseItem + " from the world")  elseif akSourceContainer == Game.GetPlayer()    Debug.Notification("The player gave me " + aiItemCount + "x " + akBaseItem)  else    Debug.Notification("I got " + aiItemCount + "x " + akBaseItem + " from another container")  endIfendEventEvent OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)    Debug.Notification("Item removed")  if !akDestContainer    Debug.Notification("I dropped " + aiItemCount + "x " + akBaseItem + " into the world")  elseif akDestContainer == Game.GetPlayer()    Debug.Notification("I gave the player " + aiItemCount + "x " + akBaseItem)  else    Debug.Notification("I gave " + aiItemCount + "x " + akBaseItem + " to another container")  endIfendEventEvent OnEquipped(Actor akActor)  if akActor == Game.GetPlayer()    Debug.Notification("We were equipped by the player!")  endIfendEventEvent OnUnequipped(Actor akActor)  if akActor == Game.GetPlayer()    Debug.Notification("We were unequipped from the player!")  endIfendEventEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)  Debug.Notification("We were hit by " + akAggressor)EndEvent

My problem currently lies with the two events "OnItemAdded" and "OnItemRemoved". Neither one of these appear to get executed.

I have yet to test whether the OnHit event works correctly (I want to detect when the weapon successfully hits a target).

Does anyone have any ideas of what I am doing wrong?

Thanks in advance!

User avatar
Horror- Puppe
 
Posts: 3376
Joined: Fri Apr 13, 2007 11:09 am

Post » Sun Mar 30, 2014 2:20 pm

On*Item() events fire in Reference Alias quest. Make a quest for PlayerRef. Attach script to the PlayerRef that extends ReferenceAlias use those events in the script
User avatar
Barbequtie
 
Posts: 3410
Joined: Mon Jun 19, 2006 11:34 pm

Post » Sun Mar 30, 2014 3:15 am

For a script on the object itself, the function you want is http://www.creationkit.com/OnContainerChanged_-_ObjectReference.
User avatar
Eve Booker
 
Posts: 3300
Joined: Thu Jul 20, 2006 7:53 pm


Return to V - Skyrim