Player's inventory - listing, weight, etc. - ESM utility

Post » Wed Jun 20, 2012 6:06 am

Hey guys, in case you need some way to track / monitor and query the player's inventory...
I've released my ESM utility called Inventory and weight: http://skyrim.nexusmods.com/downloads/file.php?id=13244

It allows mods to call these functions:
Spoiler
  • Float Function getWeight (Form item)
  • Bool Function isEquipped (Form item)
  • Armor Function getEquippedArmor ()
  • Armor Function getEquippedGauntlets ()
  • Armor Function getEquippedBoots ()
  • Armor Function getEquippedHelmet ()
  • Form [] Function getInventoryArmor (Bool equipped = False)
  • Form [] Function getInventoryJeweleries (Bool equipped = False)
  • Form [] Function getInventoryMiscObjects ()
  • Form [] Function getInventoryPotions ()
  • Form [] Function getInventoryWeapons (Bool equipped = False)
  • Form [] Function getInventoryOther ()
  • Float [] Function getWeights ()

How to use:
  • set the quest to a property in your script:
    kuiawq Property questInv Auto
  • call the functions like this:
    Float leftWeaponWeight = questInv.getWeight (Game.GetPlayer ().GetEquippedWeapon (1))
  • arrays returned have the limit of 128 elements
  • after calling any of the getInventory* functions, getWeights () will return an array of the items returned
  • e.g.:
    Spoiler
    Form [] equippedArmour = questInv.getInventoryArmor (True)Floats [] weights = questInv.getWeights ()Int i = 0Bool exitLoopWhile i < equippedArmour.Length && !exitLoop    Form armour = equippedArmour [i]    If armour        ;because the array will be 128 Length, there will be elements that are empty        Debug.Trace ("equipped armour " + armour + " weight: " + weights [i])    Else        ;the loop has hit an empty array. no more items past this.        exitLoop = True    EndIf    i += 1EndWhile
  • the singular use getWeight (Form item) only returns weight of items that are in the player's inventory.

Here's it's read-me:
Spoiler
Short description
=================
This is a ESM mod utility required by some of my mods. It tracks the player's inventory and the weight of each item in it.

Gameplay changes
================
None. This is a ESM mod utility required by some of my mods. It tracks the player's inventory and the weight of each item
in it.

Activate this mod in an interior cell with few actors.

When first activated, the mod will temporarily remove all your inventory items. It will then require about 60 seconds
to poll each item and calculate its weight. It will take this long because of the amount of items you gain from the
mod giving you back your inventory.

When in normal play, when you acquire new items in your inventory, it will poll those items for their weight. Because of
the small amount of items you gain during normal play, this polling will almost be instantaneous and will have no
impact on your gameplay.

This ESM mod utility will become obsolete in the future when Skyrim Script Extender is released.

Details
=======
The mod polls for the weight of an item by giving it to you, waiting for your inventory weight to change then
removing that item again. During normal gameplay, this happens near to instantaneously that it shouldn't impact
your gameplay.

Modders can use this mod by setting a Script property to point to kuiawqs. E.g.: kuiawqs Property invAndWeightQ Auto

Once done, these methods becom available
to their mods:
Float Function getWeight (Form item)
Bool Function isEquipped (Form item)
Armor Function getEquippedArmor ()
Armor Function getEquippedGauntlets ()
Armor Function getEquippedBoots ()
Armor Function getEquippedHelmet ()
Form [] Function getInventoryArmor (Bool equipped = False)
Form [] Function getInventoryJeweleries (Bool equipped = False)
Form [] Function getInventoryMiscObjects ()
Form [] Function getInventoryPotions ()
Form [] Function getInventoryWeapons (Bool equipped = False)
Form [] Function getInventoryOther ()
Float [] Function getWeights ()

Functions that return arrays (e.g. getInventoryArmor ()) will always return an array with 128 elements.

getWeights () return an array of weights for the inventory query last called. E.g when a query for equipped
jeweleries is called (e.g. invAndWeightQ.getInventoryJeweleries (True)), getWeights () will return the weights for those
jewelery items returned.

Once SKSE is released with its links to Papyrus, all this will become obsolete. I can't wait!
User avatar
Jenna Fields
 
Posts: 3396
Joined: Mon Dec 11, 2006 11:36 am

Post » Wed Jun 20, 2012 4:19 am

Looks great...

Can your script be attached to any actor or only the player?
User avatar
Josh Lozier
 
Posts: 3490
Joined: Tue Nov 27, 2007 5:20 pm

Post » Wed Jun 20, 2012 8:07 am

It's player only unfortunately. I wasn't getting changes to GetActorValue ("CarryWeight") quick enough on NPCs.
User avatar
Allison C
 
Posts: 3369
Joined: Mon Dec 18, 2006 11:02 am

Post » Wed Jun 20, 2012 2:22 pm

Do you mind if I hack your source about, as I'd like to have GetEquippedHelmet() for other actors....?

I'm trying to make a "NPCs equip helm onCombatStart" script....

Thanks
User avatar
x_JeNnY_x
 
Posts: 3493
Joined: Wed Jul 05, 2006 3:52 pm

