Jump to content

[LE] Help Making a Respawning Container


Bersark93

Recommended Posts

I'm trying to make a respawning salt barrel that respawns with x3 Salt Pile daily (similar to the Hearthfire respawning milk shelf) and another respawning barrel containing ingredients from a mod i'm making but I can't work out how to set the respawn time on the container and so it only respawns with my ingredient. I've searched for tutorials on this and looked on the Creation kit wiki but I still can't find out how to do this only how to stop a container respawning. When I looked at the Hearthfire milk shelf I couldn't see any scripts on it so I have no idea how Bethesda did that one either.

Link to comment
Share on other sites

Barrels which respawn will generally select its contents from a levelled list. So instead of using a levelled list, you just use the items you want and presumably it would always respawn with the same stuff. Or you could use a levelled list to set an increasing quantity based on your level.

 

As for timers, it has less to do with the container itself and more to do with the cell or general location. In other words, its contents will refresh at the same time as every other container does so in the same cell. For example, a dungeon resets after 10 days (or 30 days if cleared) and a player home never resets. So it comes down to where your container is.

Link to comment
Share on other sites

Is there anyway I can have a barrel in a respawning cell (as my player homes don't respawn) and have it respawn daily? or once every few days but not as slow as once every 10-30 days?

Link to comment
Share on other sites

I haven't seen any settings which change it. The 30-day thing is probably only for areas which can be cleared, so I suppose you're looking at 10 days. If there are any settings for this then I'd love to know because I would lower it considerably because 30 days is a long time in Skyrim.

Link to comment
Share on other sites

Is there anyway I can have a barrel in a respawning cell (as my player homes don't respawn) and have it respawn daily? or once every few days but not as slow as once every 10-30 days?

 

Yes. You can use OnUpdateGameTime and RegisterForSingleUpdateGameTime to chain together refreshes of any desired length.

Edited by foamyesque
Link to comment
Share on other sites

Oh Papyrus is confusing, I am a visual learner I know i'm going to mess this script up.

Can I set a container as a merchant chest (which has a two day respawn) and just not have it connected to any merchants but my container trigger?

Edited by Bersark93
Link to comment
Share on other sites

Use this sample script. Keep in mind papyrus scripting is almost learning by doing.

 

AddItemToContainerScript

 

Scriptname AddItemToContainerScript extends ObjectReference  
{written by ReDragon 2017}    ; attach this script to a new container baseObject

; best way: make a copy of "BarrelFood01_NoRespawn" [CONT:0010E882] the baseObject, name the copy "Barrel of Salt"
; if you like to have a sack use this: "MiscSack02Small_NoRespawn" [CONT:0010E889]

; https://forums.nexusmods.com/index.php?/topic/5993913-help-making-a-respawning-container/
; Bersark93 wrote: "trying to make a respawning salt barrel that respawns with x3 Salt Pile daily"


 ;GlobalVariable PROPERTY GameDaysPassed auto    ; use auto fill
  Float fNewDay                                  ; Zero by default, do not change!

; the item base object which should be placed
 ;MiscObject PROPERTY myItem auto                ; [MISC:0000000F] Gold001  // gold is a miscItem
  Ingredient PROPERTY myItem auto                ; [INGR:00034CDF] SaltPile // but salt is an ingredient

  Int PROPERTY count = 3 auto                    ; Three by default // How many of the above Items should the container have at least?


; -- EVENTs --

EVENT OnLoad()
IF ( myItem )
ELSE
    myF_Info(-1)
    RETURN    ; - STOP -    you forgot to fill the property
ENDIF
;---------------------
;;; float f = GameDaysPassed.GetValue()
    float f = Utility.GetCurrentGameTime()        ; https://www.creationkit.com/index.php?title=GetCurrentGameTime_-_Utility

IF (fNewDay > 0) && (f < fNewDay)
    RETURN    ; - STOP -    barrel got 3D more than once within a day
ENDIF
;---------------------
    fNewDay = f + 1.0                            ; 1.0 = wait one day, 2.0 = wait two days, ..
    myF_Add()
ENDEVENT


EVENT OnUnLoad()
    myF_Info(-2)            ; info only
ENDEVENT


EVENT OnActivate(ObjectReference akActionRef)
;;;    myF_Info(0, akActionRef)
ENDEVENT


EVENT OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
    ; https://www.creationkit.com/index.php?title=OnItemAdded_-_ObjectReference
ENDEVENT

EVENT OnItemRemoved(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
    ; https://www.creationkit.com/index.php?title=OnItemRemoved_-_ObjectReference
ENDEVENT


; -- FUNCTIONs -- 2

;-----------------
FUNCTION myF_Add()
;-----------------
    int i = self.GetItemCount(myItem as Form)
    IF (i < count)
        self.AddItem(myItem as Form, (count - i), TRUE)    ; fill up with these items, which are required
    ENDIF
ENDFUNCTION

;--------------------------------------------------
FUNCTION myF_Info(Int i, ObjectReference oRef=None)
;--------------------------------------------------
IF (i == -2)
    Debug.Trace(self+" OnUnLoad() - has been reached..")
    RETURN    ; - STOP -
ENDIF
;---------------------
IF (i == -1)
    Debug.Trace(self+" OnLoad() - Error: Missing property 'myItem' detected!  " +myItem)
    RETURN    ; - STOP -
ENDIF
;---------------------
;IF (i == 0)
;    Debug.Trace(self+" OnActivate() - has been reached..  with " +oRef)
;ENDIF
ENDFUNCTION

 

 

Link to comment
Share on other sites

That's way more complicated than necessary, I think, ReDragon.

 

My script would be the following:

scriptname BersarkContainerRespawnScript extends ObjectReference

int Property iResetHours = 48 Auto

Event OnInit()
    RegisterForSingleUpdateGameTime(iResetHours)
EndEvent

Event OnUpdateGameTime()
    Reset()
    RegisterForSingleUpdateGameTime(iResetHours)
EndEvent

Set iResetHours to be whatever you like in the properties and you're done. Reset() should set its inventory back to whatever the CK specifies for the base form, so all you need to do is create a custom base form by copying one of the barrels, renaming it to "Salt Barrel", adding the desired contents to its inventory list, and then attaching the script either to the base object or to specific references, depending on your use case.

Edited by foamyesque
Link to comment
Share on other sites

  • Recently Browsing   0 members

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