### Defining and Rolling a Loot Table - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Shows how to construct a LootTable object with different types of drops (standard weighted, one-in, tertiary) and then simulate rolling the table to get results. ```JavaScript const CorporealBeastTable = new LootTable() .add('Spirit shield', 1, 8) .add('Holy elixir', 1, 3) oneIn(585, SigilTable) tertiary(5000, 'Pet dark core'); CorporealBeastTable.roll(); ``` -------------------------------- ### Simulating Corporeal Beast Kills - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Provides multiple ways to simulate killing the Corporeal Beast 100 times: accessing it directly by property, finding it by alias, and getting it by ID. ```JavaScript Monsters.CorporealBeast.kill(100); Monsters.find(monster => monster.name.aliases.includes('corp')).kill(100); Monsters.get(319).kill(100); ``` -------------------------------- ### Getting OSRS Item by Name - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Retrieves an item object using its exact name string. The example includes a check to ensure the item was successfully found before logging. ```JavaScript const dragonDagger = Items.get('dragon dagger(p++)'); if (dragonDagger) console.log(dragonDagger); ``` -------------------------------- ### Getting OSRS Item by ID - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Retrieves an item object from the library's data store using its unique numeric ID. The example checks if the item was found before logging it. ```JavaScript const twistedBow = Items.get(20997); if (twistedBow) console.log(twistedBow); ``` -------------------------------- ### Count Users and Sum Item Quantity in Bank (Specific Item) - SQL Source: https://github.com/oldschoolgg/oldschooljs/blob/master/update-history/item-update-2024-10-1.txt This SQL query counts the number of users who possess a specific item (identified by ID '0' in this example) in their bank and calculates the total quantity of that item across all users. It assumes the 'bank' column is a JSONB type where keys are item IDs and values are quantities. ```SQL SELECT COUNT(*) FILTER (WHERE bank->>'0' IS NOT NULL) AS people_with_item_0, SUM((bank->>'0')::int) AS sum_item_0, FROM users; ``` -------------------------------- ### Calculate Total Quantity of Specific Items Per User - SQL Source: https://github.com/oldschoolgg/oldschooljs/blob/master/update-history/item-update-2024-10-1.txt This SQL query calculates the total quantity of a list of specific items (identified by IDs in the ARRAY[0] example) held by each user. It iterates through the 'bank' JSONB column using jsonb_each_text, filters for the specified item IDs, and sums the quantities per user ID. ```SQL SELECT id, SUM(kv.value::int) AS total_quantity FROM users, jsonb_each_text(bank::jsonb) AS kv(itemID, value) WHERE itemID::int = ANY(ARRAY[0]::int[]) GROUP BY id ``` -------------------------------- ### Searching OSRS Wiki Pages - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Demonstrates how to perform a search query against the OSRS Wiki using the Wiki.search method and process the results, logging the titles of found pages. ```JavaScript const searchResults = await Wiki.search('Twisted bow'); if (searchResults.length === 0) console.log('Found no results'); else console.log(`Search found these pages: ${searchResults.map(page => page.title)}`); ``` -------------------------------- ### Simulating Clue Scroll Openings - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Demonstrates how to simulate opening different tiers of clue scroll caskets (Beginner, Master, Elite) using the open method, optionally specifying the number of caskets. ```JavaScript console.log(Clues.Beginner.open(1)); console.log(Clues.Master.open(5)); console.log(Clues.Elite.open()); ``` -------------------------------- ### Importing Wiki Class - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Imports the Wiki class from the oldschooljs library, enabling interaction with the OSRS Wiki API. ```JavaScript import { Wiki } from 'oldschooljs'; ``` -------------------------------- ### Using the Bank Class - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Illustrates various methods for adding items to a Bank object, including adding by name, ID, object literal, another Bank instance, a LootTable roll, and the result of a monster kill simulation. ```JavaScript const bank = new Bank().add('Twisted bow'); const otherBank = new Bank().add('Coal'); const lootTable = new LootTable().add(; bank .add(otherBank) .add({ Coal: 1 }) .add('Coal') .add('Coal', 500) .add({ 124: 500 }) .add(lootTable.roll()) .add(CorporealBeast.kill()); console.log(bank.values()); ``` -------------------------------- ### Simulating Kills for All Monsters - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Shows how to simulate killing every monster available in the library's data store a specified number of times (100 in this case) using the map function. ```JavaScript Monsters.map(monster => monster.kill(100)); ``` -------------------------------- ### Picking Random OSRS Wiki Pages - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Shows how to fetch a specified number of random pages from the OSRS Wiki using the Wiki.random method. ```JavaScript const randomPages = await Wiki.random(10); console.log(`Search found these pages: ${searchResults.map(page => page.title)}`); ``` -------------------------------- ### Fetching OSRS Hiscores - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Demonstrates how to import the Hiscores class and fetch player data. It shows fetching for a normal account and an ironman account, highlighting the option to specify account type. ```JavaScript import { Hiscores } from 'oldschooljs'; const lynxTitan = await Hiscores.fetch('Lynx Titan'); const ironHyger = await Hiscores.fetch('Iron Hyger', { type: 'ironman' }); ``` -------------------------------- ### Converting Numbers from KMB Syntax - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Illustrates how to use the Util.fromKMB function to parse KMB formatted strings back into their corresponding numeric values. ```JavaScript Util.fromKMB('5'); // 5 Util.fromKMB('1k'); // 1000 Util.fromKMB('1m'); // 1000000 Util.fromKMB('1.2b'); // 1200000000 ``` -------------------------------- ### Converting Numbers to KMB Syntax - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Shows how to use the Util.toKMB function to convert standard numeric values into the KMB (Thousands, Millions, Billions) string format commonly used in RuneScape. ```JavaScript Util.toKMB(5); // '5' Util.toKMB(1000); // '1k' Util.toKMB(1000000); // '1m' Util.toKMB(1200000000); // '1.2b' ``` -------------------------------- ### Fetching OSRS Wiki Page by ID - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Illustrates how to retrieve a specific OSRS Wiki page directly using its unique page ID with the Wiki.fetchPage method. ```JavaScript const twistedBowPage = await Wiki.fetchPage(82098); console.log(twistedBowPage); ``` -------------------------------- ### Importing Util Class - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Imports the Util class from the oldschooljs library, which contains various utility functions. ```JavaScript import { Util } from 'oldschooljs'; ``` -------------------------------- ### Importing Clues Class - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Imports the Clues class from the oldschooljs library, which is used for simulating the opening of clue scroll caskets. ```JavaScript import { Clues } from 'oldschooljs'; ``` -------------------------------- ### Importing Items Class - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Imports the necessary Items class from the oldschooljs library to interact with item data. ```JavaScript import { Items } from 'oldschooljs'; ``` -------------------------------- ### Importing Monsters Class - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Imports the Monsters class from the oldschooljs library, which is used for simulating monster kills and accessing monster data. ```JavaScript import { Monsters } from 'oldschooljs'; ``` -------------------------------- ### Filtering OSRS Items by Properties - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Demonstrates how to use the filter method on the Items collection to find items matching specific criteria, such as having 'Dragon' in their name. It then logs the count and names of the found items. ```JavaScript const dragonItems = Items.filter(item => item.name.includes('Dragon')); console.log(`Found ${dragonItems.size} Dragon Items!`); for (const item of dragonItems.values()) { console.log(item.name); } ``` -------------------------------- ### Checking OSRS Username Validity - JavaScript Source: https://github.com/oldschoolgg/oldschooljs/blob/master/README.md Demonstrates using the Util.isValidUsername function to check if a given string conforms to the valid format for an Old School RuneScape username. ```JavaScript console.log(Util.isValidUsername(username)); // true ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.