Post » Wed Jun 20, 2012 6:22 am

Do you mind if I hack your source about, as I'd like to have GetEquippedHelmet() for other actors....?

I'm trying to make a "NPCs equip helm onCombatStart" script....

Thanks
You don't need anything fancy for that.
Inside that spoiler is a script which should accomplish what you want. Don't look unless you want to.
Spoiler
scriptname XsAutoEquipHelmetInCombat extends Actor;////////////////////////////////////////////////////////////////////////////// Properties/////////////////////////////////////////////////////////////////////////////;Keyword property ArmorHelmet autoForm property LastHelmet auto hidden;////////////////////////////////////////////////////////////////////////////// Events/////////////////////////////////////////////////////////////////////////////;event OnObjectEquipped(Form baseObject, ObjectReference reference)	if (baseObject.HasKeyword(ArmorHelmet))		LastHelmet = ArmorHelmet	endifendeventevent OnObjectUnequipped(Form baseObject, ObjectReference reference)	if (baseObject.HasKeyword(ArmorHelmet))		LastHelmet = none	endifendeventevent OnCombatStateChanged(Actor target, int combatState)	if (!LastHelmet)		return	endif	if (combatState == 0)		target.UnequipItem(LastHelmet, false, true)	else		target.EquipItem(LastHelmet, false, true)	endifendevent
Edit: You could further improve it by using states, because as it is now, there is a slight overhead which can be avoided.

NOTE: This script has an important issue, see RandomNoob's post, right below this one for the details
User avatar
jasminε
 
Posts: 3511
Joined: Mon Jan 29, 2007 4:12 am

Post » Wed Jun 20, 2012 12:04 pm

@Xetrill

I think there might be some problem with the logic of the script, not anything to do with the code though. If you unequip the helmet, then LastHelmet is none. So when the actor enters combat, the script will keep on hitting that 'return'.

In other words, this will only work the first time, when the actor already has the helmet equipped. After combat, the helmet is automatically unequipped and then you will never get to the Unequip/Equip functions again.

Well, this is assuming that scripted Equip/Unequip will trigger the OnObjectEquipped/OnObjectUnequipped events.

It might not be as elegant, but I would remove the OnObjectUnequipped event.
User avatar
Jarrett Willis
 
Posts: 3409
Joined: Thu Jul 19, 2007 6:01 pm

Post » Wed Jun 20, 2012 2:22 am

Ahh you are certainly correct RandomNoob.

I didn't plan on providing a complete solution so its kinda okay. It can still serve as inspiration.
But I'll mark it as broken just in case.

Nonetheless, it's not that hard to fix and keep that functionality intact.
User avatar
Sarah Evason
 
Posts: 3507
Joined: Mon Nov 13, 2006 10:47 pm

Post » Wed Jun 20, 2012 9:57 am

Actually, someone was making a "Knock an NPC out" script that let you temporarily kill an NPC, but had the unfortunate side effect of unequipping any clothes they had on (He wanted to prevent the respawning of items you took off them when unconscious, so he stored the remaining stuff in a box, then strip off the respawned gear and put what was left in the box back) - if you can get an array of the equipment in an NPC's inventory, you could also then order them to get dressed by running through the list and doing an NPC.EquipItem() on each item.
User avatar
Stat Wrecker
 
Posts: 3511
Joined: Mon Sep 24, 2007 6:14 am

Post » Wed Jun 20, 2012 3:12 am

Thanks Guys :)

Here's the finished version that works - might release it too, then you get to see the girls pretty faces :)

Spoiler
Scriptname ScarabFollowerUnequipHelmet extends ReferenceAlias  ;===============  PROPERTIES  ==========================================;Keyword property ArmorHelmet autoForm property LastHelmet auto hidden;===============    EVENTS    ==========================================;Event OnObjectEquipped(Form baseObject, ObjectReference reference)  if (baseObject.HasKeyword(ArmorHelmet))    LastHelmet = baseObject    debug.trace("ScarabFollower: Helmet = " + LastHelmet)    if (self.GetActorReference().IsInCombat())      debug.trace("ScarabFollower: Helmet = " + LastHelmet + " keeping")    else      debug.trace("ScarabFollower: Helmet = " + LastHelmet + " unequipping")      self.GetActorReference().UnequipItem(LastHelmet, false, true)    endif  endifendEventEvent OnCombatStateChanged(Actor target, int combatState)  if (!LastHelmet)    return  endif  if (combatState == 0)    debug.trace("ScarabFollower: Helmet = " + LastHelmet + " unequipping")    self.GetActorReference().UnequipItem(LastHelmet, false, true)  else    debug.trace("ScarabFollower: Helmet = " + LastHelmet + " equipping")    self.GetActorReference().EquipItem(LastHelmet, false, true)  endifendEvent
User avatar
Emmi Coolahan
 
Posts: 3335
Joined: Wed Jan 24, 2007 9:14 pm

Post » Wed Jun 20, 2012 4:36 pm

On the downside, we also get to see the Orc girl faces.
User avatar
Riky Carrasco
 
Posts: 3429
Joined: Tue Nov 06, 2007 12:17 am


Return to V - Skyrim