From 22cff3d0baee65c52106a4cd90952ce685d1c065 Mon Sep 17 00:00:00 2001 From: Dev Date: Wed, 29 Nov 2023 14:01:28 +0000 Subject: [PATCH] Add extra example to mod #2 --- TypeScript/2EditDatabase/src/mod.ts | 36 +++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/TypeScript/2EditDatabase/src/mod.ts b/TypeScript/2EditDatabase/src/mod.ts index 8289415..781cb24 100644 --- a/TypeScript/2EditDatabase/src/mod.ts +++ b/TypeScript/2EditDatabase/src/mod.ts @@ -2,6 +2,9 @@ import { DependencyContainer } from "tsyringe"; import { IPostDBLoadMod } from "@spt-aki/models/external/IPostDBLoadMod"; import { DatabaseServer } from "@spt-aki/servers/DatabaseServer"; +import { IDatabaseTables } from "@spt-aki/models/spt/server/IDatabaseTables"; +import { ItemHelper } from "@spt-aki/helpers/ItemHelper"; +import { BaseClasses } from "@spt-aki/models/enums/BaseClasses"; class Mod implements IPostDBLoadMod { @@ -9,9 +12,14 @@ class Mod implements IPostDBLoadMod { // get database from server const databaseServer = container.resolve("DatabaseServer"); + // Get all the in-memory json found in /assets/database - const tables = databaseServer.getTables(); + const tables: IDatabaseTables = databaseServer.getTables(); + + // --------------------------------------------------------- + // example #1 + // Make the LEDX item sellable on flea market // Find the ledx item by its Id const ledx = tables.templates.items["5c0530ee86f774697952d952"]; @@ -19,10 +27,34 @@ class Mod implements IPostDBLoadMod // Update one of its properties to be true 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 #3 + // Loop over all magazines and make them weigh nothing + + // Get ItemHelper ready to use + const itemHelper: ItemHelper = container.resolve("ItemHelper"); + // Get all items in the database as an array so we can loop over them later + const items = Object.values(tables.templates.items); + + // Use the itemHelper class to assist us in getting only magazines + // We are filtering all tiems 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 + for (const magazine of magazines) + { + // Check the magazine has a weight property before we edit it + if (magazine._props.Weight) + { + // Set its weight to 0 + magazine._props.Weight = 0; + } + } } }