The details. I have the following script on several non-respawning chests. In the ESP, the chests are empty, and the basic idea is that the player can use a chest to add and remove apparel/armor, and then the formlist passed as a property will update accordingly. There's some other code because my follower won't wear elven gear or heavy armor for personal reasons, but I think it is ignorable--the main issue seems to be with the OnItemRemoved event, where I've added some debug messaging.
Scriptname ESFAelaOutfitChestScript extends ObjectReference FormList Property OutfitFList AutoKeyword[] Property KeywordElvenGear AutoKeyword Property KeywordHeavyGear AutoEvent OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) if akBaseItem as Armor Bool bIsOkay = true Int index = 0 while index < KeywordElvenGear.Length if akBaseItem.HasKeyword(KeywordElvenGear[index]) Debug.MessageBox("\"I don't use that fancy elven kit. Give me gear made of hide from the beasts of Skyrim, and fine northern steel.\"") bIsOkay = false index = KeywordElvenGear.Length endif index = index + 1 endwhile if akBaseItem.HasKeyword(KeywordHeavyGear) Debug.MessageBox("\"That's not my style. I fight best when I'm light on my feet.\"") bIsOkay = false endif if bIsOkay == false if akItemReference == None Self.RemoveItem(akBaseItem, aiItemCount, true, Game.GetPlayer()) else Self.RemoveItem(akItemReference, aiItemCount, true, Game.GetPlayer()) endif else if OutfitFList.HasForm(akBaseItem as Form) == false OutfitFList.AddForm(akBaseItem as Form) endif endif else if akSourceContainer == Game.GetPlayer() Debug.Notification("Only base armor and clothing (unenchanted or improved by the player) can be added.") endif if akItemReference == None Self.RemoveItem(akBaseItem, Self.GetItemCount(akBaseItem), true, Game.GetPlayer()) else Self.RemoveItem(akItemReference, 1, true, Game.GetPlayer()) endif endifEndEventEvent OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer) Debug.MessageBox("Remove triggered!") if OutfitFList.HasForm(akBaseItem as Form) OutfitFList.RemoveAddedForm(akBaseItem as Form) Debug.MessageBox("Item Removed: " + akBaseItem) endif if OutfitFList.HasForm(akBaseItem as Form) Debug.MessageBox("Not removed!") else Debug.MessageBox("Removed!") endifEndEventI've also created a messagebox that uses GetSize on the formlists, and lists the forms they contain.
Okay, so when I first add items to the chests, everything works fine, and persists that way betwen saved games. In this screenshot made today I've just loaded a save made a day or two ago, after I added the initial items:
http://steamcommunity.com/profiles/76561198044640415/screenshot/524906243885237879/
However, when I try to alter the gear in one of the chests, strange things begin to happen. The "Remove triggered!" and "Item Removed:" messages always appear, but only the first item--it doesn't matter which--that I remove triggers the "Removed!" message; subsequent items taken trigger "Not removed!" For example, immediately after I took the previous screenshot, I tried removing all three items in the Outfit 1 chest and adding three new ones. What resulted was this:
http://steamcommunity.com/profiles/76561198044640415/screenshot/524906243885236174/
Five items in the formlist. (And no relevant error messages in the Papyrus log.)
Bad enough, but I then immediately made a save, quit the game, restarted and loaded that save, and I saw this:
http://steamcommunity.com/profiles/76561198044640415/screenshot/524906243885224330/
Outfit 1 had been completely corrupted--GetSize returned 6 items but somehow only 5 were displayable, and those 5 had little relation to what had been in the list before the save. (Locations?!?)
So...what is going on?
