Background for Skyrim SE
Member of the ObjectReference script
intfunctionGetNumItems()Native

Description

Wiki Description

Returns the number of items in a container. (This function requires SKSE)

Documentation Comment

Container-only functions


Caveats

CK Wiki - Notes

  • The returned value indicates the number of item types in the container regardless of the count of any particular item. If a container has ten gold and a torch, GetNumItems will return '2' and not '11'.

The exception is keys, if you have two of the same key then GetNumItems will count both keys. EDIT: This could be because the keys were quest items. More testing is needed to confirm this.


Examples

Int iNumItems = MQ101AlduinREF.GetNumItems()
Actor Property PlayerREF Auto

Event SomeEvent()
    ReweighIngredientsIn(PlayerREF, 0.1)
EndEvent

Function ReweighIngredientsIn(ObjectReference akContainer, Float afWeight) Global
    Int iFormIndex = akContainer.GetNumItems()
    While iFormIndex > 0
        iFormIndex -= 1
        Form kForm = akContainer.GetNthForm(iFormIndex)
        If kForm.GetType() == 30 ; Ingredient
            kForm.SetWeight(afWeight)
        EndIf
    EndWhile
EndFunction

Auto-Generated Example

int returnedValue = myObjectReference__toCallFunctionOn.GetNumItems()

Related Pages


Additional References

View this function’s page on the Skyrim Creation Kit Wiki

Some data provided by the Skyrim Creation Kit Wiki. Licensed under the Creative Commons Attribution-ShareAlike license.