In-game Functions: Difference between revisions

From Melvor Idle
(→‎Add XP: Added abyssal xp)
(Adding dungeon completions)
Line 300: Line 300:
</syntaxhighlight>
</syntaxhighlight>
The above code will reset all the quick equip items for '''all''' equipment sets.
The above code will reset all the quick equip items for '''all''' equipment sets.
== Dungeon Completions ==
The <code>addDungeonCompletion</code> and <code>setDungeonCompleteCount</code> functions are used to modify a dungeon's completion count.
<syntaxhighlight lang="js">
game.combat.player.manager.addDungeonCompletion(dungeon);
game.combat.player.manager.setDungeonCompleteCount(dungeon, amount);
</syntaxhighlight>
=== Attributes ===
{| class="wikitable"
|-
! Attribute !! Type !! Optional? !! Default Value !! Description
|-
| dungeon || object || No || || The dungeon you wish to add a completion to. Obtained with <syntaxhighlight lang="js" inline>game.dungeons.getObjectByID(dungeonID);</syntaxhighlight> where <code>dungeonID</code> is the ID of the dungeon.
A list of dungeon IDs can be obtained by entering the following into the console: <syntaxhighlight lang="js" inline>console.log(game.dungeons.allObjects.map((a) => a.id + ' - ' + a.name).join('\n'))</syntaxhighlight>.
|-
| amount || number || No || || The amount of dungeons clears you wish to add when using <code>setDungeonCompleteCount</code>. An amount is only required for setDungeonCompleteCount.
|}
=== Examples ===
<syntaxhighlight lang="js">
game.combat.player.manager.addDungeonCompletion(game.dungeons.getObjectByID('melvorF:Into_the_Mist'));
game.combat.player.manager.setDungeonCompleteCount(game.dungeons.getObjectByID('melvorF:Into_the_Mist'), 69420);
</syntaxhighlight>
The first line will add a single completion to {{ZoneIcon|Into the Mist}} while the second line will set the dungeon completions to 69420. Setting a dungeon completion count of 0 or lower will delete all completions from the dungeon.
After modifying the dungeon completion count, run <code>game.queueRequirementRenders();</code> to apply UI updates without having to restart the game.
{{Menu}}
{{Menu}}

Revision as of 15:37, 13 June 2024

This page was last updated for (v1.1.2).

In-game functions are responsible for most things in the game. It is possible to interact directly with them through the console. This can be used to add items, levels, GP and more. These functions can be executed though the console. To access the console open Developer Tools (usually by pressing F12) in your browser and navigate to the console. Then, simply paste the code in the input field and press enter. Most functions will require you to fill out variables in the code before executing them. Note that all code is case sensitive.

Disclaimer: Blindly adding items and experience will most likely take away game enjoyment. It is highly encouraged only to use this to either test things or recoup lost items/progress due to lost saves.

You are playing around with the code of the game, as such if you make mistakes it is possible that could corrupt your game. It is highly recommended to BACKUP YOUR SAVE before running any in-game functions.

Using In-game Functions

Players can use the dev.Console mod to execute these commands within the Steam, Epic, Android, and iOS versions of Melvor Idle.

On Web, Steam, and Epic, the console can be opened with F12. If using Steam or Epic, you must enable the dev console first before you are able to open it.

Add Item to Bank

The addItemByID function can be used to add any item in the game to the bank.

game.bank.addItemByID(itemID, quantity, logLost, found, ignoreSpace)

Attributes

Attribute Type Optional? Default Value Description
itemID string No The ID of the item.
For a complete list of items and their IDs, see: Table of Items
quantity int No Quantity of item to add.
logLost boolean Yes false If true, items that did not fit into the bank will be logged as lost
found boolean Yes false Determines if items added by this function will be included within the "Times Found" statistic for that item within the completion log. Therefore, unless this parameter is set to true, any items added in this way will not contribute towards the player's item completion percentage.

