GetFormFromFile help

Post » Tue Nov 20, 2012 7:51 am

Hey ladies and gents.

I would like a script, and some help, for including objects from another mod in my own.

The premise is this. Real Wildlife, and probably others, add new pelt types to the game. My mod users want to be able to use those pelts for my quests. Large Bear Pelts and the like.

So I would like to delve into GetFormFromFile, to add the items to my formlists, at the beginning of quests that require it. I've never touched that before, so I'm really unsure. Could somebody please help me script it? I envision that when my quest begins, I can run the function to add the items to the formlist, which is what gets tracked for my pelt fetch quests.

As always, I appreciate any help :)
User avatar
Mr. Allen
 
Posts: 3327
Joined: Fri Oct 05, 2007 8:36 am

Post » Tue Nov 20, 2012 9:00 pm

Spoiler
  • Quest
    ScriptName YourQuestScript Extends Quest;=== These 3 have same number of elements ===Bool[] Property bPluginArray Auto ; Elements left 'False'String[] Property sPluginArray Auto ; Element 0 is "Real Wildlife.esp", etc.Int[] Property iKnownFormIDArray Auto ; Element 0 is a known FormID from Real Wildlife.esp converted from hex to dec, etc.FormList Property PeltFLST AutoInt[] Property iRealWildLifePeltIDs Auto ; Contains all Real Wildlife pelt FormIDs converted to decimalEvent OnInit()	Maintenance()EndEventFunction Maintenance(Int aiFormIndex = 0)	Int iIndex = bPluginArray.Length	While iIndex > 0		iIndex -= 1		If bPluginArray[iIndex] != Game.GetFormFromFile(iKnownFormIDArray[iIndex], sPluginArray[iIndex])			bPluginArray[iIndex] = !bPluginArray[iIndex]			If bPluginArray[iIndex] ; One of the plet adding plugins is loaded				If iIndex == 0 ; Real Wildlife.esp					aiFormIndex = iRealWildLifePeltIDs.Length					While aiFormIndex > 0						aiFormIndex -= 1						PeltFLST.AddForm(Game.GetFormFromFile(iRealWildLifePeltIDs[aiFormIndex], sPluginArray[iIndex]))					EndWhile				ElseIf iIndex == 1 ; Something else...				EndIf			Else ; One was loaded, but is no longer				; If just adding stuff to FLSTs, you should not need to do anything as absent forms will be purged w/o intervening.			EndIf		EndIf	EndWhileEndFunction

  • Player Alias
    ScriptName LightweightPotionsPlayerScript Extends ReferenceAliasYourQuestScript Property QuestScript AutoEvent OnPlayerLoadGame()	QuestScript.Maintenance()EndEvent
If checking a lot of plugins, you'll probably want to compartmentalize and put the FLST.AddForm part in another function.
User avatar
Marta Wolko
 
Posts: 3383
Joined: Mon Aug 28, 2006 6:51 am

Post » Tue Nov 20, 2012 9:20 pm

Spoiler
  • Quest
    ScriptName YourQuestScript Extends Quest;=== These 3 have same number of elements ===Bool[] Property bPluginArray Auto ; Elements left 'False'String[] Property sPluginArray Auto ; Element 0 is "Real Wildlife.esp", etc.Int[] Property iKnownFormIDArray Auto ; Element 0 is a known FormID from Real Wildlife.esp converted from hex to dec, etc.FormList Property PeltFLST AutoInt[] Property iRealWildLifePeltIDs Auto ; Contains all Real Wildlife pelt FormIDs converted to decimalEvent OnInit()	Maintenance()EndEventFunction Maintenance(Int aiFormIndex = 0)	Int iIndex = bPluginArray.Length	While iIndex &--#62; 0		iIndex -= 1		If bPluginArray[iIndex] != Game.GetFormFromFile(iKnownFormIDArray[iIndex], sPluginArray[iIndex])			bPluginArray[iIndex] = !bPluginArray[iIndex]			If bPluginArray[iIndex]				If iIndex == 0 ; Real Wildlife.esp					aiFormIndex = iRealWildLifePeltIDs.Length					While aiFormIndex &--#62; 0						aiFormIndex -= 1						PeltFLST.AddForm(Game.GetFormFromFile(iRealWildLifePeltIDs[aiFormIndex], sPluginArray[iIndex]))					EndWhile				ElseIf iIndex == 1 ; Something else...				EndIf			EndIf		EndIf	EndWhileEndFunction
  • Player Alias
    ScriptName LightweightPotionsPlayerScript Extends ReferenceAliasYourQuestScript Property QuestScript AutoEvent OnPlayerLoadGame()	QuestScript.Maintenance()EndEvent
