GetFormFromFile - Game: Difference between revisions

Jump to navigation Jump to search
m
Convert source tags to syntaxhighlight
imported>JustinOther
m (→‎Examples: Omitted '> 0' as iIndex is cast as 'False' when it counts down to 0, ending the loop on time after all.)
m (Convert source tags to syntaxhighlight)
Line 7: Line 7:


== Syntax ==
== Syntax ==
<source lang="papyrus">
<syntaxhighlight lang="papyrus">
Form Function GetFormFromFile(int aiFormID, string asFilename) native global
Form Function GetFormFromFile(int aiFormID, string asFilename) native global
</source>
</syntaxhighlight>


== Parameters ==
== Parameters ==
Line 21: Line 21:
*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">
<syntaxhighlight lang="papyrus">
; Obtain form 0000ABCD we expect to be added by the KillerBees plugin
; 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
; Note the top most byte in the given ID is unused so 0000ABCD works as well as 0400ABCD
Line 29: Line 29:
   beekillerlist.AddForm( WeapBeeSlayer )
   beekillerlist.AddForm( WeapBeeSlayer )
endif
endif
</source>
</syntaxhighlight>
*To merely detect if a plugin is loaded.
*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>
<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).
*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).
<source lang="papyrus">Bool[] Property bDLCIsLoaded Auto ; Element 0 is bDawnguard, etc.
<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.
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.
String[] Property sDLCName Auto ; Element 0 is Dawnguard.ESM, Element 1 is HearthFires.ESM, element 2 is Dragonborn.ESM, etc.
Line 64: Line 64:
EndIf
EndIf
EndWhile
EndWhile
EndFunction</source>
EndFunction</syntaxhighlight>


== Notes ==
== Notes ==

Navigation menu