Note: When adding Bank Slot Tokens, it is suggested that this parameter is set to true, otherwise this may cause issues with the way the game calculates the amount of bank space a player has.
ignoreSpace boolean Yes false If true, the item will be added to the bank even if the bank is already full

Examples

game.bank.addItemByID("melvorD:Oak_Logs", 10, true, true, false);

The above code will result in attempting to add 10 Oak Logs to the Bank. If they do not fit, 10 will be added to the # of Oak Logs lost on the item's stats. Additionally, Oak Logs will be marked as discovered in the Completion Log.

Remove Item from Bank

The removeItemQuantityByID function can be used to remove any item from the bank

game.bank.removeItemQuantityByID(itemID, quantity, removeItemCharges)

Note that if an item's quantity is in an invalid state, such as NaN or Infinity, then this function will not be able to remove that item from the bank. For any such items, use the below snippet instead:

Code
First, enter the below into the console:
function removeItemByID(itemID) {
	const item = game.items.getObjectByID(itemID);
	if (item === undefined)
	throw new Error(
	`Error removing item from bank by id. Item with id: ${ itemID } is not registered.`
	);
	const bankItem = game.bank.items.get(item);
	if (bankItem === undefined)
	throw new Error(
	`Tried to remove quantity from bank, but item is not in bank.`
	);
	bankItem.quantity = 1;
	game.bank.removeItemQuantity(item, 1, true);
}

After this, invoke the newly-created function with the appropriate item ID to remove items from the bank. For example: removeItemByID('melvorD:Oak_Logs');

Attributes

Attribute Type Optional? Default Value Description
itemID string No The ID of the item.
For a complete list of items and their IDs, see: Table of Items
quantity int No The number of items to remove.
removeItemCharges boolean Yes true If true, the count of glove charges will be set to 0 if the itemID is for a pair of gloves with charges.

Examples

game.bank.removeItemQuantityByID('melvorD:Oak_Logs', 10);

The above code will result in 10 Oak Logs being removed from the bank.

Adjust Currencies (GP, Slayer Coins, and Raid Coins)

All Currency within the game, being GP GP, SC Slayer Coins (SC), and RC Raid Coins (RC) can be adjusted using the same set of functions:

  • To adjust GP, use game.gp
  • To adjust SC, use game.slayerCoins
  • To adjust RC, use game.raidCoins

Add Currency

The game.currency.add function can be used to add to the player's current balance of that currency.

game.<currency>.add(amount)

Attributes

Attribute Type Optional? Default Value Description
amount int No The amount to increase the specified currency's balance by

Examples

game.gp.add(1);

The above code will add 1 GP to the player.

Remove Currency

The game.currency.remove function can be used to subtract from the player's current balance of that currency. If the amount specified is greater than the amount the player currently has, then the currency's balance will become negative.

game.<currency>.remove(amount)

Attributes

Attribute Type Optional? Default Value Description
amount int No The quantity to decrease the specified currency's balance by

Examples

game.raidCoins.remove(1);

The above code will remove 1 Raid Coin from the player.

Set Currency

The game.currency.set function can be used to set the player's balance of that currency to the specified amount. This function may be of particular use to players who have inadvertently found their GP or SC balance is set to an invalid value such as NaN.

game.<currency>.set(amount)

Attributes

Attribute Type Optional? Default Value Description
amount int No The amount to set the specified currency's balance to

Examples

game.slayerCoins.set(999);

The above code will set the player's Raid Coin balance to 999, regardless of what the previous balance of raid coins owned was.

Add Prayer Points

The combat.player.addPrayerPoints function can be used to add prayer points to a player.

game.combat.player.addPrayerPoints(amount)

Attributes

Attribute Type Optional? Default Value Description
amount int No The quantity of prayer points to add.

Examples

game.combat.player.addPrayerPoints(1);

The above code will add 1 prayer point to the player, and update player stats.

Add XP

The addXP and addAbyssalXP functions can be used to add experience and abyssal experience to any skill.

game.<skill>.addXP(xp);
game.<skill>.addAbyssalXP(xp);

