Mod Creation/Getting Started: Difference between revisions

Use SyntaxHighlight
(User:Coolrox95 Add mod guide navigation)
(Use SyntaxHighlight)
Line 19: Line 19:
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.
Line 35: Line 35:
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 51: Line 51:
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 64: 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.
Line 92: Line 92:
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}}
{{ModGuideNav}}
{{Menu}}