Ok so before i begin i should warn you that i have very little knowledge about scripting, so please don't judge me if i seem a bit lost/confused by this.
So now that thats out of the way let me tell you what im trying to do, basically im trying to make a script that will transfer ingredient from over 60 containers to players inventory when he activates the alchemy table, and when the player exits the alchemy menu the ingredients will be sorted back to thair respective container. the script is based on the Individual Item Auto Sorter. the first part works fine, i activate the table and the item get moved to my inventory, the problem is that when i exit the alchemy menu, the items stay in my inventory. I'm not sure what im doing wrong but i think it has something to do with the IsFuritureInUse function. anyways take a look at the script, and show me what i did wrong please.
Scriptname HE_MoveingredientsScript extends ObjectReference
{Unsorts Ingredients from individual containers to master containers}
Import Game
Import Utility
Import Debug
;Ingredient Array -- items assigned in CK in special UI property assignment section
Ingredient[] Property abIM_FL_Array Auto
;Containers Array -- containers assigned in CK in special UI property assignment section
ObjectReference[] Property abIM_CONT_Array Auto
{Note: Ingredient & Container arrays must match up. Meaning that ingredient #0 goes into container #0 etc... }
;Master container where ingredients are placed and retrieved by player
ObjectReference Property abIM_CONT_TransferContainer Auto
Event OnActivate(ObjectReference Someone)
Actor Player = GetPlayer()
String Failure = "Failed to Transfer ingredients"
String Success = "Ingredients successfully Transfered"
Int NumOnHand = 0
Int Succeed = 0
If Someone == Player
Int FL_ArraySize = abIM_FL_Array.Length
Int CT_ArraySize = abIM_CONT_Array.Length
If FL_ArraySize == CT_ArraySize
Int Index = 0
While Index < CT_ArraySize
NumOnHand = abIM_CONT_Array[Index].GetItemCount(abIM_FL_Array[Index])
If NumOnHand >= 1 ;Move items to player
abIM_CONT_Array[Index].RemoveItem(abIM_FL_Array[Index],NumOnHand,True,abIM_CONT_TransferContainer)
Succeed = 1
EndIf
Index += 1
EndWhile
ElseIf !(FL_ArraySize == CT_ArraySize)
Debug.Notification("Warning: Array size mismatch. Transfer cancelled")
EndIf
If Succeed == 1
Return Notification(Success)
ElseIf Succeed == 0
Return Notification(Failure)
EndIf
While Self.IsFurnitureInUse(True) ;WAIT
;Do nothing while the alchemy table is in use
EndWhile
If !Self.IsFurnitureInUse() ;Move items back to containers
If FL_ArraySize == CT_ArraySize
Int Index = 0
While Index < CT_ArraySize
NumOnHand = abIM_CONT_TransferContainer.GetItemCount(abIM_FL_Array[Index])
If NumOnHand >= 1
abIM_CONT_TransferContainer.RemoveItem(abIM_FL_Array[Index],NumOnHand,True,abIM_CONT_Array[Index])
Succeed = 1
EndIf
Index += 1
EndWhile
ElseIf !(FL_ArraySize == CT_ArraySize)
Debug.Notification("Warning: Array size mismatch. Transfer cancelled")
EndIf
If Succeed == 1
Return Notification(Success)
ElseIf Succeed == 0
Return Notification(Failure)
EndIf
EndIf
EndIf
EndEvent