Jump to content

Container problems


shonuv

Recommended Posts

I'm trying to make a script that will populate shelves with clutter based on whats added to a container.

 

I can get it to work when adding items to a chest, but it doesn't do the opposite when removing items.

 

I have this on my OnItemRemoved event

If self.GetItemCount(akBaseItem as Ingredient) == 0
xmark01.disable()
It disables the xmarker even if the container still has other Ingredients in it. Any advice or insight would be appreciated.
Link to comment
Share on other sites

Am I correct in understanding that you want items to be removed from the shelf when something is removed from the chest?

 

What is the purpose of the xmarker? Why are you disabling it? I'm guessing it's the Enable Parent for the items you want to remove? It sounds like you are "removing" items simply by disabling them.

 

Also, is the Ingredient type correct in the getitemcount? I'm guessing you are doing that to "filter" for the item types added to the container.

 

Another thought, have you considered just using a GlobalVariable? I'm thinking that plus the use of a keyword might help as well.

Link to comment
Share on other sites

 

I'm trying to make a script that will populate shelves with clutter based on whats added to a container.

 

I can get it to work when adding items to a chest, but it doesn't do the opposite when removing items.

 

I have this on my OnItemRemoved event

If self.GetItemCount(akBaseItem as Ingredient) == 0
xmark01.disable()
It disables the xmarker even if the container still has other Ingredients in it. Any advice or insight would be appreciated.

 

It is disabling the xmarker when you have other ingredients because the check you have is only for the currently removed item and not for ALL items in the container.

 

To determine if all ingredients in the container have been removed you will need to go a bit more in depth.

 

The following function requires SKSE.

Int Function GetNumStoredIngredients(ObjectReference TheCont)
	Int StockCount = 0
	Int NumItems = TheCont.GetNumItems()
	Int i = 0
	While ( i < NumItems )
		If ((TheCont.GetNthForm(i)) as Ingredient)
			StockCount = StockCount + TheCont.GetItemCount(TheCont.GetNthForm(i))
			i += 1
		EndIf
	EndWhile
	Return StockCount
EndFunction

Add the function to the end of your script then call it in your OnItemRemoved event like so

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
	If GetNumStoredIngredients(YourContainerProperty) == 0
		xmark01.disable()
	EndIf
EndEvent

Please note that I have not tested compilation or function. This is theory, sound but still theory.

Link to comment
Share on other sites

Okay, that makes sense.

 

 

Thanks for the responses, i'll go try out the script above and see what happens.

 

-Regards

 

 

edit: The above script works like a champ. Thanks again. Oh, and dimmu, so as to not leave ya hanging, yes your assumptions were correct. The items on the shelves are static objects parented to the xmarker, and are purely aesthetic.

Edited by shonuv
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...