OnObjectEquipped issues

Post » Tue Jul 29, 2014 7:11 am

It seems to be preventing OnItemRemoved to run a second time. I had to make several changes to this script. The idea is to change the object assigned to CurrentWeapon when the player changes the weapon for any reason other than having it being disarmed.

Spoiler
Scriptname RetrieveDisarmWepRefScript extends ReferenceAlias{Attempts to detect if the equipped weapon has been removed.}Actor property PlayerRef autoObjectReference FindCurrentWeaponForm CurrentWeaponBool WeaponRetrieved = falseEvent OnInit()CurrentWeapon = PlayerRef.GetEquippedWeapon()debug.notification("Current Weapon:" +CurrentWeapon.GetName() as string);The weapon stored is the weapon currently equipped AT THE TIME THIS EVENT IS FIRED.;Any subsequent weapon changes is handled through OnObjectEquipped.AddInventoryEventFilter(CurrentWeapon);So that the OnItem events only fire for the weapons.RegisterForMenu("BarterMenu")RegisterForMenu("CraftingMenu");Incase the weapon that is stored is then sold or destroyed through disenchantment.EndEventEvent OnPlayerLoadGame()RegisterForMenu("BarterMenu")RegisterForMenu("CraftingMenu")EndEventEvent OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)akBaseItem = CurrentWeaponFindCurrentWeapon = Game.FindClosestReferenceOfTypeFromRef(CurrentWeapon, GetReference() as actor, 1000.0)        if (CurrentWeapon)        ;nothing    else        debug.notification("Didn't drop the correct weapon.")    endif             if FindCurrentWeapon == none                 debug.notification("Current weapon could not be found.")             else                 (GetReference() as Actor).Additem(FindCurrentWeapon)                     endif          EndEventEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference)    Utility.wait(1.0)    if (akBaseObject) == CurrentWeapon        ;do nothing    else        CurrentWeapon = none        CurrentWeapon = PlayerRef.GetEquippedWeapon()        debug.notification("Current weapon from Equipped Event:" +CurrentWeapon.GetName() as string)    endifEndEventEvent OnMenuOpen(String MenuName)    if MenuName == "BarterMenu" || MenuName == "CraftingMenu"        debug.notification("Menu opened.")    ;  undecided             endifEndEventEvent OnMenuClose(String MenuName)    if MenuName == "BarterMenu" || MenuName == "CraftingMenu"        debug.notification("Menu closed.")  ;undecided            endifEndEvent

OnItemRemoved fires the first time a weapon is disarmed.

The debug message for the OnObjectEquipped Event does not return the next weapon the player may equip upon disarming.

The debug message for the OnObjectEquipped Event does return the correct current weapon on subsequent weapon changes, it appears that CurrentWeapon is being properly changed.

OnItemRemoved does not fire at all on any disarms.

This is all because of sentence #3. CurrentWeapon is not being set at all despite supposedly doing so in OnObjectEquipped. Infact, it is still pointing at the weapon from the time OnInit fired. Thus, OnItemRemoved is "waiting" for the weapon to drop. In my case, an Ebony Bow.

So how do I change the object CurrentWeapon is pointing at?

User avatar
Sarah Edmunds
 
Posts: 3461
Joined: Sat Jul 08, 2006 8:03 pm

Post » Tue Jul 29, 2014 4:06 am

I think the problem might be that you have to RemoveAllInventoryEventFilters when a new object is equipped, and then add a new inventory event filter for the newly updated CurrentWeapon.

User avatar
jason worrell
 
Posts: 3345
Joined: Sat May 19, 2007 12:26 am


Return to V - Skyrim