Jump to content

finding out ObjectReference's source .esp during runtime


Recommended Posts

Hello

 

Just like in the title - I'd like to find out during runtime which esm/esp/esl file placed some particular object ref in the world. I read some docs on Creation Kit wiki (actor script, objectreference script, etc.) but couldn't find anything like that. Can it be done with papyrus or console commands?

 

To be clear: I'm talking about reference, not base object. So if there's a mod which puts a bunch of vanilla raiders in some location, their base objects will have originated from Fallout4.esm, but their refs will have been put there by the mod's .esp file - and I want to know the name of that file.

 

Any help and insight will be highly appreciated.

Link to comment
Share on other sites

If you click on the reference with the console open, it will show its form ID. The first 2 characters in the ID denote the load order of the mod it came from. Note this is in hexadecimal. To find out the index in your load order, you can type the first two characters into a programmer calculator. Example: AB = 171, 70 = 112 ect. If you're using Wrye Bash it already shows the load order in hex.

 

EDIT: this will only work for references placed in the Creation Kit. I don't think this will work for references spawned with a script via PlaceAtMe.

Link to comment
Share on other sites

There you have a couple of functions I created time ago, those are meant to get a string containing the name of the plugin based on its form id:

String Function GetPluginName(Int FormId)
	Int x = FormId
	String[] hexInvArray = new String[0]
	While x > 0
		hexInvArray.add(x % 16)
		x = x / 16
	EndWhile
	
	String PluginHex = "00"
	If(hexInvArray.Length == 8)
		PluginHex = hexInvArray[7] As String + hexInvArray[6] As String
	ElseIf(hexInvArray.Length == 7)
		PluginHex = "0" + hexInvArray[6] As String
	EndIf
	
	return "\"" + Game.GetInstalledPlugins()[HexToDec(PluginHex As Int)].name + "\""
EndFunction

Int Function HexToDec(Int hexInteger)
	Int Dec = 0
	Int Hex = hexInteger
	int count = 0
	While Hex > 0
		Dec = Dec + (Hex % 10) * (Math.Pow(16, count) As Int)
		Hex /= 10
		count += 1
	EndWhile
	Return Dec
EndFunction 

you would need to call the function like this:

GetPluginName(Ref.GetFormId()) 

PS: There are 2 dawbacks, I wrote this function before esl format existed, and the function asumes that the 2 first characters of the hex form id are the index of the array returned by GetInstalledPlugins, which might not be true now due to the way esl's are alocated in the load order. The second drawback is that GetInstalledPlugins is part of F4SE.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...