Jump to content

[ANSWERED] How do you detect if NeverRot is an activated mod (in Lua)?


jiggawutt

Recommended Posts

I was wondering if anyone knows how to check if a workshop mod has been enabled in the game or not?  The issue is that my mod overwrites another mod called NeverRot. Now, NeverRot is just a three line conditional statement shoved into the SFarmingSystem:growPlant() function.  Unfortunately, I can't just delete my version of this function as it's necessary for the new plants that my mod adds to the game.  So, my thought is just to add another condition to see if NeverRot is enabled in-game.  A clunkier version to this would be to check if the files from NeverRot exist, but I want people to have the choice to have NeverRot enabled or not.

 

Does anyone have an elegant solution to this problem, or am I just going to have to rely on checking for NeverRot files in the workshop folder?

Edited by jiggawutt
Link to comment
Share on other sites

If anyone encounters the same issue I had, this is the exact modified code snippet I've put into my mod. This should be inserted within the if(luaObject.state == "seeded") branch inside the function SFarmingSystem:growPlant(luaObject, nextGrowing, updateNbOfGrow).

 

The code this file overrides is from media/lua/server/Farming/SFarmingSystem.lua

 


        local actmods = getActivatedMods();
        local activeNR = false;
        for i=0, actmods:size()-1, 1 do
            if actmods:get(i) == "FarmingNeverRot" then
                activeNR = true;
                break;
            end
        end
        if (activeNR) then
            --NeverRot is this if statement.
            if (luaObject.nbOfGrow >6) then
                luaObject.nbOfGrow = 6
            end
        end


Edited by jiggawutt
Link to comment
Share on other sites

On 5/29/2019 at 4:30 PM, Fenris_Wolf said:

 

Those functions are pretty redundant.

 


getActivatedMods():contains("MyModName")

Just use the contains() method instead of looping though the array.

 

Yeah, it appears as if maybe the break statement is causing the code to escape all the way out of every branch in the function, which broke farming. Putting this line as the condition for an if statement does the trick way better (and doesn't break farming).

 

if (getActivatedMods():contains("FarmingNeverRot")) then
  --NeverRot is this if statement.
  if (luaObject.nbOfGrow >6) then
    luaObject.nbOfGrow = 6
  end
end
Edited by jiggawutt
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...