feat: Add JavaScript examples
This commit is contained in:
parent
93e3c05838
commit
eaaaf99d6b
8
JavaScript/1LogToConsole/package.json
Normal file
8
JavaScript/1LogToConsole/package.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "LogToConsole",
|
||||
"version": "1.0.0",
|
||||
"main": "src/mod.js",
|
||||
"license": "MIT",
|
||||
"author": "Chomp",
|
||||
"akiVersion": "2.4.0"
|
||||
}
|
19
JavaScript/1LogToConsole/src/mod.js
Normal file
19
JavaScript/1LogToConsole/src/mod.js
Normal 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() }
|
8
JavaScript/2EditDatabase/package.json
Normal file
8
JavaScript/2EditDatabase/package.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "EditDatabase",
|
||||
"version": "1.0.0",
|
||||
"main": "src/mod.js",
|
||||
"license": "MIT",
|
||||
"author": "Chomp",
|
||||
"akiVersion": "2.4.0"
|
||||
}
|
28
JavaScript/2EditDatabase/src/mod.js
Normal file
28
JavaScript/2EditDatabase/src/mod.js
Normal 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() }
|
8
JavaScript/3.0GetSptConfigFile/package.json
Normal file
8
JavaScript/3.0GetSptConfigFile/package.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "GetSptConfigFile",
|
||||
"version": "1.0.0",
|
||||
"main": "src/mod.js",
|
||||
"license": "MIT",
|
||||
"author": "Chomp",
|
||||
"akiVersion": "2.4.0"
|
||||
}
|
30
JavaScript/3.0GetSptConfigFile/src/mod.js
Normal file
30
JavaScript/3.0GetSptConfigFile/src/mod.js
Normal 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() }
|
8
JavaScript/4UseACustomConfigFile/package.json
Normal file
8
JavaScript/4UseACustomConfigFile/package.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "EditDatabase",
|
||||
"version": "1.0.0",
|
||||
"main": "src/mod.js",
|
||||
"license": "MIT",
|
||||
"author": "Chomp",
|
||||
"akiVersion": "2.4.0"
|
||||
}
|
19
JavaScript/4UseACustomConfigFile/src/mod.js
Normal file
19
JavaScript/4UseACustomConfigFile/src/mod.js
Normal 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() }
|
8
JavaScript/5ReplaceMethod/package.json
Normal file
8
JavaScript/5ReplaceMethod/package.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "ReplaceFunction",
|
||||
"version": "1.0.0",
|
||||
"main": "src/mod.js",
|
||||
"license": "MIT",
|
||||
"author": "Chomp",
|
||||
"akiVersion": "2.4.0"
|
||||
}
|
24
JavaScript/5ReplaceMethod/src/mod.js
Normal file
24
JavaScript/5ReplaceMethod/src/mod.js
Normal 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() }
|
8
JavaScript/6ReferenceAnotherClass/package.json
Normal file
8
JavaScript/6ReferenceAnotherClass/package.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "EditDatabase",
|
||||
"version": "1.0.0",
|
||||
"main": "src/mod.js",
|
||||
"license": "MIT",
|
||||
"author": "Chomp",
|
||||
"akiVersion": "2.4.0"
|
||||
}
|
9
JavaScript/6ReferenceAnotherClass/src/MoreCode.js
Normal file
9
JavaScript/6ReferenceAnotherClass/src/MoreCode.js
Normal file
@ -0,0 +1,9 @@
|
||||
class MoreCode
|
||||
{
|
||||
getTheWordFlub()
|
||||
{
|
||||
return "flub";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { MoreCode: new MoreCode()}
|
25
JavaScript/6ReferenceAnotherClass/src/mod.js
Normal file
25
JavaScript/6ReferenceAnotherClass/src/mod.js
Normal 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
Loading…
x
Reference in New Issue
Block a user