Jump to content
Sign in to follow this  
jiggawutt

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

Recommended Posts

Posted (edited)

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

Share this post


Link to post
Share on other sites
Posted (edited)

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

Share this post


Link to post
Share on other sites
Posted (edited)
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...