In-game Functions: Difference between revisions

m
Replace all getObjectByID with getObjectSafe to prevent entering invalid IDs
(Add shop purchases; Adjust dungeons code to prevent entering an invalid dungeon; Some minor page cleanup/adjustments)
m (Replace all getObjectByID with getObjectSafe to prevent entering invalid IDs)
 
Line 60: Line 60:
|text=First, enter the below into the console:
|text=First, enter the below into the console:
<syntaxhighlight lang="js">function removeItemByID(itemID) {
<syntaxhighlight lang="js">function removeItemByID(itemID) {
const item = game.items.getObjectByID(itemID);
const item = game.items.getObjectSafe(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);
const bankItem = game.bank.items.get(item);
if (bankItem === undefined)
if (bankItem === undefined)
Line 113: Line 109:
==== Examples ====
==== Examples ====
<syntaxhighlight lang="js">
<syntaxhighlight lang="js">
let purchase = game.shop.purchases.getObjectByID('melvorD:Extra_Bank_Slot');
// Settings //
let purchase = game.shop.purchases.getObjectSafe('melvorD:Extra_Bank_Slot');
let quantity = 100;
let quantity = 100;
if (purchase) {
// End of Settings //
game.shop.upgradesPurchased.set(purchase, (game.shop.upgradesPurchased.get(purchase) || 0) + quantity);
game.shop.upgradesPurchased.set(purchase, (game.shop.upgradesPurchased.get(purchase) || 0) + quantity);
game.shop.computeProvidedStats();
game.shop.computeProvidedStats();
shopMenu.tabs.get(purchase.category).menu.updateItemSelection();
shopMenu.tabs.get(purchase.category).menu.updateItemSelection();
game.shop.renderQueue.costs = true;
game.shop.renderQueue.costs = true;
} else {
console.error(`Purchase ID is invalid`);
}
</syntaxhighlight>
</syntaxhighlight>
The above will add 100 Bank Slot purchases then do the necessary render.
The above will add 100 Bank Slot purchases then do the necessary render.
Line 210: Line 204:
! Attribute !! Type !! Optional? !! Description
! Attribute !! Type !! Optional? !! Description
|-
|-
| masteryAction || object || No || The action to add Mastery XP to. Obtained with <syntaxhighlight lang="js" inline>game.<skill>.actions.getObjectByID(id);</syntaxhighlight>.
| masteryAction || object || No || The action to add Mastery XP to. Obtained with <syntaxhighlight lang="js" inline>game.<skill>.actions.getObjectSafe(id);</syntaxhighlight>.


A list of actions IDs can be generated with <syntaxhighlight lang="js" inline>console.log(game.<skill>.actions.allObjects.map((a) => a.id + ' - ' + a.name).join('\n'));</syntaxhighlight>
A list of actions IDs can be generated with <syntaxhighlight lang="js" inline>console.log(game.<skill>.actions.allObjects.map((a) => a.id + ' - ' + a.name).join('\n'));</syntaxhighlight>
Line 221: Line 215:
=== Examples ===
=== Examples ===
<syntaxhighlight lang="js">
<syntaxhighlight lang="js">
  game.farming.addMasteryXP(game.farming.actions.getObjectByID('melvorD:Carrot'), 300);
  game.farming.addMasteryXP(game.farming.actions.getObjectSafe('melvorD:Carrot'), 300);
  game.farming.addMasteryXP(game.farming.actions.getObjectByID('melvorTotH:Starfruit'), -500);
  game.farming.addMasteryXP(game.farming.actions.getObjectSafe('melvorTotH:Starfruit'), -500);
  </syntaxhighlight>
  </syntaxhighlight>
The first line will result in 300 {{Icon|Mastery}} XP being added to {{Skill|Farming}} for {{ItemIcon|Carrot Seeds}} whereas the second line will remove 500 Mastery XP from {{ItemIcon|Starfruit}}.
The first line will result in 300 {{Icon|Mastery}} XP being added to {{Skill|Farming}} for {{ItemIcon|Carrot Seeds}} whereas the second line will remove 500 Mastery XP from {{ItemIcon|Starfruit}}.
Line 238: Line 232:
! Attribute !! Type !! Optional? !! Description
! Attribute !! Type !! Optional? !! Description
|-
|-
| realm || object || No || The realm to add the Mastery Pool XP to. Obtained with <code>game.realms.getObjectByID(realmID)</code>.
| realm || object || No || The realm to add the Mastery Pool XP to. Obtained with <code>game.realms.getObjectSafe(realmID)</code>.


A list of realm IDs can be obtained by entering the following into the console: <code>console.log(game.realms.allObjects.map((a) => a.id + ' - ' + a.name).join('\n'))</code>.
A list of realm IDs can be obtained by entering the following into the console: <code>console.log(game.realms.allObjects.map((a) => a.id + ' - ' + a.name).join('\n'))</code>.
Line 246: Line 240:
=== Examples ===
=== Examples ===
<syntaxhighlight lang="js">
<syntaxhighlight lang="js">
  game.woodcutting.addMasteryPoolXP(game.realms.getObjectByID('melvorD:Melvor'), 600);
  game.woodcutting.addMasteryPoolXP(game.realms.getObjectSafe('melvorD:Melvor'), 600);
  game.woodcutting.addMasteryPoolXP(game.realms.getObjectByID('melvorItA:Abyssal'), -400);
  game.woodcutting.addMasteryPoolXP(game.realms.getObjectSafe('melvorItA:Abyssal'), -400);
  </syntaxhighlight>
  </syntaxhighlight>
The first line will result in 600 [[Mastery#The_Mastery_Pool|Mastery Pool]] XP being added to {{Skill|Woodcutting}} in the Melvor Realm whereas the second line will remove 400 mastery pool xp from Woodcutting in the abyssal realm.
The first line will result in 600 [[Mastery#The_Mastery_Pool|Mastery Pool]] XP being added to {{Skill|Woodcutting}} in the Melvor Realm whereas the second line will remove 400 mastery pool xp from Woodcutting in the abyssal realm.
Line 267: Line 261:
<syntaxhighlight lang="js">
<syntaxhighlight lang="js">
  game.petManager.unlockPetByID('melvorD:CoolRock');
  game.petManager.unlockPetByID('melvorD:CoolRock');
  game.petManager.unlocked.delete(game.pets.getObjectByID('melvorD:CoolRock'));game.petManager.computeProvidedStats();
  game.petManager.unlocked.delete(game.pets.getObjectSafe('melvorD:CoolRock'));game.petManager.computeProvidedStats();
  </syntaxhighlight>
  </syntaxhighlight>
The first line will result in the unlocking of {{PetIcon|Cool Rock}} while the second line will remove the Cool Rock then reload the player's stats.
The first line will result in the unlocking of {{PetIcon|Cool Rock}} while the second line will remove the Cool Rock then reload the player's stats.
Line 281: Line 275:
! Attribute !! Type !! Optional? !! Description
! Attribute !! Type !! Optional? !! Description
|-
|-
| mark || object || No || The mark to discover. Obtained with <syntaxhighlight lang="js" inline>game.summoning.actions.getObjectByID(markID)</syntaxhighlight> where <code>markID</code> is the ID of the mark.
| mark || object || No || The mark to discover. Obtained with <syntaxhighlight lang="js" inline>game.summoning.actions.getObjectSafe(markID)</syntaxhighlight> where <code>markID</code> is the ID of the mark.


A list of mark IDs can be obtained by entering the following into the console: <syntaxhighlight lang="js" inline>console.log(game.summoning.actions.allObjects.map((a) => a.id + ' - ' + a.name).join('\n'))</syntaxhighlight>.
A list of mark IDs can be obtained by entering the following into the console: <syntaxhighlight lang="js" inline>console.log(game.summoning.actions.allObjects.map((a) => a.id + ' - ' + a.name).join('\n'))</syntaxhighlight>.
Line 288: Line 282:
=== Examples ===
=== Examples ===
<syntaxhighlight lang="js">
<syntaxhighlight lang="js">
  game.summoning.discoverMark(game.summoning.actions.getObjectByID('melvorF:Dragon'));
  game.summoning.discoverMark(game.summoning.actions.getObjectSafe('melvorF:Dragon'));
  game.summoning.marksUnlocked.delete(game.summoning.actions.getObjectByID('melvorF:Dragon'));
  game.summoning.marksUnlocked.delete(game.summoning.actions.getObjectSafe('melvorF:Dragon'));
  </syntaxhighlight>
  </syntaxhighlight>
The first line discovers a single mark for the {{ItemIcon|Dragon}} familiar whereas the second line removes all marks from the Dragon.
The first line discovers a single mark for the {{ItemIcon|Dragon}} familiar whereas the second line removes all marks from the Dragon.
Line 313: Line 307:
| relicSet || object || No || The relicSet that the relic belongs to. Obtained with <syntaxhighlight lang="js" inline>game.<skill>.ancientRelicSets.get(realm)</syntaxhighlight>
| relicSet || object || No || The relicSet that the relic belongs to. Obtained with <syntaxhighlight lang="js" inline>game.<skill>.ancientRelicSets.get(realm)</syntaxhighlight>


A list of realms IDs can be obtained by entering the following into the console: <syntaxhighlight lang="js" inline>console.log(game.realms.allObjects.map((a) => a.id + ' - ' + a.name).join('\n'))</syntaxhighlight>. To convert the realmID into a realm object, use <syntaxhighlight lang="js" inline>game.realms.getObjectByID('realmID')</syntaxhighlight>.
A list of realms IDs can be obtained by entering the following into the console: <syntaxhighlight lang="js" inline>console.log(game.realms.allObjects.map((a) => a.id + ' - ' + a.name).join('\n'))</syntaxhighlight>. To convert the realmID into a realm object, use <syntaxhighlight lang="js" inline>game.realms.getObjectSafe(realmID)</syntaxhighlight>.
|-
|-
| relic || object || No || The relic that you wish to add.
| relic || object || No || The relic that you wish to add.
Line 322: Line 316:
=== Examples ===
=== Examples ===
<syntaxhighlight lang="js">
<syntaxhighlight lang="js">
let realm = game.realms.getObjectByID('melvorD:Melvor');
let realm = game.realms.getObjectSafe('melvorD:Melvor');
let relicSet = game.woodcutting.ancientRelicSets.get(realm);
let relicSet = game.woodcutting.ancientRelicSets.get(realm);
let relic = relicSet.relicDrops[0].relic;
let relic = relicSet.relicDrops[0].relic;
Line 374: Line 368:
! Attribute !! Type !! Optional? !! Description
! Attribute !! Type !! Optional? !! 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.
| dungeon || object || No || The dungeon you wish to add a completion to. Obtained with <syntaxhighlight lang="js" inline>game.dungeons.getObjectSafe(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>.
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>.
Line 385: Line 379:
=== Examples ===
=== Examples ===
<syntaxhighlight lang="js">
<syntaxhighlight lang="js">
  let dungeon = game.dungeons.getObjectByID('melvorF:Into_the_Mist');
  let dungeon = game.dungeons.getObjectSafe('melvorF:Into_the_Mist');
  if (dungeon !== undefined)
  game.combat.player.manager.addDungeonCompletion(dungeon);
game.combat.player.manager.addDungeonCompletion(dungeon);
else console.error('Dungeon is invalid');


  let dungeon = game.dungeons.getObjectByID('melvorItA:Into_The_Abyss')
  let dungeon = game.dungeons.getObjectSafe('melvorItA:Into_The_Abyss')
  if (dungeon !== undefined)
  game.combat.player.manager.setDungeonCompleteCount(dungeon, 15);
game.combat.player.manager.setDungeonCompleteCount(dungeon, 15);
else console.error('Dungeon is invalid');
</syntaxhighlight>
</syntaxhighlight>
The first example will add a single completion to {{ZoneIcon|Into the Mist}} while the second example will set {{ZoneIcon|Into the Abyss}} completions to 15.
The first example will add a single completion to {{ZoneIcon|Into the Mist}} while the second example will set {{ZoneIcon|Into the Abyss}} completions to 15.