Difference between revisions of "GetFormFromFile - Game"
Jump to navigation
Jump to search
imported>JustinOther m (bPluginArray Δ bDLCArray) |
imported>JustinOther m (Missed more renamed vars.) |
||
Line 40: | Line 40: | ||
aiIndex -= 1 | aiIndex -= 1 | ||
If aiIndex == 0 ; Dawnguard.ESM | If aiIndex == 0 ; Dawnguard.ESM | ||
If bDLCArray[aiIndex] != Game.GetFormFromFile(0x00000000 | If bDLCArray[aiIndex] != Game.GetFormFromFile(0x00000000 sDLCArray[aiIndex]) | ||
bDLCArray[aiIndex] = !DLCArray[aiIndex] | bDLCArray[aiIndex] = !DLCArray[aiIndex] | ||
If bDLCArray[aiIndex] | If bDLCArray[aiIndex] | ||
Line 49: | Line 49: | ||
EndIf | EndIf | ||
ElseIf aiIndex == 1 ; Hearthfire.ESM | ElseIf aiIndex == 1 ; Hearthfire.ESM | ||
If bDLCArray[aiIndex] != Game.GetFormFromFile(0x00000000, | If bDLCArray[aiIndex] != Game.GetFormFromFile(0x00000000, sDLCArray[aiIndex]) | ||
bDLCArray[aiIndex] = !DLCArray[aiIndex] | bDLCArray[aiIndex] = !DLCArray[aiIndex] | ||
If bDLCArray[aiIndex] | If bDLCArray[aiIndex] | ||
Line 58: | Line 58: | ||
EndIf | EndIf | ||
ElseIf aiIndex == 2 ; KillerBees.esp | ElseIf aiIndex == 2 ; KillerBees.esp | ||
If bDLCArray[aiIndex] != Game.GetFormFromFile(0x0000ABCD, | If bDLCArray[aiIndex] != Game.GetFormFromFile(0x0000ABCD, sDLCArray[aiIndex]) | ||
bDLCArray[aiIndex] = !DLCArray[aiIndex] | bDLCArray[aiIndex] = !DLCArray[aiIndex] | ||
If bDLCArray[aiIndex] | If bDLCArray[aiIndex] |
Revision as of 22:04, 23 June 2012
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
Form Function GetFormFromFile(int aiFormID, string asFilename) native global
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, 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.
; 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
- To merely detect if a plugin is loaded.
Bool bIsBagOfHoldingLoaded = Game.GetFormFromFile(0x000012EE, "Bag of Holding.esp") ; Is Bag of Holding.esp loaded?
- 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 and string array, each with one element per DLC to check. When setting up the properties, leave the boolean elements with their default 'False' values and set each string element with the exact name of the plugin to check for such that their indices correspond. For this to work, the '000000' instances must be changed to match a known existing FormID in each plugin.
Bool[] Property bDLCArray Auto
String[] Property sDLCArray Auto
Function CheckForDLC(Int aiIndex = 0, String asDLCName = "")
aiIndex = bDLCArray.Length
While aiIndex > 0
aiIndex -= 1
If aiIndex == 0 ; Dawnguard.ESM
If bDLCArray[aiIndex] != Game.GetFormFromFile(0x00000000 sDLCArray[aiIndex])
bDLCArray[aiIndex] = !DLCArray[aiIndex]
If bDLCArray[aiIndex]
Debug.Trace("Dawnguard.ESM is loaded")
Else
Debug.Trace("Dawnguard.ESM was loaded, but is no longer")
EndIf
EndIf
ElseIf aiIndex == 1 ; Hearthfire.ESM
If bDLCArray[aiIndex] != Game.GetFormFromFile(0x00000000, sDLCArray[aiIndex])
bDLCArray[aiIndex] = !DLCArray[aiIndex]
If bDLCArray[aiIndex]
Debug.Trace("Hearthfire.ESM is loaded")
Else
Debug.Trace("Hearthfire.ESM was loaded, but is no longer")
EndIf
EndIf
ElseIf aiIndex == 2 ; KillerBees.esp
If bDLCArray[aiIndex] != Game.GetFormFromFile(0x0000ABCD, sDLCArray[aiIndex])
bDLCArray[aiIndex] = !DLCArray[aiIndex]
If bDLCArray[aiIndex]
Debug.Trace("KillerBees.esp izzz loaded")
Else
Debug.Trace("KillerBees wazzz loaded, but izzz no longer")
EndIf
EndIf
ElseIf aiIndex == 3 ; DLC04.ESM
; etc.
ElseIf aiIndex == 4 ; DLC05.ESM
; etc.
EndIf
EndWhile
EndFunction
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.