Difference between revisions of "GetFormFromFile - Game"
Notes/Simple plugin check/CheckForDLC()
imported>JustinOther m ('As FormList' added to example.) |
imported>JustinOther (Notes/Simple plugin check/CheckForDLC()) |
||
Line 18: | Line 18: | ||
== Examples == | == 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. | *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. | ||
<source lang="papyrus"> | <source lang="papyrus"> | ||
Line 29: | Line 29: | ||
endif | endif | ||
</source> | </source> | ||
*To merely detect if a plugin is loaded. | |||
<source lang="papyrus">Bool bIsBagOfHoldingLoaded = Game.GetFormFromFile(0x000012EE, "Bag of Holding.esp") ; Is Bag of Holding.esp loaded?</source> | |||
*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. | |||
<source lang="papyrus">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 sPluginArray[aiIndex]) | |||
bDLCArray[aiIndex] = !bPluginArray[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, sPluginArray[aiIndex]) | |||
bDLCArray[aiIndex] = !bPluginArray[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, sPluginArray[aiIndex]) | |||
bDLCArray[aiIndex] = !bPluginArray[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</source> | |||
== 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. | |||
== See Also == | == See Also == | ||
*[[Game Script]] | *[[Game Script]] | ||
*[[GetForm - Game]] | *[[GetForm - Game]] | ||
*[[GetFormID - Form]] | *[[GetFormID - Form]] |