1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Checking if mods are activated with LUA?

Discussion in 'Civ5 - SDK / LUA' started by Enginseer, Aug 27, 2015.

  1. Enginseer

    Enginseer Salientia of the Community Patch Supporter

    Joined:
    Nov 7, 2012
    Messages:
    3,226
    Gender:
    Male
    Location:
    Somewhere in California
    Code:
    GameEvents.CityCanConstruct.Add(function(iBuildingType) 
    	if (iBuildingType == GameInfo.Buildings["BUILDING_MONUMENT_UP_FOOD"].ID) then
    		if (isUsingBUS == true) then
    			print("Cannot build Monument of Food")
    			return false;
    		end
    	end
    	if (iBuildingType == GameInfo.Buildings["BUILDING_MONUMENT_UP_LABOR"].ID) then
    		if (isUsingBUS == true) then
    			print("Cannot build Monument of Labor")
    			return false;
    		end
    	end
    	if (iBuildingType == GameInfo.Buildings["BUILDING_MONUMENT_UP_FAITH"].ID) then
    		if (isUsingBUS == true) then
    			print("Cannot build Monument of Faith")
    			return false;
    		end
    	end
    	if (iBuildingType == GameInfo.Buildings["BUILDING_MONUMENT_UP_RESEARCH"].ID) then
    		if (isUsingBUS == true) then
    			print("Cannot build Monument of Research")
    			return false;
    		end
    	end
    	if (iBuildingType == GameInfo.Buildings["BUILDING_MONUMENT_UP_MIGHT"].ID) then
    		if (isUsingBUS == true) then
    			print("Cannot build Monument of Might")
    			return false;
    		end
    	end
    	return true;
    end);
    
    --########################################################################
    -- Detect active mods
    -- Compatability addition by Xaragas from civfanatics
    function HavingMods()
    	for _, mod in pairs(Modding.GetActivatedMods()) do
    		--Assumes that if this mod ID is activated then this is true? I believe?
    		if (mod.ID == e3fed66f-f129-45a4-abce-a5496dc2f0c5) then
    			isUsingBUS = true
    		end
    	end
    end
    
    isUsingBUS = false
    HavingMods()
    Using the source code from the 1066 scenario and Xaragas's Compatibility coding.. I've developed a sort of file which enforces that this mod is required before any modded buildings can be built... any LUA experts know if I am doing this correctly or on the right track?
     
  2. Vicevirtuoso

    Vicevirtuoso The Modetta Man

    Joined:
    May 14, 2013
    Messages:
    775
    Location:
    The Wreckage, Brother
    It generally works, but one caveat is that it does not work properly in multiplayer. With the current methods, the game considers no mods to be active when you are running a multiplayer modpack.

    Are you trying to make a building in your mod which can't be built without the presence of another mod? What I'd do is test for the existence of something that mod adds, like a building or policy or whatever.
     
  3. Enginseer

    Enginseer Salientia of the Community Patch Supporter

    Joined:
    Nov 7, 2012
    Messages:
    3,226
    Gender:
    Male
    Location:
    Somewhere in California
    And how would you test the added modded building in LUA?
     
  4. Enginseer

    Enginseer Salientia of the Community Patch Supporter

    Joined:
    Nov 7, 2012
    Messages:
    3,226
    Gender:
    Male
    Location:
    Somewhere in California
    Could someone shed some light on this? The game never seems to respond to any of my functions...?
     
  5. DarkScythe

    DarkScythe Hunkalicious Holo

    Joined:
    May 6, 2014
    Messages:
    804
    ViceVirtuoso has already addressed the multiplayer issue, so I'll assume you mean it doesn't work in single player.

    Best thing to do is to throw some print() statements in there and see where Lua is failing during execution.

    Having said that, doublecheck your comparisons:

    Code:
    function HavingMods()
    	for _, mod in pairs(Modding.GetActivatedMods()) do
    		--Assumes that if this mod ID is activated then this is true? I believe?
    		if ([COLOR="Red"]mod.ID == e3fed66f-f129-45a4-abce-a5496dc2f0c5[/COLOR]) then
    			isUsingBUS = true
    		end
    	end
    end
    You likely need to encapsulate the target mod ID in quotes, because the mod ID returned is a string, and you're trying to compare it to...something Lua likely can't figure out, because you've not specified it as a string.

    Code:
    function HavingMods()
    	for _, mod in pairs(Modding.GetActivatedMods()) do
    		--Assumes that if this mod ID is activated then this is true? I believe?
    		if (mod.ID == [COLOR="Blue"][B]"e3fed66f-f129-45a4-abce-a5496dc2f0c5"[/B][/COLOR]) then
    			isUsingBUS = true
    		end
    	end
    end
     
  6. Enginseer

    Enginseer Salientia of the Community Patch Supporter

    Joined:
    Nov 7, 2012
    Messages:
    3,226
    Gender:
    Male
    Location:
    Somewhere in California
    Code:
    function CityCanConstructBUS(iPlayer, iCity, buildingType)
    	if (isUsingBUS == false) then
    		--print("Doesn't have BUS")
    		if ((buildingType ~= GameInfoTypes.BUILDING_MONUMENT_UP)) then
    			return true
    		else
    			return false
    		end
    	elseif (isUsingBUS == true) then
    		--print("Have BUS")
    		return true
    	end
    end
    
    --########################################################################
    -- Detect active mods
    -- Compatability addition by Xaragas from civfanatics
    function HavingMods()
    	for _, mod in pairs(Modding.GetActivatedMods()) do
    		--Assumes that if this mod ID is activated then this is true? I believe?
    		if (mod.ID == "e3fed66f-f129-45a4-abce-a5496dc2f0c5") then
    			isUsingBUS = true
    			--print("mod online")
    		end
    	end
    end
    
    isUsingBUS = false
    HavingMods()
    print(isUsingBUS)
    GameEvents.CityCanConstruct.Add(CityCanConstructBUS)
    Looking at previous past posts, I was able to replicate this to success. Thanks for the help!
     

Share This Page