Jump to content

[LE] Cycling trough all opened containers


Recommended Posts

Hello All!

 

Im new on Skyrim mod creation. I been reading some guides and watched some videos but what I wish to accomplish is hard to find.

Btw, im good at coding Python, I have no problem with that. What I need is help to understand the creation kit systems to be able to do this:

 

 

I need to run a custom made script each time the PC opens any (even mod added ) container in game.

This script would cycle through every item and detect wich are magical items (have enchantments)

 

I dont know if I have to manually place the script on every container type in game or if there's another easier way.

 

Always bearing in mind I wish my future mod to be very friendly compatibilitywise.

 

Thanks

 

 

Link to comment
Share on other sites

This is doable and will require SKSE most likely. Also keep in mind that by cycling through the items in a container you'll be using up processing time that would otherwise be used for other things. This could cause some slowdowns in the papyrus system should there be a lot of items in a given container.

 

At any rate, create a quest record and flag it as start game enabled and run once. You will add a papyrus script to this quest.

On the script: You want to register for the container menu (RegisterForMenu). You want to listen for the OnMenuOpen event. You'll need to use GetNumItems to obtain the total # of items in the container (do note that this value will change if the player adds or removes items from the container - as such you may want to use OnMenuClose and figure things out with whatever is remaining in the container instead - depending on your needs of course). You'll then use While to go through the each item in the container and check if said item has an enchantment with GetEnchantment or GetEnchantment (the first is used for base armor and weapon objects - will return pre-defined enchanted items, the second is for catching items enchanted by the player BUT will require moving the item out of the container and into the open world in order to first obtain an object reference ID).

 

While it might have been faster to pre-write the script, I opted to link the necessary information for learning purposes instead.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...