MadTod Posted October 30, 2016 Share Posted October 30, 2016 I'm in need of a script that respawns the contents of a container, either every time the player enters the cell or after a set number of days. I have a basic understanding of scripts (I can copy and edit script, just not make them from scratch) and think I would need to use Removeitems then AddItems to stop the contents building up unless I could use the ResetInventory function in a script for a container. Basically I need someone with better knowledge than I to write the script for me, preferably using a FormList for the items as I don't want to add 100's of 'AddItem' lines in the script, one for each item (there's quite a few). Any help would be greatly appreciated, thanks. Link to comment Share on other sites More sharing options...
Surilindur Posted October 30, 2016 Share Posted October 30, 2016 (edited) So I am not on my desktop, but if it helps, here are a couple of untested ideas that may or may not actually work. :happy: Assuming ResetInventory resets the contents to default and also restores the original items, then that one would probably be as best good as it gets (edit: oops cannot write English). You can also use OnActivate event I think? Or not? At least for testing purposes. Event OnActivate(ObjectReference akActionRef) If (akActionRef == Game.GetPlayer()) ResetInventory() EndIf EndEventOr if ResetInventory does not restore the original items then adding each item from the FormList to the container one by one would probably be another choice. FormList Property ItemList Auto ; <-- this one points to the item list in the CK Event OnActivate(ObjectReference akActionRef) If (akActionRef == Game.GetPlayer()) Int i = ItemList.GetSize() RemoveAllItems() While (i > 0) i -= 1 AddItem(ItemList.GetAt(i), 10, True) EndWhile EndIf EndEventIf you can find another event to move the scripts in that works better, then that is great. These wiki pages might also be handy for finding all sorts of useful pieces to build things from, related to your idea:http://www.creationkit.com/index.php?title=Category:Script_Objectshttp://www.creationkit.com/index.php?title=ObjectReference_Scripthttp://www.creationkit.com/index.php?title=FormList_ScriptHopefully that helps a little. I have not tested if those compile at all, but just some ideas. If someone spots anything fishy, feel free to correct. I usually make lots of mistakes. :blush: Edited October 30, 2016 by Contrathetix Link to comment Share on other sites More sharing options...
MadTod Posted October 30, 2016 Author Share Posted October 30, 2016 (edited) First one didn't work, apparently 'ResetInventory' isn't a script function but the second one worked a treat, thanks. Addition: Any chance I could exclude a few items from this script, for instance: I have a note in the chest that I don't want to respawn but I also don't want it to be removed from the chest until the player takes it; If the player does not take it the first time the chest is opened it will be gone the second time. Edited October 30, 2016 by MadTod Link to comment Share on other sites More sharing options...
Surilindur Posted October 30, 2016 Share Posted October 30, 2016 No problem. :) What script are you extending (or, inheriting, whatever it is called)? If you have SKSE installed, ResetInventory should be an ObjectReference Script function according to the wiki. Something like this: ScriptName _YourPrefix_ContainerRefScript Extends ObjectReference Event OnActivate(ObjectReference akActionRef) If (akActionRef == Game.GetPlayer()) ResetInventory() EndIf EndEventAnd then adding the script on the reference that you have placed in the game world? In case the CK will not allow you to attach it on the base object (probably will not). Double-clicking the reference in the world should also bring up a list where you can add scripts I think. Or not. I cannot remember how it works at the moment. Maybe you could also cast the thing as ObjectReference if your script extends something else, but I am not sure how it would work (if it would work). Depends on how you have it set up. (Self as ObjectReference).ResetInventory() Link to comment Share on other sites More sharing options...
MadTod Posted October 30, 2016 Author Share Posted October 30, 2016 I've got the script working fine (attatched to the base object), what I would like to know is if I can omit an object or 2 from resetting (persist in tyhe chest until the player removes it). I also do not wish to make this mod dependant on SKSE as this is for a published mod and I don't like publishing mods that require other mods. Link to comment Share on other sites More sharing options...
Surilindur Posted October 30, 2016 Share Posted October 30, 2016 Okay. Great to hear you got it working. I have not looked into container resets and such in Skyrim, and I have no idea how to go about preventing individual items from resetting. Hopefully someone else can help you with that. Link to comment Share on other sites More sharing options...
MadTod Posted October 30, 2016 Author Share Posted October 30, 2016 It's not that important, I've had these mods published for over 4 years and I constantly get comments asking if and when the chests will restock (answer: normal game time), so I think the users of my mods won't mind if there's no longer a thank you note in the chest. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted October 30, 2016 Share Posted October 30, 2016 Here is a modified variation which runs through the formlist and checks the contents of the container before adding in new instances. Anything that is still in the container will remain in the container until normal cell reset. Scriptname SomeScript Extends ObjectReference FormList Property ItemList Auto ; <-- this one points to the item list in the CK Event OnActivate(ObjectReference akActionRef) ObjectReference SelfObj = Self as ObjectReference If (akActionRef == Game.GetPlayer()) Int i = 0 While i < ItemList.GetSize() Form Entry = ItemList.GetAt(i) If SelfObj.GetItemCount(Entry) <= 0 AddItem(ItemList.GetAt(i), 10, True) EndIf i += 1 EndWhile EndIf EndEvent If it doesn't work with the casting of Self into an object reference, then add a property that points to your container and adjust the script accordingly. Also, it may be beneficial to use OnCellAttach event instead of OnActivate. Either will work tho the latter may allow the user to see items appear as they are added to the container. The former may process unnecessarily as the player passes through the area but doesn't access the container. Your choice. Link to comment Share on other sites More sharing options...
MadTod Posted October 30, 2016 Author Share Posted October 30, 2016 Is it possible to do this with a LeveledList instead of a FormList? The chest contains some items with fewer counts that others. Using a FormList, the number of items is defined within the script so I cannot have less of some items and more of other, whereas in a LeveledList the number is defined within the list itself so I can. Link to comment Share on other sites More sharing options...
Surilindur Posted October 30, 2016 Share Posted October 30, 2016 (edited) <snip> Your alternative example uses this: Int i = 0 While i < ItemList.GetSize() <contents> i += 1 EndWhile But mine used this: Int i = ItemList.GetSize() While (i > 0) i -= 1 <contents> EndWhile How does Papyrus handle a function call as a condition in a loop? Does it call it once somehow, or does the compiler optimise it away somehow? I have been taking the number and decreasing it each time, instead of placing a function call in the loop condition, afraid that Papyrus would call the function each loop. Does it not call it? I see people doing it that way, even providing it in their own alternative versions for all sorts of loops, but no one has ever mentioned why they replaced the "x to 0" sort of thing with a "0 to x" when the "0 to x" usually also features a function call with it. This is interesting, and I would love to know why people keep doing it that way. Just me being curious. And confused. :blush: Edited October 30, 2016 by Contrathetix Link to comment Share on other sites More sharing options...
Recommended Posts