SteelyGlint Posted February 19, 2012 Share Posted February 19, 2012 I'm fairly new to modding, and I've got a scripting question. Is there an easy way to query the contents of a container? Specifically, I'd like to be able to be able to get a list of the items held within, a random item, the most valuable item of a specific type, and/or a random item of a specific type. Thanks! Link to comment Share on other sites More sharing options...
Cipscis Posted February 19, 2012 Share Posted February 19, 2012 No, unfortunately there's not. Only if you know what item(s) you're looking for can you make queries about the contents of a container. Cipscis Link to comment Share on other sites More sharing options...
SteelyGlint Posted February 19, 2012 Author Share Posted February 19, 2012 Would it be possible to maintain a list of the types of item in a container in a FormList, adding or removing list elements with OnItemAdded/OnItemRemoved events? Link to comment Share on other sites More sharing options...
Cipscis Posted February 19, 2012 Share Posted February 19, 2012 It should be, yeah, if you can attach a script to the container and know the initial state of its inventory. Keep in mind, however, that a FormList is global, so if you want more than one instance of this container you might want to take another approach, like a set of arrays as variables in your script. Have a play with it, you'll probably be able to get something working. Cipscis Link to comment Share on other sites More sharing options...
SteelyGlint Posted February 19, 2012 Author Share Posted February 19, 2012 Fortunately, the container is unique so a global list is fine. Is there a maximum size for a FormList? Seems like 128 is the maximum size for an array and while I don't expect that size would be exceeded under most circumstances, it would be a good thing to know. Link to comment Share on other sites More sharing options...
SteelyGlint Posted February 19, 2012 Author Share Posted February 19, 2012 Now I'm trying to get the gold value of items added or removed from the container. The OnItemAdded and OnItemRemoved functions each provide a Form parameter named akBaseItem and an ObjectReference parameter named akItemReference. The akBaseItem is a Form, and can be queried about its value. Since it's the base item, this would not include the value of any enchantments on the item, which I need. The akItemReference seems to contain the information I'm looking for: a reference to the specific item added or removed from the container. However, I'm not sure how to get game item handling functions like GetGoldValue() to work with an ObjectReference, as they only seem to work with Form objects. This also makes me worried that I won't be able to store ObjectReference objects in a FormList. Is there a way to cast an ObjectReference object into a Form object? The fact that the word cast can mean translation from one data type to another as well as using a magic spell makes it very hard to search the internet for this information. If not (and I have no idea if that question is stupid, since due to my inexperience and the poor documentation I'm not entirely sure what either data type is), how could I keep track of the objects placed in my container in a way that allows me to determine their gold value including enchantments? Link to comment Share on other sites More sharing options...
Cipscis Posted February 19, 2012 Share Posted February 19, 2012 ObjectReference extends Form, so casting ObjectReference as Form will work every time. I also expect you should be able to add an ObjectReference to a FormList without any issues, although you may end up with problems due to persistence, so watch out. I discovered the importance of being aware of persistence first hand the other night. I don't know if it's possible to get the ObjectReference-specific value for an instance of an item. You may need to wait for SKSE for that functionality. Cipscis Link to comment Share on other sites More sharing options...
SteelyGlint Posted February 19, 2012 Author Share Posted February 19, 2012 I think you're right that persistence (or a lack thereof) is what is causing my problems. When I called GetGoldValue() on the akItemReference parameter, it returned a value of 0. The documentation for OnItemAdded() says that akItemReference will have a value of None if the object is non-persistent, which seems to be the case. You may be right that it's impossible to get the information I need since it's apparently not passed to the OnItemAdded() function, and by the time OnItemAdded() is called it's already too late to make the object persistent. Thanks for the help. I'll keep trying to figure out if there's any way to get the information I need. Link to comment Share on other sites More sharing options...
SteelyGlint Posted February 20, 2012 Author Share Posted February 20, 2012 Hmmm... do you think there would be some way to extract an ObjectReference from the items if they were stored in an Actor's inventory rather than in a container? Are there any functions that get this kind of info from Actors but don't work on containers? Or would it be exactly the same problem? Link to comment Share on other sites More sharing options...
Cipscis Posted February 20, 2012 Share Posted February 20, 2012 Exactly the same, I'm afraid. For all intents and purposes with regard to inventories, actors and containers can basically be treated as identical. Cipscis Link to comment Share on other sites More sharing options...
Recommended Posts