Jump to content

Adding a Recycle Container to Settlement


vonBennett

Recommended Posts

All,

 

I would like to add a 'recycle container' to one of my player home/settlement mods. Basically I am tired of scrapping the old way in 'workshop mod'. I would like to simply put unwanted junk items in the container, close it and when I re-open it, the junk items would be broken down to their basic components. I am not sure if there is a script available that can be added to a container or there is more needed?

Thank you.

 

B..

Link to comment
Share on other sites

Heyas vonBennett.

SKK may have something along the lines of what you are looking for, plus a whole lot more.

https://www.nexusmods.com/fallout4/mods/41511

 

Maybe check it out and read down into it's scrapping features. :D

That you, I will check it out.

 

I am really just looking for a script that someone may have created themselves and would let me use, and any help/guidance in creating my own recycle container that I can make myself from existing Creation Kit assets and include within my player home/settlement mod.

 

Thanks again :wink:

Link to comment
Share on other sites

This is from the component scrapping agent in F4MS:

Int Function ScrapItems(Int componentCountRequested, Component componentToScrapFor, ObjectReference sourceContainer, ObjectReference targetContainer)
	; get available component count for source container
	Int numberOfComponentsScrapped = sourceContainer.GetComponentCount(componentToScrapFor)
		
	; container has requested component(s) in it?
	If (numberOfComponentsScrapped > 0)			
	
		; component count supplied?
		If (componentCountRequested > 0)
			; limit scrapped count to requested amount
			If (numberOfComponentsScrapped > componentCountRequested)
				numberOfComponentsScrapped = componentCountRequested
			EndIf
		EndIf		
		
		; perform scrapping on source container
		sourceContainer.RemoveComponents(componentToScrapFor, numberOfComponentsScrapped, abSilent = true)
		
		; add scrapped components to target container
		targetContainer.AddItem(componentToScrapFor, numberOfComponentsScrapped, abSilent = true)		
		
	Else
		; nothing to scrap for in this container
		numberOfComponentsScrapped = 0

	EndIf
	
	; return amount of scrapped components moved to target container
	Return numberOfComponentsScrapped
EndFunction

If you don't have a specific componentToScrapFor, you'll have to make a formlist of all base game components and process them one after the other.

 

Alternatively, F4SE has GetMiscComponents() function on MiscObject script. It returns an array of MiscComponent, describing the components and their counts in a given MiscObject item.

F4SE also adds a few scrap related functions to the Component script. Could be helpful, if F4SE is available to you.

Link to comment
Share on other sites

This is from the component scrapping agent in F4MS:

Int Function ScrapItems(Int componentCountRequested, Component componentToScrapFor, ObjectReference sourceContainer, ObjectReference targetContainer)
	; get available component count for source container
	Int numberOfComponentsScrapped = sourceContainer.GetComponentCount(componentToScrapFor)
		
	; container has requested component(s) in it?
	If (numberOfComponentsScrapped > 0)			
	
		; component count supplied?
		If (componentCountRequested > 0)
			; limit scrapped count to requested amount
			If (numberOfComponentsScrapped > componentCountRequested)
				numberOfComponentsScrapped = componentCountRequested
			EndIf
		EndIf		
		
		; perform scrapping on source container
		sourceContainer.RemoveComponents(componentToScrapFor, numberOfComponentsScrapped, abSilent = true)
		
		; add scrapped components to target container
		targetContainer.AddItem(componentToScrapFor, numberOfComponentsScrapped, abSilent = true)		
		
	Else
		; nothing to scrap for in this container
		numberOfComponentsScrapped = 0

	EndIf
	
	; return amount of scrapped components moved to target container
	Return numberOfComponentsScrapped
EndFunction

If you don't have a specific componentToScrapFor, you'll have to make a formlist of all base game components and process them one after the other.

 

Alternatively, F4SE has GetMiscComponents() function on MiscObject script. It returns an array of MiscComponent, describing the components and their counts in a given MiscObject item.

F4SE also adds a few scrap related functions to the Component script. Could be helpful, if F4SE is available to you.

As always....thank you Niston.

Link to comment
Share on other sites

This is how it can be done in F4SE:

function doScrap()
    Form[] inventory = GetInventoryItems()
    
    int i=0
    while(i<inventory.length)
        processItem(inventory[i])
    
        i += 1
    endwhile
endfunction

function processItem(Form itemBase)
    
    MiscObject misc = itemBase as MiscObject
    if(!misc)
        return
    endif    
    
    MiscObject:MiscComponent[] comps = misc.GetMiscComponents()
    if(comps.length == 0)
        return
    endif

    ; misc might be scrap already, check that
    if(comps.length == 1 && comps[0].Object.GetScrapItem() == misc)
        return
    endif
    
    int itemCount = getItemCount(itemBase)
    self.removeItem(itemBase, itemCount)
    int i=0
    while(i<comps.length)
        MiscObject:MiscComponent cur = comps[i]

        MiscObject scrapItem = cur.Object.GetScrapItem()
        
        int amount = cur.Count * itemCount
        if(amount > 0)
            self.addItem(scrapItem, amount)        
        endif
        i += 1
    endwhile
endfunction
Link to comment
Share on other sites

 

This is how it can be done in F4SE:

function doScrap()
    Form[] inventory = GetInventoryItems()
    
    int i=0
    while(i<inventory.length)
        processItem(inventory[i])
    
        i += 1
    endwhile
endfunction

function processItem(Form itemBase)
    
    MiscObject misc = itemBase as MiscObject
    if(!misc)
        return
    endif    
    
    MiscObject:MiscComponent[] comps = misc.GetMiscComponents()
    if(comps.length == 0)
        return
    endif

    ; misc might be scrap already, check that
    if(comps.length == 1 && comps[0].Object.GetScrapItem() == misc)
        return
    endif
    
    int itemCount = getItemCount(itemBase)
    self.removeItem(itemBase, itemCount)
    int i=0
    while(i<comps.length)
        MiscObject:MiscComponent cur = comps[i]

        MiscObject scrapItem = cur.Object.GetScrapItem()
        
        int amount = cur.Count * itemCount
        if(amount > 0)
            self.addItem(scrapItem, amount)        
        endif
        i += 1
    endwhile
endfunction

Just add that to a container's script? It will work just as long as F$SE is being used as well?

Link to comment
Share on other sites

not quite. you need to call doScrap() from somewhere. Like, from the onClose:

event onClose(ObjectReference akActionRef)
    if(akActionRef == Game.GetPlayer())
        doScrap()
    endif
endEvent

This will make it so that as soon as you put anything into it and exit out of the menu, it will do the thing.

 

You can also extract the script from my scrapping machine mod and look at that. I do some more things there, like, only work when powered, lock the container, play a rumbling sound while it works, and a "ding" when done, if you want to look up how to do that kind of stuff.

Link to comment
Share on other sites

T

 

not quite. you need to call doScrap() from somewhere. Like, from the onClose:

event onClose(ObjectReference akActionRef)
    if(akActionRef == Game.GetPlayer())
        doScrap()
    endif
endEvent

This will make it so that as soon as you put anything into it and exit out of the menu, it will do the thing.

 

You can also extract the script from my scrapping machine mod and look at that. I do some more things there, like, only work when powered, lock the container, play a rumbling sound while it works, and a "ding" when done, if you want to look up how to do that kind of stuff.

Thank you very much. I will check it out. Much appreciated. :happy:

Link to comment
Share on other sites

  • Recently Browsing   0 members

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