Jump to content

SKSE: OnCrosshairRefChange & containers


Recommended Posts

I have successfully used OnCrosshairRefChange and performed functions with target objects that have specific keywords. However, I'd like to know if there is a way to target any object that is a container.

 

There is no IsContainer() bool function (that I know of) that I could check against the ref target of OnCrosshairRefChange.

 

Does anyone have any ideas?

Link to comment
Share on other sites

The is because containers are form types, not properties of form types. To identify the type of a form you can either use the Form.GetType() function or cast it to that type. When casting, it will become null if it cannot be cast to that type. So you could either do

; This is preferable if you need to use the object as a container

ObjectReference Ref ; this is the object reference passed by the OnCrosshairRefChange()

Container ContainerRef = Ref as Container

If containerRef
     ; do stuff on Ref or containerRef
EndIf



OR



; This is preferable if you want to cast but don't need it as a container

ObjectReference Ref ; this is the object reference passed by the OnCrosshairRefChange()

If (Ref as Container)
     ; do stuff on Ref
EndIf



OR



; This is preferable if you don't need to use the object as a container, and can get any form type easily

ObjectReference Ref ; this is the object reference passed by the OnCrosshairRefChange()

Int RefType = Ref.GetType() ; or do (Ref as Form).GetType(), but it should auto cast

If (RefType == 28) ; it's a container
     ; do stuff on Ref
ElseIf (RefType == 29) ; can be used for other types too, this checks if it's a door
     ; do stuff on Ref
EndIf

Types can be gotten here. Hope this helps!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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