Background: I am working on one of my mods and I replace /items/builderconfig/buildweapon.lua, which is very important to a lot of other mods. I need a way to check if a mod is loaded so that I can add compatibility for those other mods. In this case I need to check if Frackin' Universe is loaded, since it adds critical hit stats to weapon tool tips. However, I can't just check if a weapon already has crit stats in its config, since some modded weapons might have critical stats already defined for Frackin' Universe. What I need is a way to test if a mod is loaded, or if a file is loaded (because then I could check for a unique file from that mod). I've already figured out one way of doing it, but it's very annoying and so I'm hoping for something better. Here's a list of things I've tried. io.open io is not included with Starbound, and for a pretty good reason. This means it's impossible to check if a file exists through it. root.imageSize I've tried using this to test for an image loaded, and have tried combining it with pcall. This doesn't work, because if the image doesn't exist, the game complains about it, puts it into the log, and then still returns a placeholder image. This means that I get errors in the log that I don't want, and it still doesn't work. root.assetJson I tried using pcall for this too. Surprisingly, it works, and I can return true if it's loaded, and false if it isn't. The problem with this is that it prints a massive error into the log too, and as far as I know there is no way to tell it to stop. This error makes checking for issues in the log more difficult, and I fear it could confuse people reporting glitches. This would be viable if there was a way to tell the game to not log in this case, since I don't want it to. So does anyone know of an actual solution to this? It seems like a very important thing to have missing.
Modinfo file uses includes and requires parameters. Requires = Mod is not loaded unless a certain mod is there Includes = If mod is loaded, then load your mod after that mod. You can also use the Test operation in patching. But is only valid if a file exists to patch. So it is better to make a mod using requires - if a particular file is involved.
I'm already using include to make sure of that, but I don't want to use require since my mod works fine without Frackin' Universe. It's just that if Frackin' Universe is loaded, then buildweapon.lua needs to do a little bit extra. Because of this, I was hoping there was some way to check if a mod was loaded, so that the following pseudocode would work. Code: if modIsLoaded("FrackinUniverse") then --could also use if fileExists("interace/fubutton.png") then --code to set critical labels end If nothing like this is possible, I can always use config file for users to enable or disable the tooltips, but that is less elegant and requires the mod user to put in more work.
I can't imagine there's no vanilla file that FU patches which adds something specific to FU. If there is, couldn't you root.assetJson such a file and check if the key has a value assigned in it? Without the mod cfg["someFUThing"] would simply be nill, which doesn't cause any issues.
That's possible too, but I'd prefer to just be fully compatible without needing any extra .paks. I'll probably do that if I can't get any other way working. That's a good idea, it seems like it would work well. Frackin' Universe has tons of JSON patches, so I'll just pick one that's unlikely to be removed in future updates (like items/categories.config.patch).
Test for changes in vanilla files that mod alters. Code: local playerConfig = root.assetJson("/player.config") for k, v in ipairs(playerConfig.statusControllerSettings.primaryScriptSources) do if v == "/scripts/fu_tilegroundeffects.lua" then return true end end return false There may be easier places to check, but that comes off the top of my head as something that would work for sure. Also is it viable to simply hook the script instead?
Code seems fine, though it is probably better to find a FU patch that adds a new key rather than one that adds a member to an array. This means you don't have to loop over a bunch of values that aren't important to you.
Yeah, that's what I did. Here's the code I used if anyone is wondering. Code: options = {} function options.isFrackinUniverseLoaded() if options.frackinUniverseIsLoaded == nil then local json = root.assetJson("/items/categories.config") options.frackinUniverseIsLoaded = json["fu_warspear"] ~= nil end return options.frackinUniverseIsLoaded end Of course, if Frackin' Universe ever removes warspears I'll have to find something else. Hopefully in a later version of Starbound they'll add something like root.isModLoaded("modid") as an easier way to do this.
I'm hoping what I did here(Ships aren't safe) catches on. The use of a "modEnvironment" object Code: [ [ { "op" : "add", "path" : "/statusControllerSettings/primaryScriptSources/-", "value" : "/scripts/bk3k/bk3k_shipDamage.lua" } ], [ { "op" : "test", "path" : "/modEnvironment", "inverse" : true }, { "op" : "add", "path" : "/modEnvironment", "value" : {} } ], [ { "op" : "test", "path" : "/modEnvironment/on_shipDamage", "inverse" : true }, { "op" : "add", "path" : "/modEnvironment/on_shipDamage", "value" : true } ] ] It is then possible to check for the presence of the mod while patching player.config, but also easily with this simple code Code: function playersVulnerable() temp = root.assetJson("/player.config") return temp.modEnvironment and temp.modEnvironment.on_shipDamage end