From aec9c8a066a5ba104f588e61b2f9ffcbe61a76e2 Mon Sep 17 00:00:00 2001 From: Saint Wish Date: Sun, 13 Feb 2022 15:10:54 -0700 Subject: [PATCH 1/3] load custom scripts from a json file --- scripts/config.lua | 2 ++ scripts/serverCore.lua | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/scripts/config.lua b/scripts/config.lua index 56f0e5b8..78102a46 100644 --- a/scripts/config.lua +++ b/scripts/config.lua @@ -462,5 +462,7 @@ config.recordstoreKeyOrder = { "general", "permanentRecords", "generatedRecords" config.worldKeyOrder = { "general", "time", "topics", "kills", "journal", "customVariables", "type", "index", "quest", "actorRefId", "year", "month", "day", "hour", "daysPassed", "timeScale" } + +config.customScriptsPath = "scripts.json" return config diff --git a/scripts/serverCore.lua b/scripts/serverCore.lua index c9da7425..db99016e 100644 --- a/scripts/serverCore.lua +++ b/scripts/serverCore.lua @@ -207,6 +207,23 @@ function OnServerInit() customEventHooks.triggerHandlers("OnServerInit", eventStatus, {}) end +function LoadScriptsFromJson(filename) + local scripts = jsonInterface.load(filename) + tableHelper.fixNumericalKeys(scripts, true) + + if scripts == nil then + tes3mp.LogMessage(enumerations.log.ERROR, "Script file list " .. filename .. " cannot be read!") + tes3mp.StopServer(2) + else + for index,script in ipairs(scripts) do + for name,file in pairs(script) do + require(file) + tes3mp.LogMessage(enumerations.log.INFO, "Loaded script "..name) + end + end + end +end + function OnServerPostInit() tes3mp.LogMessage(enumerations.log.INFO, "Called \"OnServerPostInit\"") local eventStatus = customEventHooks.triggerValidators("OnServerPostInit", {}) @@ -275,6 +292,7 @@ function OnServerPostInit() end tes3mp.SetRuleString("respawnCell", respawnCell) + LoadScriptsFromJson(config.customScriptsPath) end customEventHooks.triggerHandlers("OnServerPostInit", eventStatus, {}) end From 03d3bec74c97f582322a695e75e8f4e80610b415 Mon Sep 17 00:00:00 2001 From: Saint Wish Date: Sat, 19 Feb 2022 22:37:29 -0700 Subject: [PATCH 2/3] renamed scripts.json to customScripts.json --- scripts/config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/config.lua b/scripts/config.lua index 78102a46..75dae2df 100644 --- a/scripts/config.lua +++ b/scripts/config.lua @@ -463,6 +463,6 @@ config.recordstoreKeyOrder = { "general", "permanentRecords", "generatedRecords" config.worldKeyOrder = { "general", "time", "topics", "kills", "journal", "customVariables", "type", "index", "quest", "actorRefId", "year", "month", "day", "hour", "daysPassed", "timeScale" } -config.customScriptsPath = "scripts.json" +config.customScriptsPath = "customScripts.json" return config From 579af682ac94b3db3993b91cde22281e75691c11 Mon Sep 17 00:00:00 2001 From: Saint Wish Date: Sun, 20 Feb 2022 18:45:36 -0700 Subject: [PATCH 3/3] Create customScripts.json --- data/customScripts.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 data/customScripts.json diff --git a/data/customScripts.json b/data/customScripts.json new file mode 100644 index 00000000..1610ea14 --- /dev/null +++ b/data/customScripts.json @@ -0,0 +1,3 @@ +[ + +] \ No newline at end of file