-
Notifications
You must be signed in to change notification settings - Fork 8
Inventories
Manipulating container contents in SKSE is tricky because of the way container inventories are represented in Skyrim's backend model. A container has the items defined by its base form (Items added in the Creation Kit), and then it has modifications to that list that are stored in an extra data list. A negative count on an item indicates that the container has fewer of that item than was originally defined in that container's base form. Any Actor
, including the Player
, can be treated in the exact same way as any chest or other container item.
- Getting container contents is safe because you're not actually modifying what's already there.
TODO: Add code here - Changing the count of items that are already in a counter should also be safe because you are not changing the inventory's data structure TODO: Add code here
- On the other hand, actually adding items to a container is risky. For efficiency, Skyrim will duplicate an existing object to create a new object. If you alter the data structure on an object and Skyrim duplicates it, you will end up with two items that have the changes you made rather than only the item you intended to edit.
"An example where the structure would need to change is if you spawn two Iron Swords, the inventory uses both the same Form entry, and ExtraDataList, but has a count of 2, to alter only one of those two swords you would need to alter the structure to split it into two separate ExtraDataLists" -PurpleLunchbox
Class Heirarchy
TESObjectREFR // The object reference of the container whose inventory you want to work on
->extraData.GetByType(kExtraData_ContainerChanges) //ExtraContainerChanges
->data->objList //EntryDataList
(*position) //EntryData
->countDelta //int
-> type //TESForm
TODO: Link to a gist to download a class of methods to deal with container contents
- Get the name of a
TESForm
object:
#include "skse\PapyrusForm.h"
papyrusForm::GetName(myForm)