Jump to content

Obtain a Container Name?


Recommended Posts

So, I was reading through this thread and looking over the Papyrus documentation...

https://forums.nexusmods.com/index.php?/topic/5294165-get-container-currently-accessed-by-player/page-2

 

I'm interested in being able to use an object reference with GetName() to get the full name of any container opened BEFORE doing any ItemAdded or ItemRemoved action and wondering if it is indeed possible. It seems to be pretty straightforward (as below) with furniture, but less so with containers. I don't think I need to go as far as getting the specific FormID, but it would be good to know if the container is a chest, a sack, a barrel, etc, and Full Name seemed like the easiest way to go.

 

Furniture is set up like so:

 

ObjectReference Property furniture_using auto

 

Function handle_using_furniture(ObjectReference obj)
if !is_enabled
return
endif
_debug("Using Furniture")
Debug.Notification("Using Furniture")
furniture_using = obj

String furniture_name = furniture_using.GetBaseObject().GetName()
Debug.Notification("The Object Name is " + furniture_name)
EndFunction

Link to comment
Share on other sites

The question is: How are you going to get the container reference in order to obtain the name? Especially if you want the name BEFORE the player adds or removes items.

 

Once you answer that question, applying SKSE's GetName function should be fairly easy.

Link to comment
Share on other sites

Hey, there's two ways I can think to do this. If you need to get the name when you first open the container, but before adding or removing items, you can do this:

 

 

 

Event OnInit() 
    RegisterForMenu("ContainerMenu")       
EndEvent


Event OnMenuOpen(String menuName)
    ObjectReference ContainerRef = Game.GetCurrentCrosshairRef()    
    
    If ContainerRef
        String ContainerName = ContainerRef.GetBaseObject().GetName()
        Debug.Notification(ContainerName)
    Endif 
EndEvent

If you need to get the reference before you even open the menu, you can do this:

Event OnInit() 
    RegisterForCrosshairRef()
EndEvent

Event OnCrosshairRefChange(ObjectReference ref)
    If Ref 
        Form Base = Ref.GetBaseObject()
        If Base as Container 
            String ContainerName = Base.GetName()
            Debug.Notification(ContainerName)
        Endif 
    Endif 
EndEvent 

Using OnCrosshairRefChange is script intensive though. That event will fire a lot so I wouldn't keep it on all the time.
Edited by dylbill
Link to comment
Share on other sites

Wow, I think that first method will work perfectly! I was thinking doing it OnMenuOpen but I think register is the piece I was missing. I only need the name when actually interacting with the container, but before adding/removing items. Let me give it a try! Thank you!!

 

Edit: Yeah the crosshair piece is interesting because I was thinking simply opening the conatainer would be enough but it sounds like something else is needed to identify the container. 'this' is used in Javascript, so was hoping Papyrus had something similar.

Link to comment
Share on other sites

No problem. The first method is the way to go then. I tested it and it does work. If you want to be absolutely sure the reference is a container you can add another check like so:

 

 

 

Event OnInit() 
    RegisterForMenu("ContainerMenu")       
EndEvent

Event OnMenuOpen(String menuName)
    ObjectReference ContainerRef = Game.GetCurrentCrosshairRef()    
    
    If ContainerRef
        Form Base = ContainerRef.GetBaseObject()
        If Base as Container 
            String ContainerName = Base.GetName()
            Debug.Notification(ContainerName)
        Endif
    Endif 
EndEvent

Link to comment
Share on other sites

That's a good point. To be more precise you can use skse's UI script GetString(String menuName, String target) https://www.creationkit.com/index.php?title=UI_Script

 

I'm not sure which string exactly to search for, but you can go here for examples of UI script: https://github.com/schlangster/skyui.plugins/blob/master/PapyrusScaleform/UI.psc

 

And here for action script repository:

https://github.com/Mardoxx/skyrimui/tree/master/src

Edited by dylbill
Link to comment
Share on other sites

Well, tested and the script works a charm for visible containers in the game, thank you! It's not as full a solution for containers created dynamically or via script. I already am using the UI Script (isMenuOpen) to determine if a Container Menu is open, but not sure how that that could be translated into getting the reference for the specific container object name being used by a script. What are the target values being shown in those GetString api examples (_global.test.a.b.c)? This is a big discovery for me though, and a good place to start.

Link to comment
Share on other sites

I could be wrong. I think that the GetString function's Target parameter needs a string variable from the SWF file associated with the menu passed into the menuName parameter. How and where one would get said string data, I have no idea. Once one moves beyond the realm of papyrus, I'm pretty much clueless.

Link to comment
Share on other sites

Thanks Ishara. Don't think I'm ready to go delving into swf files to do. Gosh, wouldn't it be nice if you could do reference queries on the currently activated object? Getting the visible references is the next best thing, though.

 

ObjectReference ContainerRef = Game.GetCurrentActiveObjectRef()

Link to comment
Share on other sites

  • Recently Browsing   0 members

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