where <skill> is the lowercase name of the skill you are adding experience to.

Attributes

Attribute Type Optional? Default Value Description
xp int No Amount of experience to add.

Examples

game.thieving.addXP(1000);
game.thieving.addAbyssalXP(1000);

The above lines will result in 1000 experience and abyssal experience being added to

Error creating thumbnail: File missing
Thieving

.

Add Mastery XP

The addMasteryXP function can be used to add experience to any specific

Error creating thumbnail: File missing
Mastery

in a skill.

game.skill.addMasteryXP(masteryAction, xp)

where skill is the lowercase name of the skill you are adding mastery experience to.

Attributes

Attribute Type Optional? Default Value Description
masteryAction object No The action to add Mastery XP to. Obtained with game.skill.actions.getObjectByID(id) where skill is to be replaced with the name of the skill (all lowercase), and id is the ID of the action.

A list of action IDs can be obtained by entering the following into the console: console.log(game.skill.actions.allObjects.map((a) => a.id + ' - ' + a.name).join('\n')).

xp int Yes 0 Amount of experience to add.

Examples

game.farming.addMasteryXP(game.farming.actions.getObjectByID('melvorD:Carrot'), 300);

The above code will result in 300

Error creating thumbnail: File missing
Mastery

XP being added to

Error creating thumbnail: File missing
Farming

for Carrot Seeds.

game.firemaking.addMasteryXP(game.firemaking.actions.getObjectByID('melvorD:Teak_Logs'), 3000);

The above code will result in 3,000

Error creating thumbnail: File missing
Mastery

XP being added to

Error creating thumbnail: File missing
Firemaking

for Teak Logs.

Add Mastery XP to Pool

The addMasteryPoolXP function can be used to add Mastery Pool experience to a skill

game.<skill>.addMasteryPoolXP(realm, xp)

where <skill> is the lowercase name of the skill you are adding mastery experience to.

Attributes

Attribute Type Optional? Default Value Description
realm object No The realm to add the Mastery Pool XP to. Obtained with game.realms.getObjectByID(id) where the id is the ID of the realm.

A list of action IDs can be obtained by entering the following into the console: console.log(game.realms.allObjects.map((a) => a.id + ' - ' + a.name).join('\n')).

xp int Yes 0 Amount of experience to add.

Examples

game.woodcutting.addMasteryPoolXP(game.realms.getObjectByID('melvorD:Melvor'), 600);

The above code will result in 600 Mastery Pool XP being added to

Error creating thumbnail: File missing
Woodcutting

in the Melvor Realm.

Unlock Pet

The petManager.unlockPetByID function is used to unlock Pets. Note that unlocking a pet is permanent - there is no supported method to lock a pet once again.

game.petManager.unlockPetByID(petID)

Attributes

Attribute Type Optional? Default Value Description
petID string No The ID of the pet, which can be found on the individual pet pages (such as
Error creating thumbnail: File missing
Ty
for example) or by using the following command: console.log(game.pets.allObjects.map((a) => a.id + ' - ' + a.name).join('\n'))

Examples

game.petManager.unlockPetByID('melvorD:CoolRock');

The above code will result in the unlocking of

Error creating thumbnail: File missing
Cool Rock

.

Discover Mark

The discoverMark function is used to discover Summoning Marks. Once discovered, there is no supported method to allow a mark to become undiscovered again.

game.summoning.discoverMark(mark)

Attributes

Attribute Type Optional? Default Value Description
mark object No The mark to discover. Obtained with game.summoning.actions.getObjectByID(markID) where markID is the ID of the mark.

A list of mark IDs can be obtained by entering the following into the console: console.log(game.summoning.actions.allObjects.map((a) => a.id + ' - ' + a.name).join('\n')).

Examples

game.summoning.discoverMark(game.summoning.actions.getObjectByID('melvorF:Dragon'));

The above code discovers a single mark for the

Error creating thumbnail: File missing
Dragon

familiar.

Locate Ancient Relic

The locateAncientRelic function is used to locate Ancient Relics.

