Scripting Help: How to get a list of items the player has?

Post » Thu Jun 21, 2012 7:26 am

Hello!

Was messing around in the CK today and wanted to know what items a player has. The closest thing I could find was GetItemCount from which I was able to deduce (for example) that the player has two helmets in his inventory - but i can't find out WHICH two helmets he has..

Is there any way of extracting this information? Optimally I would like it work similiar to GetItemCount where you can pass a keyword such as ArmorHelmet.

Thank you for your time!
User avatar
Pawel Platek
 
Posts: 3489
Joined: Sat May 26, 2007 2:08 pm

Post » Thu Jun 21, 2012 9:45 am

No, I don't think that there is a reliable way to do this (surprisingly, you would think you could iterate the list, but it appears you cannot).

GetItemCount will allow you to specify a keyword as the driver-variable ... which might help you a little bit ... But I don't think you are able to find out which "SteelHelmet":

if (Game.GetPlayer().GetItemCount(WeapTypeSwordKeyword) == 0)  Debug.Trace("Player has no swords")endIf

So, you can check for ANY sword, but not which sword.

If you are very, very desperate for the information, I think you would have to create your own Formlist and amend it each time the player adds or drops an item ... That's one big pain though, if you don't really need the information
User avatar
Adrian Powers
 
Posts: 3368
Joined: Fri Oct 26, 2007 4:44 pm

Post » Thu Jun 21, 2012 2:41 am

To expand on that...

AFAIK you have to put a script on the player (as a quest alias) to track every OnItemAdded / Removed event from the outset to build a list of what the player has.

OnItemEquipped / Unequipped can be used to track which item (if any) is equipped in each slot.

Keywords (e.g. ArmorShield) indicate the item type.

Surprising that Papyrus has no native inventory search function. Bethesda seems to adopt the standard that items of interest are tracked by quests, so they never need to ask directly what the player has.
User avatar
sarah
 
Posts: 3430
Joined: Wed Jul 05, 2006 1:53 pm

Post » Thu Jun 21, 2012 10:35 am

Come to think of it: we have "ShowInventory" for in-game console, can't we use that in Papyrus?
User avatar
Amy Siebenhaar
 
Posts: 3426
Joined: Fri Aug 10, 2007 1:51 am

Post » Thu Jun 21, 2012 8:01 am

Come to think of it: we have "ShowInventory" for in-game console, can't we use that in Papyrus?
No (unsurprisingly!)

There is that BAT file trick that someone has in their sig ... but I don't think even that will help.

I can't see a way to do this (unless one of the Scripting Gods on here knows a way to enumerate the Inventory List?)
User avatar
{Richies Mommy}
 
Posts: 3398
Joined: Wed Jun 21, 2006 2:40 pm

Post » Thu Jun 21, 2012 4:08 pm

you can manipulate player's inventory and form ID check for each item by doing a Removeallitems into a dummy container that has a script on it.

the container will have to have an AddForm function inside the Event block OnItemAdded that adds every item to a custom formlist. then the container will give back all items to the player. you can use the formlist howver you want, every item the player had in their inventpry (minus quest items) will be accessable and recall-able through the form list script functions

the downside to this is the execution is game-intrusive to the player, it is not discreet at all, nor will it work on quest items. all weapons and clothing will be unequipped, even if the code is executed in a split second. you will also have to use the story manager with a quest that tracks every time the player adds/removes an item, which will then perform the container-swap to update the formlist. you can see how this would become extremely annoying to the user

although someone else may think of a better way to get the player's items onto a formlist without having to strip them naked each time.
User avatar
Scared humanity
 
Posts: 3470
Joined: Tue Oct 16, 2007 3:41 am

Post » Thu Jun 21, 2012 7:26 am

Thank you all for your replies. Seems we've all arrived at pretty much the same conclusion and since neither tracking every pick-up/drop or the dummy container is a really good solution I'll have to re-think how to do this without having access to the inventory..

I have to say it's very wierd not to be able to search a players inventory but I guess bethesda didn't find a use for it..

Again, thanks for looking into it guys :)
User avatar
Matthew Warren
 
Posts: 3463
Joined: Fri Oct 19, 2007 11:37 pm

Post » Thu Jun 21, 2012 1:05 am

