• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Spells Parser - Configurable - Any TFS / OTX Version

Void_

Banned User
Joined
Jan 7, 2018
Messages
9
Reaction score
12
This script will produce a file which is a table of all the spells in your spells.xml file. Which you can then reference via scripts. You will need a lua interpreter to run this script or you can integrate it with your server by calling the method parseSpells()
Lua:
function cwd(name)
    local chr = os.tmpname():sub(1,1)
    if chr == "/" then
      -- linux
      chr = "/[^/]*$"
    else
      -- windows
      chr = "\\[^\\]*$"
    end
    return arg[0]:sub(1, arg[0]:find(chr))..(name or '')
end

function isNumber(v)
    local val = tonumber(v)
    if type(val) == 'number' then
        return val
    end
    return '"'..v..'"'
end

function insert(t, i, v)
    if type(i) == 'number' then
        table.insert(t, i, v)
    else
        if not t[i] then
            t[i] = v
        end
    end
end

local dir = 'data/spells/'
local path = cwd(dir..'spells.xml')

local fileEx = cwd(dir..'spellsTable.lua')
local outputFile = fileEx
local storage = 1000
local spells = {}
local para = {
    'name', 'words', 'lvl', 'level', 'mana', 'prem', 'range', 'needtarget', 'blockwalls',
    'needweapon', 'exhaustion', 'groupcooldown', 'casterTargetOrDirection', 'aggressive', 'needlearn',
    'selftarget', 'script', 'charges', 'maglv', 'soul'
    }
function parseSpells()
    local file = path
    fileEx = io.open(fileEx, "w+")
    local k = {}
    fileEx:write("SPELLS = {\n")
    for line in io.lines(file) do
        if string.match(line, '<(%a-)%s* ') ~= nil then
            spellParam =  string.match(line, '<(%a-)%s* ')
            if spellParam ~= nil and spellParam ~= 'vocation' then
                for type_ in line:gmatch(spellParam) do
                    local sName = ''
                    for i = 1, #para do
                        if line:match(para[i]..'="(.-)"') then
                            if para[i] == 'name' then
                              sName = line:match('name="(.-)"')
                            else
                              table.insert(k, para[i]..' = '..isNumber(line:match(para[i]..'="(.-)"'))..', ')
                            end
                        end
                    end
                    local temp = '{\n\t\t'..table.concat(k)
                    temp = temp:sub(1, #temp - 2)
                    k = {}
                    insert(spells, sName, temp)
                end
            end
        end
    end
    local n = 1
    for k, v in pairs(spells)do
        fileEx:write("\t[\""..k.."\"] = "..v..", storage = ".. (storage + n) .."\n\t},\n")
        n = n + 1
    end
    fileEx:write("}")
    fileEx:close()
end
parseSpells()

Example of the table it produces:
Lua:
SPELLS = {
   ["Wound Cleansing"] = {
       words = "exura ico", level = 8, mana = 40, groupcooldown = 1000, aggressive = 0, needlearn = 0, selftarget = 1, script = "healing/wound_cleansing.lua", storage = 1001
   },
   ["Conjure Poisoned Arrow"] = {
       words = "exevo con pox", level = 16, mana = 130, groupcooldown = 2000, aggressive = 0, needlearn = 0, selftarget = 1, script = "conjuring/conjure_poisoned_arrow.lua", soul = 2, storage = 1002
   },
   ["Stalagmite Rune"] = {
       level = 24, needtarget = 1, groupcooldown = 2000, script = "attack/stalagmite_rune.lua", charges = 10, storage = 1003
   },
 
Back
Top