Creating a chest for a specific item type?

Post » Mon Nov 19, 2012 9:07 am

Hi all...longtime morrowind modder here just now getting into skyrim modding with a scripting question.

Basically, i want to add some chests to my house that only accept certain types of items, i.e. alchemy ingredients in one, weapons in another, soul gems in another, etc.

I've searched for seemingly hours and the only thing i've found about this on the web is here: http://www.creationkit.com/Complete_Example_Scripts#Script_a_container_that_only_accepts_certain_types_of_items

So I went ahead and made a new FormList containing all the alchemy ingredients, made a chest with nothing in it (no respawn), and attached the script in the link to the chest.

When i open the chest in game, it acts as a normal chest, and accepts all types of items, as if the script isn't even being seen.

I'm admittedly a noob to this part of the creation kit (I'm more of a level design type), but i'm sure i'm doing something wrong, i just don't know what. Unless the linked script is wrong, which is another issue.

Would appreciate any help or examples (seems i learn best by reverse engineering, so if anyone knows of any mods that do this correctly, i'd appreciate that, too). Thanks a ton. :biggrin:
User avatar
Jason Rice
 
Posts: 3445
Joined: Thu Aug 16, 2007 3:42 pm

Post » Sun Nov 18, 2012 10:00 pm

Was noticing the script you linked is checking against the player's inventory, and refusing to accept items from the form list into the player's inventory. Extending this idea, you will need to have a script for each chest you intend to filter non-specific items (I.E. MyAlchemyChestFilterScript), along with their associated property (I.E. Container Property MyAlchemyChestRef auto), replacing the reference in the check with the chest.

If this event does not automatically handles this for you, you will probably want to also re-add the item to the player if it is refused, which will still require that PlayerReference property.
User avatar
Sammygirl
 
Posts: 3378
Joined: Fri Jun 16, 2006 6:15 pm

Post » Mon Nov 19, 2012 11:11 am

What you looking for is something like this

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)If akBaseItem as Book; Debug.Notification((MIndex - (Self.GetItemCount(ItemBook) + Self.GetItemCount(ItemRecipe))))If aiItemCount <= (MIndex - (Self.GetItemCount(ItemBook) + Self.GetItemCount(ItemRecipe)))While aiItemCount > 0GetEmptyRef(akBaseItem, akSourceContainer)aiItemCount -= 1EndWhileElseSelf.RemoveItem(akBaseItem, aiItemCount, true, akSourceContainer)BookShelfNoMoreRoomMESSAGE.Show()EndifElseSelf.RemoveItem(akBaseItem, aiItemCount, true, akSourceContainer)BookShelfNotABookMESSAGE.Show()EndifEndEvent

This is an excerpt from my own Bookcase script dealing with returning any items added that are not Books structurally its nearly identical to the original Bethesda OnItemAdded section of their Bookcase script.

This is the only section that should concern you, just replace Book with any other form to exclude all but that form as items that the chest will accept -> also if you do prefer using FormLists to be exact as to whats available to be placed inside you can so that as well.

If akBaseItem as Book

Else
Self.RemoveItem(akBaseItem, aiItemCount, true, akSourceContainer)
EndIf
User avatar
Rinceoir
 
Posts: 3407
Joined: Thu Jun 29, 2006 1:54 am

Post » Mon Nov 19, 2012 4:47 am

Sweet, this worked like a charm. I was about to go muck around with the bookshelf scripts myself but you saved me the trouble.

Thanks again!

-Sky
User avatar
Phillip Brunyee
 
Posts: 3510
Joined: Tue Jul 31, 2007 7:43 pm


Return to V - Skyrim