Jump to content

Script that breaks down junk in a container


warsinger

Recommended Posts

Hi, I am currently trying to create a house mod, and I would like to put in a junk recycler that will break down junk items and move the components into the workshop inventory. What I'd like to do is for the script to activate when the container is closed, i.e. when the player leaves the container window.

 

However, I haven;t the faintest idea how it's done. Even looking at similar scripts such as the Portable Recycler mod and other house mods, I am not sure how it works. Also, I don't have permission to use their scripts, so I can't just use theirs.

 

Could I please get a little help on either how that script works, or perhaps have one made for me? Or, alternatively, if someone else has already made one, may I have your permission to use the script?

Edited by warsinger
Link to comment
Share on other sites

The only function I found that appears to scrap things in a container is:

; Removes the specified count of component from the container, scrapping items, and returning the remainder to said container
Function RemoveComponents(Component akComponent, int aiCount, bool abSilent = false) native

It could be a little tricky, but using this function and a bit of logic, you could maybe achieve what you are looking for.

Link to comment
Share on other sites

what does RemoveComponents do if you give it a higher count than there are components? will it remove as much as possible or just silently fail?

 

I guess you would have to use a formlist/array of all components, then go through it, for each component call getComponentCount onto your container. If the count is > 0, use that in RemoveComponents, and then in addItem().

 

You will probably need two arrays, since you can't just additem the component directly, you need the misc item which represents it's scrap form.

And you will need compatibility patches or similar for mods which add their own components. It's not that common, but not unusual either.

 

Edit: nevermind the part about two arrays. Component has getScrapItem(), which returns you the corresponding Misc Item. That's an F4SE function...

Edited by pra
Link to comment
Share on other sites

The evaluation of formlists for components is straight forward, but with 600+ to scan it can take 60 seconds to complete which is rubbish UX and needs to be multi threaded. Have a read of this to build a mental map of a likely design:

 

And no, I am not going to hand out my scripts as this is not the right starting place.
Link to comment
Share on other sites

 

The evaluation of formlists for components is straight forward, but with 600+ to scan it can take 60 seconds to complete which is rubbish UX and needs to be multi threaded. Have a read of this to build a mental map of a likely design:

 

And no, I am not going to hand out my scripts as this is not the right starting place.

 

I don't really get what you are trying to do there. Hardcode ALL MISC ITEMS which are scrappable into Formlists?

 

 

I'd rather hardcode all expsting components and do it the way I posted above. Or, just use F4SE, then you can just iterate all items in the container and get their components. Quite a lot of people use F4SE, for Place Everywhere or MCM or such things, so I think it's not an unreasonable dependency.

Link to comment
Share on other sites

I've tested it, and seems to work fine, so there's my approach:

Scriptname Scrapper:ScrapperContainer extends ObjectReference Const

FormList Property ScrapperComponentList Auto Const
FormList Property ScrapperScrapComponentList Auto Const

Event OnActivate(ObjectReference akActionRef)
	If(akActionRef == Game.GetPlayer())
		int i = 0
		While i < ScrapperComponentList.GetSize()
			Component CurrentComponent = ScrapperComponentList.GetAt(i) As Component
			If(CurrentComponent)
				Int ComponentCount = GetComponentCount(CurrentComponent)
				If(ComponentCount > 0)
					RemoveComponents(CurrentComponent, ComponentCount, True)
					AddItem(ScrapperScrapComponentList.GetAt(i), ComponentCount, True)
				EndIf
			EndIf
			i += 1
		EndWhile
	EndIf
EndEvent

UM4LxO.jpg

Link to comment
Share on other sites

  • 4 weeks later...
  • Recently Browsing   0 members

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