game.<skill>.locateAncientRelic(relicSet, relic)

where <skill> is the lowercase name of the skill you wish to add a relic to.

Attributes

Attribute Type Optional? Default Value Description
relicSet object No The relicSet that the relic belongs to. Obtained with game.<skill>.ancientRelicSets.get(realm)

A list of realms IDs can be obtained by entering the following into the console: console.log(game.realms.allObjects.map((a) => a.id + ' - ' + a.name).join('\n')). To convert the realmID into a realm object, use game.realms.getObjectByID('realmID').

relic object No The relic that you wish to add.

The relic can be obtained with <relicSet>.relicDrops.find(x => x.relic.id.toLowerCase().includes('relic<#>')); where <#> is replaced with the relic number, starting from 1 and ending with 5.

Examples

let realm = game.realms.getObjectByID('melvorD:Melvor');
let relicSet = game.woodcutting.ancientRelicSets.get(realm);
let relicDrop = relicSet.relicDrops.find(x => x.relic.id.toLowerCase().includes('relic1'));
if (!relicSet.foundRelics.has(relicDrop.relic))
     game.woodcutting.locateAncientRelic(relicSet, relic);

The above code locates Woodcutting Relic 1 in the Melvor Realm.

game.skills.forEach(skill => {
	let realm = game.realms.getObjectByID('melvorD:Melvor');
	let relicSet = skill.ancientRelicSets.get(realm);
	if (skill.hasAncientRelics)
		relicSet.relicDrops.forEach(({ relic }) => {
			if (!relicSet.foundRelics.has(relic))
				skill.locateAncientRelic(relicSet, relic)
		});
});

The above will add all ancient relics to every skill, including modded skills.

Reset all Equipment Quick Equip Items

The below script will reset the Equipment Quick Equip items back to an empty item. These are the Quick Equip items that are found when clicking on an equipment slot, not the ones found in the skilling minibar (that are set through the bank).

Examples

game.combat.player.equipment.equippedArray.forEach(equipped => {
	equipped.quickEquipItems = [game.emptyEquipmentItem, game.emptyEquipmentItem, game.emptyEquipmentItem];
	equipped.trimQuickEquipItems();
});

The above code will reset all the quick equip items for the current equipment set.

game.combat.player.equipmentSets.forEach(({ equipment }) => {
	equipment.equippedArray.forEach(equipped => {
		equipped.quickEquipItems = [game.emptyEquipmentItem, game.emptyEquipmentItem, game.emptyEquipmentItem];
		equipped.trimQuickEquipItems();
	});
});

The above code will reset all the quick equip items for all equipment sets.

Dungeon Completions

The addDungeonCompletion and setDungeonCompleteCount functions are used to modify a dungeon's completion count.

game.combat.player.manager.addDungeonCompletion(dungeon);
game.combat.player.manager.setDungeonCompleteCount(dungeon, amount);

Attributes

Attribute Type Optional? Default Value Description
dungeon object No The dungeon you wish to add a completion to. Obtained with game.dungeons.getObjectByID(dungeonID); where dungeonID is the ID of the dungeon.

A list of dungeon IDs can be obtained by entering the following into the console: console.log(game.dungeons.allObjects.map((a) => a.id + ' - ' + a.name).join('\n')).

amount number No The amount of dungeons clears you wish to add when using setDungeonCompleteCount. An amount is only required for setDungeonCompleteCount.

Examples

 game.combat.player.manager.addDungeonCompletion(game.dungeons.getObjectByID('melvorF:Into_the_Mist'));
 game.combat.player.manager.setDungeonCompleteCount(game.dungeons.getObjectByID('melvorF:Into_the_Mist'), 69420);

The first line will add a single completion to

Error creating thumbnail: File missing
Into the Mist

while the second line will set the dungeon completions to 69420. Setting a dungeon completion count of 0 or lower will delete all completions from the dungeon.

After modifying the dungeon completion count, run game.queueRequirementRenders(); to apply UI updates without having to restart the game.