Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propose: Allow custom scripts to be loaded from a JSON file. #99

Open
wants to merge 3 commits into
base: 0.8.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions data/customScripts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be valid json, and just an array is not.

{
  "customScripts": []
}

would be more acceptable in case a different json reader is used


]
2 changes: 2 additions & 0 deletions scripts/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "customScripts.json"

return config
18 changes: 18 additions & 0 deletions scripts/serverCore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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", {})
Expand Down Expand Up @@ -275,6 +292,7 @@ function OnServerPostInit()
end

tes3mp.SetRuleString("respawnCell", respawnCell)
LoadScriptsFromJson(config.customScriptsPath)
end
customEventHooks.triggerHandlers("OnServerPostInit", eventStatus, {})
end
Expand Down