Difference between revisions of "GetActorOwner - ObjectReference"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Zartar
imported>Fireundubh
(explicit vs. inherited ownership)
Line 6: Line 6:


== Syntax ==
== Syntax ==
<source lang="papyrus">
<source lang="papyrus">
ActorBase Function GetActorOwner() native
ActorBase Function GetActorOwner() native
Line 11: Line 12:


== Parameters ==
== Parameters ==
None.
None.


== Return Value ==
== Return Value ==
The [[ActorBase Script|ActorBase]] that owns this object.
The [[ActorBase Script|ActorBase]] that owns this object.


== Examples ==
== Examples ==
=== Returning an explicit owner ===
<source lang="papyrus">
; Does the player own the sword?
Bool playerOwnsSword = SwordProperty.GetActorOwner() == Game.GetPlayer().GetActorBase()
</source>
=== Returning an inherited owner ===
<source lang="papyrus">
<source lang="papyrus">
; Does the player own the sword?
; Does the player own the sword?
bool playerOwnsSword = (SwordProperty.GetActorOwner() == Game.GetPlayer().GetActorBase())
Bool playerOwnsSword = GetInheritedOwner(SwordProperty, SwordRackProperty) == Game.GetPlayer().GetActorBase()
 
ActorBase Function GetInheritedOwner(ObjectReference aObj, ObjectReference aContainer)
    ActorBase actorOwner = aObj.GetActorOwner()
    If !actorOwner
        If aContainer
            actorOwner = aContainer.GetActorOwner()
            If !actorOwner
                actorOwner = aContainer.GetParentCell().GetActorOwner()
            EndIf
        EndIf
        If !actorOwner
            actorOwner = aObj.GetParentCell().GetActorOwner()
        EndIf
    EndIf
    Return actorOwner
EndFunction
</source>
</source>


== Notes ==
== Notes ==
NEEDS VERIFICATION: This function always returns none. It used to work correctly, perhaps it was broken in an update?
 
=== Explicit vs. Inherited Ownership ===
 
Object references can have explicit owners and inherited owners. An ''explicit owner'' is associated directly with the object. An ''inherited owner'' is derived from the container that contains the object, the cell that contains the object, or the cell that contains the container that contains the object when the object has not been associated with an explicit owner. GetActorOwner() returns only the explicit owner of an object reference and None when an explicit owner is not found.


== See Also ==
== See Also ==
*[[ObjectReference Script]]
 
*[[SetActorOwner - ObjectReference]]
* [[ObjectReference Script]]
* [[SetActorOwner - ObjectReference]]

Revision as of 02:51, 8 September 2015

Member of: ObjectReference Script

Gets the ActorBase that owns this object. Will return None if the object isn't owned by an actor.

Syntax

ActorBase Function GetActorOwner() native

Parameters

None.

Return Value

The ActorBase that owns this object.

Examples

Returning an explicit owner

; Does the player own the sword?
Bool playerOwnsSword = SwordProperty.GetActorOwner() == Game.GetPlayer().GetActorBase()

Returning an inherited owner

; Does the player own the sword?
Bool playerOwnsSword = GetInheritedOwner(SwordProperty, SwordRackProperty) == Game.GetPlayer().GetActorBase()

ActorBase Function GetInheritedOwner(ObjectReference aObj, ObjectReference aContainer)
    ActorBase actorOwner = aObj.GetActorOwner()
    If !actorOwner 
        If aContainer
            actorOwner = aContainer.GetActorOwner()
            If !actorOwner
                actorOwner = aContainer.GetParentCell().GetActorOwner()
            EndIf
        EndIf
        If !actorOwner 
            actorOwner = aObj.GetParentCell().GetActorOwner()
        EndIf
    EndIf
    Return actorOwner
EndFunction

Notes

Explicit vs. Inherited Ownership

Object references can have explicit owners and inherited owners. An explicit owner is associated directly with the object. An inherited owner is derived from the container that contains the object, the cell that contains the object, or the cell that contains the container that contains the object when the object has not been associated with an explicit owner. GetActorOwner() returns only the explicit owner of an object reference and None when an explicit owner is not found.

See Also