AddKeyIfNeeded - ObjectReference: Difference between revisions
Jump to navigation
Jump to search
imported>Thingy Person (→Syntax) |
m (Convert source tags to syntaxhighlight) |
||
| Line 6: | Line 6: | ||
== Syntax == | == Syntax == | ||
< | <syntaxhighlight lang="papyrus"> | ||
Function AddKeyIfNeeded(ObjectReference ObjectWithNeededKey) | Function AddKeyIfNeeded(ObjectReference ObjectWithNeededKey) | ||
key NeededKey = ObjectWithNeededKey.GetKey() | key NeededKey = ObjectWithNeededKey.GetKey() | ||
| Line 15: | Line 15: | ||
EndIf | EndIf | ||
EndFunction | EndFunction | ||
</ | </syntaxhighlight> | ||
== Parameters == | == Parameters == | ||
| Line 24: | Line 24: | ||
== Examples == | == Examples == | ||
< | <syntaxhighlight lang="papyrus"> | ||
; Creates a key to BobsDoorRef and puts it in BobRef's inventory if BobRef doesn't already have that key in his inventory. | ; Creates a key to BobsDoorRef and puts it in BobRef's inventory if BobRef doesn't already have that key in his inventory. | ||
BobRef.AddKeyIfNeeded(BobsDoorRef) | BobRef.AddKeyIfNeeded(BobsDoorRef) | ||
</ | </syntaxhighlight> | ||
== See Also == | == See Also == | ||
Latest revision as of 20:53, 5 September 2026
Member of: ObjectReference Script
Checks this object's inventory for a key used by the parameter ObjectWithNeededKey. If this object does not have the key, it creates it and adds it to its inventory.
Syntax[edit | edit source]
Function AddKeyIfNeeded(ObjectReference ObjectWithNeededKey)
key NeededKey = ObjectWithNeededKey.GetKey()
if NeededKey != None
if GetItemCount(NeededKey) == 0
AddItem(NeededKey)
EndIf
EndIf
EndFunctionParameters[edit | edit source]
- ObjectWithNeededKey: The reference that is locked with a key. It will create a key to this object and add it to the calling object if the calling object doesn't already have one.
Return Value[edit | edit source]
None.
Examples[edit | edit source]
; Creates a key to BobsDoorRef and puts it in BobRef's inventory if BobRef doesn't already have that key in his inventory.
BobRef.AddKeyIfNeeded(BobsDoorRef)