tModLoader

tModLoader

Simple Equipment Perks
 This topic has been pinned, so it's probably important
BlockCrusader  [developer] 24 Sep, 2023 @ 7:12am
Cross-Mod & Mod.Call Guide:
Do you want to add perks to content for your own mod? This guide will give the basic rundown on how to do so, utilizing Mod.Call functions in this mod that will let you easily check when perks are active. Do note this guides assumes you have some knowldege of modding with tML (You'll need to know what I mean/want when I say 'player.whoAmI', for example)

In general, this is how you can add 'perk' effects to something;
  1. Add in the desired perk effects (Preferably to a respective ModBuff if adding a perk to a pet, light pet, or minecart. However, the UpdateEquip hook will work for accessories, such as wings)
  2. Place the perk effects within an conditional/if statement such that they only apply when the conditional evaluates to true
  3. Utilize the appropriate Call function from this mod and plug the return bool into your conditional/if
  4. Profit!
There are also Call functions that allow you to add respective perk tooltips. The process is the same, but you'll probably need to utilize the GlobalItem class and ModifyTooltips hook to conditionally add the perk tooltips.

List of Calls:
  • PerksActivePets: Returns a boolean representing if a given player instance has perks for pets turned on. Takes player.whoAmI as an integer argument.
  • PerksActiveLightPets: Returns a boolean representing if a given player instance has perks for light pets turned on. Takes player.whoAmI as an integer argument.
  • PerksActiveMinecarts: Returns a boolean representing if a given player instance has perks for minecarts turned on. Takes player.whoAmI as an integer argument.
  • PerksActiveWings: Returns a boolean representing if a given player instance has perks for wings turned on. Takes player.whoAmI as an integer argument.
  • PerkTooltipsPets: Returns a boolean representing if perk tooltips for pets are turned on. No arguments.
  • PerkTooltipsLightPets: Returns a boolean representing if perk tooltips for light pets are turned on. No arguments.
  • PerkTooltipsMinecarts: Returns a boolean representing if perk tooltips for minecarts pets are turned on. No arguments.
  • PerkTooltipsWings: Returns a boolean representing if perk tooltips for wings are turned on. No arguments.

Example:
Here are annotated examples of adding a perk to a pet, and a respective tooltip. This comes from my mod Kirbo Pets;

Adding a perk to a pet:
/* Some other code in the Update hook for a GlobalBuff */ // First check to make sure Simple Equipment Perks is loaded/active if (ModLoader.TryGetMod("EquipPerks", out Mod equipPerks)) { // Make the mod.Call, and cast the return to a bool and check it if (equipPerks.Call("PerksActivePets", player.whoAmI) is bool perks && !perks) { // Don't apply perk effects if the return was false return; } } else { // Don't apply perk effects if Simple Equipment Perks couldn't be found return; } /* Here we start adding perks. These 6 pets all use the same perk. Note that we're checking for the respective buff */ if (type == ModContent.BuffType<KirboBuff>() || type == ModContent.BuffType<YellowKirboBuff>() || type == ModContent.BuffType<GreenKirboBuff>() || type == ModContent.BuffType<RedKirboBuff>() || type == ModContent.BuffType<BlueKirboBuff>() || type == ModContent.BuffType<MetaKirboBuff>()) { player.buffImmune[BuffID.Weak] = true; player.lifeRegen++; } /* More perks and some other code in the Update hook for a GlobalBuff */

Adding a perk tooltip:
/* Some other code in the ModifyTooltips hook for a GlobalItem */ /* Checks if tooltips for light pets are enabled. This follows the same logic as the above example */ if (ModLoader.TryGetMod("EquipPerks", out Mod equipPerks)) { if (equipPerks.Call("PerkTooltipsLightPets") is bool perks && !perks) { return; } } else { return; } // Now add tooltips to desired items. Make sure you know how to use ModifyTooltips! int type = item.type; if (type == ModContent.ItemType<CrossOrange>()) { tooltips.Insert(3, new(Mod, "Perk", Language.GetTextValue("Mods.KirboPets.CommonItemTooltip.LightKirbIPerk"))); } /* More perk tooltips and some other code in the ModifyTooltips hook for a GlobalItem */

For further help with using Mod.Call, please check out this guide on tModLoader's GitHub![github.com]
Last edited by BlockCrusader; 27 Sep, 2023 @ 6:38am