feat: Add JavaScript examples

This commit is contained in:
Mangiang 2022-05-16 14:59:55 -04:00
parent 93e3c05838
commit eaaaf99d6b
2705 changed files with 205 additions and 0 deletions

View File

@ -0,0 +1,8 @@
{
"name": "LogToConsole",
"version": "1.0.0",
"main": "src/mod.js",
"license": "MIT",
"author": "Chomp",
"akiVersion": "2.4.0"
}

View File

@ -0,0 +1,19 @@
class Mod
{
// Code added here will load BEFORE the server has started loading
load(container)
{
// get the logger from the server container
const logger = container.resolve("WinstonLogger");
logger.info("I am logging info!");
logger.warning("I am logging a warning!");
logger.error("I am logging an error!");
}
// Code added here will be run AFTER the server has started
delayedLoad(container)
{ return }
}
module.exports = { mod: new Mod() }

View File

@ -0,0 +1,8 @@
{
"name": "EditDatabase",
"version": "1.0.0",
"main": "src/mod.js",
"license": "MIT",
"author": "Chomp",
"akiVersion": "2.4.0"
}

View File

@ -0,0 +1,28 @@
class Mod
{
// not used for this example
load(container)
{ return }
delayedLoad(container)
{
// get database from server
const databaseServer = container.resolve("DatabaseServer");
// Get all the in-memory json found in /assets/database
const tables = databaseServer.getTables();
// find the ledx item by its Id
const ledx = tables.templates.items["5c0530ee86f774697952d952"];
// 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;
}
}
module.exports = { mod: new Mod() }

View File

@ -0,0 +1,8 @@
{
"name": "GetSptConfigFile",
"version": "1.0.0",
"main": "src/mod.js",
"license": "MIT",
"author": "Chomp",
"akiVersion": "2.4.0"
}

View File

@ -0,0 +1,30 @@
class Mod
{
// not used for this example
load(container)
{ return }
delayedLoad(container)
{
// get logger
const logger = container.resolve("WinstonLogger");
// get the config server
const configServer = container.resolve("ConfigServer");
// Request bot config
// Required - ConfigTypes.BOT is the enum of the config we want, others include ConfigTypes.Airdrop
const botConfig = configServer.getConfig("aki-bot");
// log the original pmc difficulty
logger.info(`here is the original bot pmc difficulty: ${botConfig.pmc.difficulty}`)
// adjust the difficulty
botConfig.pmc.difficulty = "easy";
// log the new pmc difficulty
logger.info(`here is the altered bot pmc difficulty: ${botConfig.pmc.difficulty}`)
}
}
module.exports = { mod: new Mod() }

View File

@ -0,0 +1,8 @@
{
"name": "EditDatabase",
"version": "1.0.0",
"main": "src/mod.js",
"license": "MIT",
"author": "Chomp",
"akiVersion": "2.4.0"
}

View File

@ -0,0 +1,19 @@
const modConfig = require("../config/config.json");
class Mod
{
// not used for this example
load(container)
{ return }
delayedLoad(container)
{
// get logger
const logger = container.resolve("WinstonLogger");
// log the 'myProperty' value to the console
logger.info(`here is the value from my config: ${modConfig.myProperty}`);
}
}
module.exports = { mod: new Mod() }

View File

@ -0,0 +1,8 @@
{
"name": "ReplaceFunction",
"version": "1.0.0",
"main": "src/mod.js",
"license": "MIT",
"author": "Chomp",
"akiVersion": "2.4.0"
}

View File

@ -0,0 +1,24 @@
class Mod
{
// Perform these actions before server fully loads
load(container)
{
// get watermarkLocale class from server
const watermarkLocale = container.resolve("WatermarkLocale");
// Replace the getDescription() function with the one below called 'replacementFunction()'
watermarkLocale.getDescription = this.replacementFunction;
}
// not used for this example
delayedLoad(container)
{ return }
// our new replacement function, ready to be used
replacementFunction()
{
return ["SPT AKI, WOW VERY COOL"];
}
}
module.exports = { mod: new Mod() }

View File

@ -0,0 +1,8 @@
{
"name": "EditDatabase",
"version": "1.0.0",
"main": "src/mod.js",
"license": "MIT",
"author": "Chomp",
"akiVersion": "2.4.0"
}

View File

@ -0,0 +1,9 @@
class MoreCode
{
getTheWordFlub()
{
return "flub";
}
}
module.exports = { MoreCode: new MoreCode()}

View File

@ -0,0 +1,25 @@
const MoreCode = require("./MoreCode");
class Mod
{
// not used for this example
load(container)
{ return }
delayedLoad(container)
{
// get logger
const logger = container.resolve("WinstonLogger");
// Make a new instance of the 'MoreCode' class
const moreCode = new MoreCode();
// call the function 'getTheWordFlub()' and assign the result to 'result'
const result = moreCode.getTheWordFlub();
// log the 'myProperty' property to the console
logger.info(`Here is the value from my second class: ${result}`);
}
}
module.exports = { mod: new Mod() }

Some files were not shown because too many files have changed in this diff Show More