The Skyrime Script Extender (SKSE) will be adding this functionality, if you don't mind making your mod dependent on it. Because of these Papyrus limitations, I imagine many mods will be using it.

In the meantime, Kuertee created a nice library of code that does the (ahem) "strip search" method--available http://www.gamesas.com/topic/1359925-players-inventory-listing-weight-etc-esm-utility/.
User avatar
Elea Rossi
 
Posts: 3554
Joined: Tue Mar 27, 2007 1:39 am

Post » Thu Jun 21, 2012 3:52 pm

The Skyrime Script Extender (SKSE) will be adding this functionality, if you don't mind making your mod dependent on it. Because of these Papyrus limitations, I imagine many mods will be using it.

In the meantime, Kuertee created a nice library of code that does the (ahem) "strip search" method--available http://www.gamesas.com/topic/1359925-players-inventory-listing-weight-etc-esm-utility/.

Interesting. That mod does the remove all / add all thing which is fairly slow. It is a work-around def. but it feels very ... hacky.

If you don't mind me asking, which route is SKSE going for determining the inventory? I would of course, in a perfect world, not be dependant on any other mod which is why I'd rather solve it myself but I am not quite sure how to. There are a few options but all seem very clunky.

Also, out of curioisty how does the SKSE work? How do you actually add functionality to the engine without the source of the engine available, or does it work similiarly to the mod you linked that you make "hacky" solutions to existing problems (if this came off as offensive, I aplogoize just not sure how to articulate my question)? I'm a junior software engineer myself but haven't really dabbled in this sort of thing though it seems very interesting.
User avatar
kevin ball
 
Posts: 3399
Joined: Fri Jun 08, 2007 10:02 pm

Post » Thu Jun 21, 2012 9:39 am

I'm not associated with the SKSE project, so on one hand no need to worry about offending me, but on the other hand I can't really tell you how it works. I think it is some combination of memory profiling to decipher what the game's internals are doing when, say, the player's inventory is displayed by the UI or the showinventory console command, and then writing their own assembly/C++ code that gets injected at runtime, which enables support for new quasi-native Papyrus functions that can call the same internals. But you should ask on http://www.gamesas.com/forum/183-skyrim-mods/ if you're curious and want a more accurate answer.
User avatar
Jarrett Willis
 
Posts: 3409
Joined: Thu Jul 19, 2007 6:01 pm

Post » Thu Jun 21, 2012 10:02 am

I prefer to be independent, too.

These days, I need a really overwhelming artistic reason to rely on a third-party mod.

For quest purposes, we generally don't need to know about all items in inventory.

For example, I have a case where I only need to know what clothing / armour the player is wearing.

Since there's no GetEquipped... function for that, I invented a plot-related excuse to change the player's costume temporarily. After that, I track what the player is wearing, using events as previously mentioned.

I'm sure there are other workarounds, depending on the specific situation.
User avatar
Elizabeth Lysons
 
Posts: 3474
Joined: Fri Feb 02, 2007 7:16 am

Post » Thu Jun 21, 2012 8:09 am

The Skyrime Script Extender (SKSE) will be adding this functionality, if you don't mind making your mod dependent on it. Because of these Papyrus limitations, I imagine many mods will be using it.

In the meantime, Kuertee created a nice library of code that does the (ahem) "strip search" method--available http://www.gamesas.com/topic/1359925-players-inventory-listing-weight-etc-esm-utility/.
Interesting. That mod does the remove all / add all thing which is fairly slow. It is a work-around def. but it feels very ... hacky.

If you don't mind me asking, which route is SKSE going for determining the inventory? I would of course, in a perfect world, not be dependant on any other mod which is why I'd rather solve it myself but I am not quite sure how to. There are a few options but all seem very clunky.

Also, out of curioisty how does the SKSE work? How do you actually add functionality to the engine without the source of the engine available, or does it work similiarly to the mod you linked that you make "hacky" solutions to existing problems (if this came off as offensive, I aplogoize just not sure how to articulate my question)? I'm a junior software engineer myself but haven't really dabbled in this sort of thing though it seems very interesting.
Inventory and weight is now obsolete. I built it in the time before SKSE's Papyrus support. I recommend using SKSE.
User avatar
Curveballs On Phoenix
 
Posts: 3365
Joined: Sun Jul 01, 2007 4:43 am


Return to V - Skyrim