Custom Licences allow you to lock features of your mod behind natural game progression with a custom licence specific to your mod.
It's highly recommended to create your licence and change any of it's settings in your plugin's Awake function. If you do not do so, your licence may not show up in-game.
To add your licence to the game, you'll need to call the TRLicences.AddLicence function. You should assign what it returns to a variable in order to make other changes and check it's level at any given time.
private TRCustomLicence yourCustomLicence;
private void Awake() {
plugin = TRTools.Initialize(this, yourNexusID, yourChatTrigger);
yourCustomLicence = plugin.AddLicence(licenceID, licenceName, maxLevel);
}
There are a few parameters to this function:
int licenceID | Used to save/load this specific licence. To ensure there are no save data mixups, it must be unique to this licence in particular within your mod. I recommend starting with 1 and counting up with each licence added. |
string licenceName | The name for the licence shown in-game on the purchase screen and in your player details. You can change this at any time without causing issues as it is only used for display purposes. |
int maxLevel | How many levels of this licence there are available to purchase. This parameter can be omitted and will default to 1. It has a maximum of 5 due to that being the max number of dots that can appear on a licence. |
Note as well that you MUST set a Nexus ID when initializing. See the Nexus ID page for more information.
After adding your custom licence, you'll want to tell the game how many permit points it costs to buy each level and what description should be shown for each level. To do this, use yourCustomLicence.SetLevelInfo(level, description, cost)
for each level. Example below.
private void Awake() {
yourCustomLicence = TRLicences.AddLicence(uniqueModID, "1", "My First Licence", 3);
yourCustomLicence.SetLevelInfo(1, "The description for the first level.", 250);
yourCustomLicence.SetLevelInfo(2, "The description for the second level.", 1000);
yourCustomLicence.SetLevelInfo(3, "The description for the third level.", 3000);
}
You can change the icon used for it with yourCustomLicence.ChangeIcon(icon)
The default icon used for custom licences can be found at “plugins/TR Tools/default_licence.png”. To use a custom icon, you would create your own image (or copy and edit the default) in your preferred image editor and load it as a Sprite using the TRAssets class. For more info on importing a custom sprite, see the Custom Assets page.
You can change the color of the banner for your licence using yourCustomLicence.SetColor(color)
The default color used is the color of the main color in the default licence icon, rgb(195, 135, 112). Note that if you change the color of your licence, it will not change the color used in its icon. In order to do that, you would need to create a custom licence icon with the color changes made manually.
If you do not want your licence to be visible or purchaseable until the player has unlocked a different licence, you can use yourCustomLicence.AddPrerequisite(requiredLicence, minimumLevel)
The requiredLicence can be any vanilla licence or a custom licence that you created. The minimum level is the minimum level that the requiredLicence must be in order for this licence to be available.
You can lock levels of your licence behind skill requirements as well by calling yourCustomLicence.AddSkillRequirement(licenceLevel, skill, skillLevelRequirement)
The ‘licenceLevel’ is the level you want this requirement to be added to. Generally, if you're adding requirements then you'll want to add a skill requirement to every level. For that, you'll have to call this multiple times with a different licenceLevel each time.
The ‘skillLevelRequirement’ is the level that you have to reach in the ‘skill’ for this level of the licence to be unlockable. Note that you can call this as many times as you want for a single licenceLevel to add multiple skill requirements.
For example, if you wanted the first level of your licence to require level 10 Farming, and the second level of your licence to require both level 20 Farming and level 10 Hunting, then you'd do:
yourCustomLicence = plugin.AddLicence(licenceID, licenceName, maxLevel);
yourCustomLicence.AddSkillRequirement(1, CharLevelManager.SkillTypes.Farming, 10);
yourCustomLicence.AddSkillRequirement(2, CharLevelManager.SkillTypes.Farming, 20);
yourCustomLicence.AddSkillRequirement(2, CharLevelManager.SkillTypes.Hunting, 10);
Once your licence is fully configured, you can check the player's progress by checking yourCustomLicence.level
at any time. It's value will be 0 if the licence hasn't been unlocked yet. It will be 1 if the player has unlocked the first level, 2 if they've unlocked the second level, and so on.
Modders and users both can use chat commands built into TR Tools to immediately unlock the max level of any custom licence. To do this, see the Chat Commands (Users) page for more information.