If checking a lot of plugins, you'll probably want to compartmentalize and put the FLST.AddForm part in another function.

That's brilliant mate just what I was looking for :smile:

Lastly, how would I add just 1 of the pelts (Large Bear Pelt for example - using it's FormID) to the formlist, so I can play around with it?

Looking at this script here (It smells like one of yours :wink:) as a base:

; Obtain form 0000ABCD we expect to be added by the KillerBees plugin; Note the top most byte in the given ID is unused so 0000ABCD works as well as 0400ABCDFormList beekillerlist = Game.GetFormFromFile(0x0000ABCD, "KillerBees.esp") As FormList; If "KillerBees.esp" is not loaded the form will be NONE. Otherwise, add our weapon to the list.if ( beekillerlist )  beekillerlist.AddForm( WeapBeeSlayer )endif
User avatar
michael danso
 
Posts: 3492
Joined: Wed Jun 13, 2007 9:21 am

Post » Tue Nov 20, 2012 3:13 pm

The killer bees example is Jeff's and will work perfectly for the addition of a single form. You'll probably want to flesh it out with the array stuff once you get it down, that way you can just add/remove FormIDs to the array(s) if/when a mod adds or subtracts a pelt and/or more easily add plugins to check as time goes by.
User avatar
Patrick Gordon
 
Posts: 3366
Joined: Thu May 31, 2007 5:38 am

Post » Tue Nov 20, 2012 7:37 am

But the object is a Misc Object, so would be it...

MiscObject LargeBearPelt = Game.GetFormFromFile(0x0000ABCD, "Real Wildlife.esp") As MiscObject;if ( LargeBearPelt )  MyFormList.AddForm( LargeBearPelt )endif

To run, check if that mod is loaded, if so, add that specific item to my formlist, which my quest pulls items from?
User avatar
Ian White
 
Posts: 3476
Joined: Thu Jul 19, 2007 8:08 pm

Post » Tue Nov 20, 2012 8:36 pm

Yeah. That will check for the existence of the pelt form and, vicariously, indicate if the plugin is or isn't loaded. Provided Real Wildlife.esp is loaded and LargeBearPelt's FormID is 0xABCD, that will assuredly add it to MyFormList.

Alternatively...
MyFormList.AddForm(Game.GetFormFromFile(0x0000ABCD, "Real Wildlife.esp"))
...will work just as well as the log error will be reported either way if Real Wildlife.esp isn't there.

GetFormFromFile == CoolestFunctionEver
User avatar
Steve Smith
 
Posts: 3540
Joined: Sat Jun 30, 2007 10:47 am

Post » Tue Nov 20, 2012 5:45 pm

Yeah. That will check for the existence of the pelt form and, vicariously, indicate if the plugin is or isn't loaded. Provided Real Wildlife.esp is loaded and LargeBearPelt's FormID is 0xABCD, that will assuredly add it to MyFormList.

Alternatively...
MyFormList.AddForm(Game.GetFormFromFile(0x0000ABCD, "Real Wildlife.esp"))
...will work just as well as the log error will be reported either way if Real Wildlife.esp isn't there.

GetFormFromFile == CoolestFunctionEver

Thanks Justin, such a small line of code, that really adds that little extra something to a mod (allowing other mod support). Legend! :)
User avatar
matt
 
Posts: 3267
Joined: Wed May 30, 2007 10:17 am

Post » Tue Nov 20, 2012 11:27 am

NP, mate, as you'd say :smile: GetFormFromFile is definitely one of my favorite Papyrus functions. It really tears down the walls between/among plugins. Note that it can also reach down, so you can check for plugins loaded not only before, but also after your plugin. Update.ESM, theoretically, could patch up FLSTs for as many DLCs roll out, even though it'll always be loading before 'em.
User avatar
sharon
 
Posts: 3449
Joined: Wed Nov 22, 2006 4:59 am

Post » Tue Nov 20, 2012 3:48 pm

NP, mate, as you'd say :smile: GetFormFromFile is definitely one of my favorite Papyrus functions. It really tears down the walls between/among plugins. Note that it can also reach down, so you can check for plugins loaded not only before, but also after your plugin. Update.ESM, theoretically, could patch up FLSTs for as many DLCs roll out, even though it'll always be loading before 'em.

Defo something I'm going to start using more often :)
User avatar
Peter lopez
 
Posts: 3383
Joined: Mon Sep 10, 2007 5:55 pm


Return to V - Skyrim