Checking whether a mod is active by ID#

LeeS

Imperator
Joined
Jul 23, 2013
Messages
7,241
Location
Illinois, USA
Is it possible to detect whether another mod is active in lua by this method:
Code:
local bIsBNW = ContentManager.IsActive("6DA07636-4123-4018-B643-6575B4EC336B", ContentType.GAMEPLAY)
Or does it only apply to DLC and Expansion "content" ?

It would certainly be less bloaty than using a method like this where I printed out the titles and ID's of all active mods:
Code:
local activatedMods = Modding.GetActivatedMods();
for i,v in ipairs(activatedMods) do
	local title = Modding.GetModProperty(v.ID, v.Version, "Name");
	title = Locale.TruncateString(title, 30, true);
	local sModID = v.ID
	print(title .. " is " .. sModID)
end
In 'real' code I would only want the local sModID = v.ID bit to compare against a known mod ID, but it still seems like a bloaty way to go about it.

PS: I tried searching the forum and kept getting 'terms too short' or 'terms too common' errors. My google-foo is sadly lacking, I guess.
 
JFD uses this type of system:

Spoiler :
Code:
-- JFD_IsUsingMercenaries
function JFD_IsUsingMercenaries()
	local pietyModID = "a19351c5-c0b3-4b07-8695-4affaa199949"
	for _, mod in pairs(Modding.GetActivatedMods()) do
		if (mod.ID == pietyModID) then
			return true
		end
	end
end
local isUsingMercenaries = JFD_IsUsingMercenaries()

-- JFD_IsUsingPiety
function JFD_IsUsingPiety()
	local pietyModID = "eea66053-7579-481a-bb8d-2f3959b59974"
	for _, mod in pairs(Modding.GetActivatedMods()) do
		if (mod.ID == pietyModID) then
			return true
		end
	end
end

-- JFD_IsUsingSovereignty
function JFD_IsUsingSovereignty()
	local sovereigntyModID = "d99bf7aa-51ac-4bef-bd88-d765b28e260e"
	for _, mod in pairs(Modding.GetActivatedMods()) do
		 if (mod.ID == sovereigntyModID) then
			return true
		end
	end
end

Not sure if that gets you what you need. Note: I spend way too much time reading code, I think.
 
JFD uses this type of system:

Spoiler :
Code:
-- JFD_IsUsingMercenaries
function JFD_IsUsingMercenaries()
	local pietyModID = "a19351c5-c0b3-4b07-8695-4affaa199949"
	for _, mod in pairs(Modding.GetActivatedMods()) do
		if (mod.ID == pietyModID) then
			return true
		end
	end
end
local isUsingMercenaries = JFD_IsUsingMercenaries()

-- JFD_IsUsingPiety
function JFD_IsUsingPiety()
	local pietyModID = "eea66053-7579-481a-bb8d-2f3959b59974"
	for _, mod in pairs(Modding.GetActivatedMods()) do
		if (mod.ID == pietyModID) then
			return true
		end
	end
end

-- JFD_IsUsingSovereignty
function JFD_IsUsingSovereignty()
	local sovereigntyModID = "d99bf7aa-51ac-4bef-bd88-d765b28e260e"
	for _, mod in pairs(Modding.GetActivatedMods()) do
		 if (mod.ID == sovereigntyModID) then
			return true
		end
	end
end

Not sure if that gets you what you need. Note: I spend way too much time reading code, I think.
Yeah, that's basically the second method except without my print statements and with a specification for the desired mod to look for, plus some more efficient code-statements. I was hoping I could use the other method and be done with it all in one line.
 
IIRC ContentManager.IsActive() only checks the DLC

I use something very similar to JFD to check for IGE being enabled

Edit: Pretty sure this has been discussed on these forums before - between me and Don Quiche - but my Google-Fu has failed!
 
I ended making a small modification to the code as used by JFD:
Code:
function ModEnabledCheck(sModID)
	for i,v in pairs(Modding.GetActivatedMods()) do
		if sModID == v.ID then
			return true
		end
	end
	return false
end
local bEnlightenmentEraIsActive = ModEnabledCheck("ce8aa614-7ef7-4a45-a179-5329869e8d6d")
 
If you have more than one active mod to check for, the following will be more efficient, as GetActivatedMods() requires a database search

Code:
local bEnlightenmentEraIsActive = false
local bDllVmcIsActive = false
-- add more "booleans" here

for _,v in ipairs(Modding.GetActivatedMods()) do
	if (v.ID == "ce8aa614-7ef7-4a45-a179-5329869e8d6d") then
		bEnlightenmentEraIsActive = true
	elseif (v.ID == "d1b6328c-ff44-4b0d-aad7-c657f83610cd") then
		bDllVmcIsActive = true
	-- add more "elseifs" here
	end
end
 
Back
Top Bottom