Difference between revisions of "SetKeywords - InstanceData"

From the Fallout4 CreationKit Wiki
Jump to navigation Jump to search
imported>Qazaaq
(added f4se member)
 
 
(One intermediate revision by the same user not shown)
Line 19: Line 19:
== Examples ==
== Examples ==
<source lang="papyrus">
<source lang="papyrus">
; Placeholder Code.
; set up the weapon instance
int slotIndex = Game.GetPlayer().GetEquippedItemType(0) + 32
instanceData:Owner myInstance = Game.GetPlayer().GetInstanceOwner(slotIndex)
 
; we want to add the keyword MyKeyword to our instance using an easy-to-use function
instanceData.SetKeywords(myInstance, editKeywords(instancedata.GetKeywords(myInstance), MyKeyword, "add"))
 
; we want to remove the keyword MyKeyword from our instance using an easy-to-use function
instanceData.SetKeywords(myInstance, editKeywords(instancedata.GetKeywords(myInstance), MyKeyword, "remove"))
 
; this will add / remove a keyword from a chosen array
Keyword[] Function editKeywords(Keyword[] mainArray, keyword keywordToUse, string sAction)
; generate an empty array
Keyword[] tempArray = new Keyword[0]
; populate the empty array with the array on the instance
tempArray = mainArray
; options on how to modify the array
if sAction == "add"
; add the keyword into the array
tempArray.Add(keywordToUse)
        ; return our array with the keyword added
return tempArray
elseIf sAction == "remove"
; find the position of the keyword
int removeFrom = tempArray.Find(keywordToUse)
; remove the keyword from that position
tempArray.Remove(removeFrom)
        ; return our array with the keyword removed
return tempArray
    endIf
endFunction
</source>
</source>



Latest revision as of 17:08, 14 October 2022

This article has been flagged as incomplete.
Please help improve the wiki by learning how to contribute.

F4SE Member of: InstanceData Script
Requires F4SE version 0.6.0 or higher.

Placeholder Description.

Syntax[edit | edit source]

Function SetKeywords(Owner akOwner, Keyword[] akKwds) Native Global

Parameters[edit | edit source]

  • akOwner: Placeholder Description.
  • akKwds: Placeholder Description.

Return Value[edit | edit source]

  • None

Examples[edit | edit source]

; set up the weapon instance
int slotIndex = Game.GetPlayer().GetEquippedItemType(0) + 32
instanceData:Owner myInstance = Game.GetPlayer().GetInstanceOwner(slotIndex)

; we want to add the keyword MyKeyword to our instance using an easy-to-use function
instanceData.SetKeywords(myInstance, editKeywords(instancedata.GetKeywords(myInstance), MyKeyword, "add"))

; we want to remove the keyword MyKeyword from our instance using an easy-to-use function
instanceData.SetKeywords(myInstance, editKeywords(instancedata.GetKeywords(myInstance), MyKeyword, "remove"))

; this will add / remove a keyword from a chosen array
Keyword[] Function editKeywords(Keyword[] mainArray, keyword keywordToUse, string sAction)
	; generate an empty array
	Keyword[] tempArray = new Keyword[0]
	; populate the empty array with the array on the instance
	tempArray = mainArray
	; options on how to modify the array
	if sAction == "add"
		; add the keyword into the array
		tempArray.Add(keywordToUse)
        ; return our array with the keyword added
		return tempArray
	elseIf sAction == "remove"
		; find the position of the keyword 
		int removeFrom = tempArray.Find(keywordToUse)
		; remove the keyword from that position
		tempArray.Remove(removeFrom)
        ; return our array with the keyword removed
		return tempArray
    endIf
endFunction

See Also[edit | edit source]