Mod Creation/Getting Started: Difference between revisions

Use SyntaxHighlight
(Created page with "A mod in Melvor Idle, much like other games with mods, is a game modification created by the player community. The modification to the game can range from a minor balance change to introducing new skills and items, or a simple quality of life improvement to a full suite of automation tools. There are various programming APIs within Melvor Idle to help you create mods, regardless of how simple or complex it is. == Prerequisites == Mods for Melvor Idle are created using J...")
 
(Use SyntaxHighlight)
 
(2 intermediate revisions by 2 users not shown)
Line 2: Line 2:


== Prerequisites ==
== Prerequisites ==
Mods for Melvor Idle are created using JavaScript, and at least a beginner level understanding of the language, or programming languages in general, is recommended before jumping into the guides.
Mods for Melvor Idle are created using JavaScript, and at least a beginner level understanding of the language, or programming languages in general, is recommended before jumping into the guides.


Line 7: Line 8:


== Quick Start ==
== Quick Start ==
Want to dive right into creating your first mod with a (mostly) blank canvas? Follow along to get started.
Want to dive right into creating your first mod with a (mostly) blank canvas? Follow along to get started.


=== Project Setup ===
=== Project Setup ===
Start by creating a new empty folder for your mod. You'll want to create two files in this new folder:
Start by creating a new empty folder for your mod. You'll want to create two files in this new folder:
* <code>manifest.json</code>
* <code>manifest.json</code>
Line 15: Line 18:


The <code>manifest.json</code> file is used to define metadata for your mod, or important information for Melvor Idle to know how to load your mod. Put the following code within <code>manifest.json</code>:
The <code>manifest.json</code> file is used to define metadata for your mod, or important information for Melvor Idle to know how to load your mod. Put the following code within <code>manifest.json</code>:
  <nowiki>{
 
  <syntaxhighlight lang="js" line>{
   "setup": "setup.mjs"
   "setup": "setup.mjs"
}</nowiki>
}</syntaxhighlight>


This tells Melvor Idle to look for a <code>setup.mjs</code> file and run its exported <code>setup</code> function. Next we'll create that function within <code>setup.mjs</code>:
This tells Melvor Idle to look for a <code>setup.mjs</code> file and run its exported <code>setup</code> function. Next we'll create that function within <code>setup.mjs</code>:
  <nowiki>export function setup() {
 
  <syntaxhighlight lang="js" line>export function setup() {
   console.log('Hello From My Mod!');
   console.log('Hello From My Mod!');
}</nowiki>
}</syntaxhighlight>


The export word is important here as it will let the Mod Manager access the setup function to load the mod.
The export word is important here as it will let the Mod Manager access the setup function to load the mod.


=== Making it Do Something ===
=== Making it Do Something ===
You'd already have a working "mod" at this point but it's not really modifying anything yet. Let's let the <code>setup</code> function know we want to accept a context object (<code>ctx</code> for short) when <code>setup</code> is executed, and then patch the <code>Skill</code> class to double all XP gains.
You'd already have a working "mod" at this point but it's not really modifying anything yet. Let's let the <code>setup</code> function know we want to accept a context object (<code>ctx</code> for short) when <code>setup</code> is executed, and then patch the <code>Skill</code> class to double all XP gains.
  <nowiki>export function setup(ctx) {
 
  <syntaxhighlight lang="js" line>export function setup(ctx) {
   ctx.patch(Skill, 'addXP').before(function(amount, masteryAction) {
   ctx.patch(Skill, 'addXP').before(function(amount, masteryAction) {
     return [amount * 2, masteryAction];
     return [amount * 2, masteryAction];
   });
   });
}</nowiki>
}</syntaxhighlight>


The context object will  be the bread-and-butter for your mod performing game modifications. Find more information on the patch method and details on everything else possible with the context object in the Essentials guide.
The context object will  be the bread-and-butter for your mod performing game modifications. Find more information on the patch method and details on everything else possible with the context object in the Essentials guide.
Line 39: Line 46:


=== Using Player Input ===
=== Using Player Input ===
Doubling XP is okay, but the mod would be even more useful if the player could customize the amount that the XP was being multiplied by. Luckily, that's easy with another part of the context object: mod settings.
Doubling XP is okay, but the mod would be even more useful if the player could customize the amount that the XP was being multiplied by. Luckily, that's easy with another part of the context object: mod settings.


You can define a setting for the player to change using the settings object within the context object, and modify the patch code from above to use this value instead of a value of 2:
You can define a setting for the player to change using the settings object within the context object, and modify the patch code from above to use this value instead of a value of 2:
  <nowiki>export function setup(ctx) {
 
  <syntaxhighlight lang="js" line>export function setup(ctx) {
   ctx.settings.section('General').add({
   ctx.settings.section('General').add({
     type: 'number',
     type: 'number',
Line 55: Line 64:
     return [amount * xpMultiplier, masteryAction];
     return [amount * xpMultiplier, masteryAction];
   });
   });
}</nowiki>
}</syntaxhighlight>


The player will then be able to open up your mod's settings from the sidebar and change the multiplier to any number they'd like.
The player will then be able to open up your mod's settings from the sidebar and change the multiplier to any number they'd like.


=== Packaging and Adding Your Mod ===
=== Packaging and Adding Your Mod ===
Once you're ready to test your mod or make it available in the Mod Manager, you'll want to package it and upload it to mod.io.
Once you're ready to test your mod or make it available in the Mod Manager, you'll want to package it and upload it to mod.io.


Line 71: Line 81:


=== Using Your Mod ===
=== Using Your Mod ===
You'll now be able to subscribe, download, install, and use your mod. If you've made the mod public try searching for it in the in-game Mod Manager and subscribing to it there. Once installed, you'll need to restart the game for the mod to take effect.
You'll now be able to subscribe, download, install, and use your mod. If you've made the mod public try searching for it in the in-game Mod Manager and subscribing to it there. Once installed, you'll need to restart the game for the mod to take effect.


Line 78: Line 89:


== Next Steps ==
== Next Steps ==
From here the [[Mod Creation/Essentials]] guide is strongly recommended to learn about the different modding concepts and APIs available to you.
From here the [[Mod Creation/Essentials]] guide is strongly recommended to learn about the different modding concepts and APIs available to you.
{{ModGuideNav}}
{{Menu}}