Add extra example to mod #2
This commit is contained in:
parent
08213cbfcd
commit
22cff3d0ba
@ -2,6 +2,9 @@ import { DependencyContainer } from "tsyringe";
|
|||||||
|
|
||||||
import { IPostDBLoadMod } from "@spt-aki/models/external/IPostDBLoadMod";
|
import { IPostDBLoadMod } from "@spt-aki/models/external/IPostDBLoadMod";
|
||||||
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
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
|
class Mod implements IPostDBLoadMod
|
||||||
{
|
{
|
||||||
@ -9,9 +12,14 @@ class Mod implements IPostDBLoadMod
|
|||||||
{
|
{
|
||||||
// get database from server
|
// get database from server
|
||||||
const databaseServer = container.resolve<DatabaseServer>("DatabaseServer");
|
const databaseServer = container.resolve<DatabaseServer>("DatabaseServer");
|
||||||
|
|
||||||
|
|
||||||
// Get all the in-memory json found in /assets/database
|
// 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
|
// Find the ledx item by its Id
|
||||||
const ledx = tables.templates.items["5c0530ee86f774697952d952"];
|
const ledx = tables.templates.items["5c0530ee86f774697952d952"];
|
||||||
@ -19,10 +27,34 @@ class Mod implements IPostDBLoadMod
|
|||||||
// Update one of its properties to be true
|
// Update one of its properties to be true
|
||||||
ledx._props.CanSellOnRagfair = true;
|
ledx._props.CanSellOnRagfair = true;
|
||||||
|
|
||||||
|
// ---------------------------------------------------------
|
||||||
// example #2
|
// example #2
|
||||||
// get globals settings and set flea market min level to be 1
|
// get globals settings and set flea market min level to be 1
|
||||||
tables.globals.config.RagFair.minUserLevel = 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>("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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user