warsinger Posted October 9, 2018 Share Posted October 9, 2018 (edited) 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 October 9, 2018 by warsinger Link to comment Share on other sites More sharing options...
DieFeM Posted October 14, 2018 Share Posted October 14, 2018 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) nativeIt 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 More sharing options...
pra Posted October 15, 2018 Share Posted October 15, 2018 (edited) 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 October 15, 2018 by pra Link to comment Share on other sites More sharing options...
SKKmods Posted October 15, 2018 Share Posted October 15, 2018 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: SKK Scrapper editing list items 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 More sharing options...
pra Posted October 15, 2018 Share Posted October 15, 2018 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: SKK Scrapper editing list items 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 More sharing options...
SKKmods Posted October 15, 2018 Share Posted October 15, 2018 There are thousands of SKK Scrapper users enjoying their junk being scrapped in sub-second real-time as it is added to player inventory. So lets not argue, it just works. Link to comment Share on other sites More sharing options...
DieFeM Posted October 16, 2018 Share Posted October 16, 2018 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 Link to comment Share on other sites More sharing options...
deadbeeftffn Posted October 16, 2018 Share Posted October 16, 2018 I've tested it, and seems to work fine, so there's my approach:That's the way - the way I like it .... :whistling: :thumbsup: Link to comment Share on other sites More sharing options...
pra Posted November 8, 2018 Share Posted November 8, 2018 I did it the F4SE way now: https://www.nexusmods.com/fallout4/mods/35793 In case anyone cares, or wants to look at the script. The source should be included in the ba2. Link to comment Share on other sites More sharing options...
Recommended Posts