diff --git a/TypeScript/2EditDatabase/src/mod.ts b/TypeScript/2EditDatabase/src/mod.ts index 3dc1bdf..7d2bfb8 100644 --- a/TypeScript/2EditDatabase/src/mod.ts +++ b/TypeScript/2EditDatabase/src/mod.ts @@ -1,54 +1,58 @@ import { DependencyContainer } from "tsyringe"; import { IPostDBLoadMod } from "@spt/models/external/IPostDBLoadMod"; -import { DatabaseServer } from "@spt/servers/DatabaseServer"; -import { IDatabaseTables } from "@spt/models/spt/server/IDatabaseTables"; +import { DatabaseService } from "@spt/services/DatabaseService"; import { ItemHelper } from "@spt/helpers/ItemHelper"; import { BaseClasses } from "@spt/models/enums/BaseClasses"; -class Mod implements IPostDBLoadMod -{ +class Mod implements IPostDBLoadMod { public postDBLoad(container: DependencyContainer): void { - // get database from server - const databaseServer = container.resolve("DatabaseServer"); + // Get database service from server + const databaseService = container.resolve("DatabaseService"); - // Get all the in-memory json found in /assets/database - const tables: IDatabaseTables = databaseServer.getTables(); + // Get all the in-memory item data found in /assets/database/templates/items.json + const itemsInDb = databaseService.getItems(); - // --------------------------------------------------------- - // example #1 - // Make the LEDX item sellable on flea market + // ------------------------------------------------------------------ + // Example #1 + // Make the LedX item sellable on flea market - // Find the ledx item by its Id - const ledx = tables.templates.items["5c0530ee86f774697952d952"]; + // Find the LedX item by its Id + const ledx = itemsInDb["5c0530ee86f774697952d952"]; // The long string of characters is the ledx Id, you can find these Ids via: https://db.sp-tarkov.com/search - // Update one of its properties to be true + // Update the LedX `CanSellOnRagfair` property to be true + // This will alter ALL LedX items ledx._props.CanSellOnRagfair = true; - // --------------------------------------------------------- - // example #2 - // Get globals settings and set flea market min level to be 1 - tables.globals.config.RagFair.minUserLevel = 1; + // ------------------------------------------------------------------ + // Example #2 + // Set flea market min level to be 1 for all players - // --------------------------------------------------------- + // Get globals data from database + const globals = databaseService.getGlobals(); + + // Set ragfair property `minUserLevel` to 1 + globals.config.RagFair.minUserLevel = 1; + + // ------------------------------------------------------------------ // Example #3 - // Loop over all magazines and make them weigh nothing + // Loop over all magazines in database and make them weigh nothing - // Get ItemHelper ready to use + // Prepare the ItemHelper class so we can use it const itemHelper: ItemHelper = container.resolve("ItemHelper"); // Get all items in the database as an array so we can loop over them later - // tables.templates.items is a dictionary, the key being the items template id, the value being the objects data, - // we want to convert it into an array so we can loop over all the items easily + // `databaseService.getItems()` returns a dictionary, the key being the items template id, the value being the item itself, + // We want to convert it into an array so we can loop over all the items easily // Object.values lets us grab the 'value' part as an array and ignore the 'key' part - const items = Object.values(tables.templates.items); + const items = Object.values(itemsInDb); - // Use the itemHelper class to assist us in getting only magazines + // Use the `ItemHelper` class to assist us in getting only magazines // We are filtering all items to only those with a base class of MAGAZINE (5448bc234bdc2d3c308b4569) const magazines = items.filter(x => itemHelper.isOfBaseclass(x._id, BaseClasses.MAGAZINE)); - // Loop over all the magazines the above code found + // Loop over all the magazines we found using above code for (const magazine of magazines) { // Check the magazine has a weight property before we edit it @@ -58,6 +62,17 @@ class Mod implements IPostDBLoadMod magazine._props.Weight = 0; } } + + // ------------------------------------------------------------------ + // Example #4 + // Adjust the red keycards flea price to be one million + + // Get all flea prices + // The prices are stored as a dictionary too, the key is the items ID, the value is the rouble price + const fleaPrices = databaseService.getPrices(); + + // Edit the red keycard price + fleaPrices["5c1d0efb86f7744baf2e7b7b"] = 1000000; // We can use this site to find item Ids: https://db.sp-tarkov.com/search } }