Skip to content

Using items from other mods

PrimeSonic edited this page Dec 8, 2020 · 2 revisions

One of the advantages of having SMLHelper manage the addition of new items and keep track of them between game loads is that now you have a way of addressing items added by mod without having to directly reference that mod's dll.
Remember, as a courtesy, check with the mod's author and make sure they're cool with you incorporating part of their work into your mod.


First: Check if the other mod is present

See QModManager's QMod Services to check if the other mod is installed.


Next: Checking for (and using) Cross-Mod TechTypes

To be able to look for a cross-mod TechType, you'll need the internal name it was registered with.
There's a couple of ways you can get this:

  1. Ask the mod's author
  2. Check the mod's source code and look at what they used in the TechTypeHandler.AddTechType call.
  3. Open the TechTypeCache.txt file and look for it. Obviously you'll need to have this mod installed yourself.

Once you have the cross-mod TechType's internal name, you'll find two methods in TechTypeHandler to look for them.


ModdedTechTypeExists

This is a method you can if you just want to check if the player has that mod installed in the first place.

public static bool ModdedTechTypeExists([string] techtypeString);

If you don't need to actually use the item for anything but just want to enable other features when you know the player has this mod installed, this is the way to go.
You can call it like this:

bool otherModIsInstalled = TechTypeHandler.ModdedTechTypeExists("WarpCannon");

TryGetModdedTechType

This next method is the one to call if you actually intend on using the the cross-mod TechType for anything.

public static bool TryGetModdedTechType([string] techtypeString, out [TechType] modTechType);

You'll use TechTypeHandler.TryGetModdedTechType like any other TryGet/TryParse method in C#.
If it returns true, you're good to use the item. And if it's false, the player didn't have the mod you were looking for installed.
You can call it like this:

bool otherModIsInstalled = TechTypeHandler.TryGetModdedTechType("WarpCannon", out TechType warpCannonTechType);

Once you have an actual TechType enum instance for this cross-mod item, you can do anything with it that you would do with any other TechType.
Things you might do with another cross-mod TechType:

  • Include extra crafting recipes that use this item
  • Lock an extra blueprint behind this item
  • Add this item as compatible with your mod's new feature
  • Get creative cause it all depends on what you want to do

For more details on these methods, check the documentation in Visual Studio.

As a final remark, be aware that there is no guarantee in which order SMLHelper dependent mods are loaded.
So if two mods were installed at the same time, it may take a second game load for both mods to be visible to each other using the methods showcased here.

Please note that some pages are under construction and the links to them will be enabled as they are completed

Home
Quick Start Guide

[Adding]

[Editing]

[General Utilities]

[Language]

Clone this wiki locally