Plugin config
Declare typed config in package.json under s2script.config. The host materializes defaults ⊕ an admin-editable JSON override at load.
{
"s2script": {
"config": {
"greeting": { "type": "string", "default": "hello", "description": "Chat greeting" },
"maxUses": { "type": "int", "default": 3 },
"enabled": { "type": "bool", "default": true }
}
}
} Supported types: string, int, float, bool. Wrong-typed override values degrade to the default and log a warning — never crash.
Reading values
import { config } from '@s2script/config';
export function onLoad() {
const greeting = config.getString('greeting');
const maxUses = config.getInt('maxUses');
const enabled = config.getBool('enabled');
} Undeclared keys return the type’s zero value (empty string / 0 / false), never throw.
Live reload
Opt in by subscribing — the first onChange starts watching the override file. Edits re-materialize and fire handlers without reloading the plugin:
config.onChange((cfg) => {
console.log('config changed', cfg);
}); No subscriber → config is read once at load (zero watch overhead).
Raw files
config.readFile / config.writeFile read and write plain files under addons/s2script/configs/ (e.g. maplist.txt). Names are sanitized; path traversal is rejected.
Override files live at addons/s2script/configs/<plugin-id>.json and are auto-generated on first load with defaults and // comments.
See the config module.