Editing
GetFormFromFile - Game
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
[[Category:Scripting]] [[Category:Papyrus]] [[Category:Non-delayed Native Function]] '''Member of:''' [[Game Script]] ''(Requires 1.6)'' Obtains the form specified by its form ID number which originated in the specified file. The ID for a form changes based on the load order of the file it loaded from. So a form which shows up as 0101ABCD in the editor may show up as 0401ABCD in game depending on how many other files load before it. This function lets you blindly grab a form based on the lower bytes of its ID and the expected file which created the form. == Syntax == <syntaxhighlight lang="papyrus"> Form Function GetFormFromFile(int aiFormID, string asFilename) native global </syntaxhighlight> == Parameters == *aiFormID: The form ID number of the form we want. (FormID proceeded by 0x) For example Form ID "0001ABCD" is given as: 0x0001ABCD *asFilename: The name of the file we expect the form to have originated in. == Return Value == The requested [[Form Script|Form]], or None if the form ID is not valid or the file does not exist or is not loaded. == Examples == *Assume a mod or DLC called "KillerBees.esp" was released which made the bee critters agressive and immortal, only killable by weapons in the form list BeeKillerWeapList (0100ABCD). Another mod or DLC wants to add a BeeSlayer sword which they want to be able to kill the killer bees if you have that mod. <syntaxhighlight lang="papyrus"> ; 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 0400ABCD FormList 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 </syntaxhighlight> *To merely detect if a plugin is loaded. <syntaxhighlight lang="papyrus">Bool bIsBagOfHoldingLoaded = Game.GetFormFromFile(0x000012EE, "Bag of Holding.esp") ; Is Bag of Holding.esp loaded?</syntaxhighlight> *Say you want to detect if DLCs are loaded and need to do/undo something in the event a DLC is added or removed from the user's load list: Create a Boolean, Int, and String array, each with one element per DLC to check such that the indices of all three correspond. Leave the boolean elements with their default 'False' values and set each string element with the exact name of the plugin to check for. For this to work, the Int[] elements must match known existing FormIDs in the corresponding plugins converted from Hex to Dec (easily done with Windows' calculator in programmer mode). <syntaxhighlight lang="papyrus">Bool[] Property bDLCIsLoaded Auto ; Element 0 is bDawnguard, etc. Int[] Property iKnownFormID Auto ; Element 0 is 2048 for Dawnguard's DLC1AurielsBow "Auriel's Bow" [WEAP:02000800], etc. String[] Property sDLCName Auto ; Element 0 is Dawnguard.ESM, Element 1 is HearthFires.ESM, element 2 is Dragonborn.ESM, etc. Function CheckForDLC() Int iIndex = sDLCName.Length While iIndex iIndex -= 1 If bDLCIsLoaded[iIndex] != Game.GetFormFromFile(iKnownFormID[iIndex], sDLCName[iIndex]) bDLCIsLoaded[iIndex] = !bDLCIsLoaded[iIndex] If bDLCIsLoaded[iIndex] Debug.Trace(sDLCName[iIndex] + " is loaded") If iIndex == 0 ; Dawnguard ; Make any changes needed for Dawnguard ElseIf iIndex == 1 ; Hearthfire ; Make any changes needed for Hearthfire ElseIf iIndex == 2 ; Dragonborn ; Make any changes needed for Dragonborn EndIf Else Debug.Trace(sDLCName[iIndex] + " was loaded, but is no longer") If iIndex == 0 ; Dawnguard ; Revert any changes previously made for Dawnguard ElseIf iIndex == 1 ; Hearthfire ; Revert any changes previously made for Hearthfire ElseIf iIndex == 2 ; Dragonborn ; Revert any changes previously made for Dragonborn EndIf EndIf EndIf EndWhile EndFunction</syntaxhighlight> == Notes == *If asFilename is not loaded, it will be reported in one's log. *Don't forget to cast if setting a property to any given form type with GetFormFromFile. *Almost invariably, a plugin will have a form with 0x00000800 or 0x00000D62 as its FormID. The latter for a plugin that is masterless when its first form is created and the former when another plugin is loaded at that time. Checking for both FormIDs in most plugins will suffice to merely determine if asFileName is loaded, but there's always the possibility the first form added gets deleted in which case you'd get a false negative. Whenever possible, use a verified FormID that is likely to remain in asFileName. * For plugin files flagged as light masters, including ESL and ESPFE, only the lower three hex digits are needed. The rest should be zeros including the "FE" digits. For example, to get form FExxx85B of an ESL, aiFormID should be given as 0x0000085B. == See Also == *[[Game Script]] *[[GetForm - Game]] *[[GetFormID - Form]] *[[Arrays (Papyrus)#Creating_a_FormID Array|FormID Array]]
Summary:
Please note that all contributions to the CreationKit Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see
CreationKit:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
Edit source
View history
More
Search
Navigation
Landing page
Tutorials
Game Systems
Editor Reference
Scripting Reference
Recent changes
Help
Tools
What links here
Related changes
Special pages
Page information
Page values