Skip to content

LuaAPI Config Files

itvnnnd87 edited this page Oct 24, 2026 · 3 revisions

Reading config files (XML / INI / TXT / Lua)

Paths

Path Relative to
"Includes\\ABC\\abc.xml" The Data\LuaAPI\ folder
"..\\Data\\Event\\abc.xml" Starts with ..: the GameServer folder

A path with a drive letter ("D:\\...") is used as it is.

If the file cannot be read, File.ReadText, File.ReadIni and File.ReadXml return nil and an error message:

local cfg, err = File.ReadXml("Includes\\ABC\\abc.xml")
if cfg == nil then Log.AddC(1, err) return end

File

File.Exists

File.Exists(path) → boolean

true if the file exists. false if it does not exist or the path is a folder.

local path = "Includes\\ABC\\abc.xml"
if not File.Exists(path) then
    Log.AddC(3, "[ABC] " .. path .. " not found, using default settings")
end

File.ReadText

File.ReadText(path) → table or nil, string

Table of lines: { "line 1", "line 2", ... }. Line ends (\r\n) and the UTF-8 BOM are removed. Empty lines are kept as "".

local lines, err = File.ReadText("Includes\\ABC\\news.txt")
if lines == nil then Log.AddC(1, err) return end
for _, line in ipairs(lines) do
    if line ~= "" then Message.Send(aIndex, 1, line) end
end

File.ReadIni

File.ReadIni(path) → table or nil, string

Returns { [Section] = { Key = "Value" } }. Lines starting with ; or # are comments. Keys outside any section go into [""]. Keys and values are trimmed, quotes around a value are removed. Values are always strings.

[Reward]
Rate = 2
local ini = File.ReadIni("Includes\\ABC\\abc.ini")
local rate = 1
if ini ~= nil and ini["Reward"] ~= nil then
    rate = tonumber(ini["Reward"]["Rate"]) or 1
end

INI values can also be read and written one by one with Config.ReadNumber, Config.ReadString and Config.SaveString (Function reference).

File.ReadXml

File.ReadXml(path) → table or nil, string

Returns the root tag as:

root = {
    name = "TagName",                       -- tag name
    attr = { Attribute = "value" },         -- attributes
    kids = { --[[ child tags, same shape ]] },
    text = "text inside the tag",
}

Attribute values are always strings; use tonumber() when you need a number. On a parse error the message gives the error and its offset in the file. Very deep nesting is refused with an error.

<Reward>
    <Item Index="6181" Level="15" Count="1"/>
</Reward>
local root = File.ReadXml("Includes\\ABC\\abc.xml")

for _, node in ipairs(root.kids) do
    if node.name == "Item" then
        local index = tonumber(node.attr.Index)
    end
end

Lua files

LoadScript

LoadScript(path) → nothing

Runs a Lua file every time it is called (path rules as above). Returns nothing. If the file cannot be loaded or raises an error, the error is passed to the calling script; use pcall to catch it.

local ok, err = pcall(LoadScript, "Includes\\ABC\\Config.lua")
if not ok then
    Log.AddC(1, "[ABC] config error: " .. tostring(err))
end

require("ABC\\Config") loads a Lua file only once.


Next: Database

Clone this wiki locally