Jump to content

How do I script inject formlists and keywords into other formlists?


RayoftheSun

Recommended Posts

I am trying to make a mod that adds new items to robots and I managed to finally get some submenus working. I have all the keywords and formlists I need ready, but in order to reduce the chance of conflicts I need to use script injection. I am not aware exactly how to do this though. Can anyone give me a rundown or how this is done? Or does anyone know any good templates? I need to add a formlist to DLC01WorkbenchRobotTopListSublist and a keyword to DLC01WorkbenchRobotTopList. 

2023-12-01 11_29_26-Cell View.png

2023-12-01 11_37_17-FormList.png

Edited by RayoftheSun
Link to comment
Share on other sites

Here you go:

Scriptname YOURSCRIPTNAME extends Quest Const	; attach this script to a quest

FormList Property SourceFormList Auto Const	; don't forget to fill the script properties
FormList Property TargetFormList Auto Const

Event OnQuestInit()					; when the quest starts
	If SourceFormList && TargetFormList			; if both FormLists exist (e.g., script properties have been filled out)
		Int Index = SourceFormList.GetSize() - 1	; GetSize() returns how many Forms are in SourceFormList, so Index = size of FormList - 1; note: if Size = 0, then the FormList has no Form in it; size of FormList - 1 is "where" the last Form in the FormList lives
		While Index >= 0						; while this condition is true
			Form LoopForm = SourceFormList.GetAt(Index)		; get the Form in SourceFormList at Index; note: first Form in a FormList can be found at Index = 0
			If LoopForm					; Form exists; simple error check
				If TargetFormList.Find(LoopForm) < 0		; it means "if LoopForm is not in TargetFormList, then"; notes: no Form in a FormList lives at Index < 0, that would mean the Form is simply not in the FormList ("not found" in Papyrus means "return -1")
					TargetFormList.AddForm(LoopForm)	; add LoopForm to TargetFormList; note: the above line is almost redundant because the native code wouldn't allow to add the same Form to the FormList again (hardcoded, intentional limitation)
				EndIf
			EndIf
			Index = Index - 1					; decrement Index so that GetAt() can grab another Form when the loop restarts
		EndWhile							; the loop restarts as long as ("while") Index >= 0; 0 because no Forms can't live in a FormList at Index < 0
	EndIf
EndEvent

 

Edited by LarannKiar
Link to comment
Share on other sites

It's really easy to inject formList inside another formlist using robco patcher: you do it like this:
filterByFormLists=MyMod1.esp|FormListID:formsToAdd=MyMod2.esp|FormListID

I tested this and i was able to retrieve an injected formList inside a parent one.

Edited by lee3310
Link to comment
Share on other sites

On 12/1/2023 at 1:50 PM, LarannKiar said:

Here you go:

Scriptname YOURSCRIPTNAME extends Quest Const	; attach this script to a quest

FormList Property SourceFormList Auto Const	; don't forget to fill the script properties
FormList Property TargetFormList Auto Const

Event OnQuestInit()					; when the quest starts
	If SourceFormList && TargetFormList			; if both FormLists exist (e.g., script properties have been filled out)
		Int Index = SourceFormList.GetSize() - 1	; GetSize() returns how many Forms are in SourceFormList, so Index = size of FormList - 1; note: if Size = 0, then the FormList has no Form in it; size of FormList - 1 is "where" the last Form in the FormList lives
		While Index >= 0						; while this condition is true
			Form LoopForm = SourceFormList.GetAt(Index)		; get the Form in SourceFormList at Index; note: first Form in a FormList can be found at Index = 0
			If LoopForm					; Form exists; simple error check
				If TargetFormList.Find(LoopForm) < 0		; it means "if LoopForm is not in TargetFormList, then"; notes: no Form in a FormList lives at Index < 0, that would mean the Form is simply not in the FormList ("not found" in Papyrus means "return -1")
					TargetFormList.AddForm(LoopForm)	; add LoopForm to TargetFormList; note: the above line is almost redundant because the native code wouldn't allow to add the same Form to the FormList again (hardcoded, intentional limitation)
				EndIf
			EndIf
			Index = Index - 1					; decrement Index so that GetAt() can grab another Form when the loop restarts
		EndWhile							; the loop restarts as long as ("while") Index >= 0; 0 because no Forms can't live in a FormList at Index < 0
	EndIf
EndEvent

 

I have a question. For Sourceformlist am I supposed to replace that with the name of the existing formlist I want to inject into or the formlist I want to inject with? And what would I use for injecting Keywords? Since I need a formlist and a keyword injected. 

 

On 12/2/2023 at 2:39 PM, lee3310 said:

It's really easy to inject formList inside another formlist using robco patcher: you do it like this:
filterByFormLists=MyMod1.esp|FormListID:formsToAdd=MyMod2.esp|FormListID

I tested this and i was able to retrieve an injected formList inside a parent one.

Going to give this a try too, but I also need to inject a keyword in.

Link to comment
Share on other sites

21 hours ago, RayoftheSun said:

I have a question. For Sourceformlist am I supposed to replace that with the name of the existing formlist I want to inject into or the formlist I want to inject with?

SourceFormList should contain the Forms which you'd like to inject to the TargetFormList. So, TargetFormList would receive the Forms from SourceFormList.

21 hours ago, RayoftheSun said:

And what would I use for injecting Keywords? Since I need a formlist and a keyword injected. 

You can put the keywords to SourceFormList so that the script can add them too to TargetFormList.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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