Codex NG
Recurrent Flamer
- Joined
- Jul 24, 2015
- Messages
- 2,994
- Solutions
- 12
- Reaction score
- 1,657
Completely re-written
Based on @zbizu item parser
https://otland.net/threads/tfs-1-1-items-parser-useful-for-searching-ids.228705/
It was bothering me all day at work that i didn't include the vocations in the script so i woke up early and re-wrote it
It isn't completely perfect tho, but its on the todo list hehe
Based on @zbizu item parser
https://otland.net/threads/tfs-1-1-items-parser-useful-for-searching-ids.228705/
It was bothering me all day at work that i didn't include the vocations in the script so i woke up early and re-wrote it
It isn't completely perfect tho, but its on the todo list hehe
Code:
-- Credits to zbizu for using the code based on his item parser
-- https://otland.net/threads/tfs-1-1-items-parser-useful-for-searching-ids.228705/
-- Credits to me Codex NG for making the changes in this script to extract almost everything in the spells.xml
local p, spells = {}, {}
function parseSpells()
local file = 'data/spells/spells.xml'
local fileEx = 'spells.lua'
local outputFile = fileEx
local types = {
['instant'] = 'name="(.-)" words="(.-)" lvl="(%d+)" mana="(%d+)"',
['conjure'] = 'name="(.-)" words="(.-)" lvl="(%d+)" mana="(%d+)"',
['rune'] = 'name="(.-)" id="(%d+)" allowfaruse="(%d+)" charges="(%d+)" lvl="(%d+)" maglv="(%d+)" exhaustion="(%d+)"',
['vocation'] = 'id="(%d+)"'
}
local index = 0
local text = ''
-- vocations from 1 - 8
local vocs = {min = 1, max = 8}
-- returns a table of all the vocations based on vocs min and max values
local function AllVocs()
local o = ''
for i = vocs['min'], vocs['max'] do
if i ~= vocs['max'] then
o = o..i..', '
else
o = o..i
end
end
return o
end
for line in io.lines(file) do
-- make sure line isn't empty
if string.match(line, '<(%a-)%s* ') ~= nil then
-- use the 1st string to indicate which index of the types we want to retrieve,
-- basically we are taking everything, rune, conjure, instant
spellParam = types[string.match(line, '<(%a-)%s* ')]
-- now we can retrieve the data from the line as needed, based on the index selected
for type_, p1, p2, p3, p4, p5, p6, p7 in line:gmatch('<(%a-)%s* '..spellParam) do
if type_ ~= nil then
if(type_ == 'conjure' or type_ == 'instant') then
p['types'] = type_
p['name'] = p1 -- name
p['words'] = p2 -- words
p['level'] = p3 -- level
p['mana'] = p4 -- mana
index = 0
elseif (type_ == 'rune') then
p['types'] = type_
p['name'] = p1 -- name
p['id'] = p2 -- id
p['allowfaruse'] = p3 -- allowfaruse
p['charges'] = p4 -- charges
p['lvl'] = p5 -- lvl
p['maglvl'] = p6 -- maglvl
p['exhaust'] = p7 -- exhaust
index = 0
p['vocs_'] = p['vocs'] ~= '' and p['vocs'] or AllVocs() -- all the vocations
table.insert(spells, {types = p['types'], name = p['name'], id = p['id'], allowfaruse = p['allowfaruse'], charges = p['charges'], lvl = p['lvl'], maglvl = p['maglvl'], exhaust = p['exhaust'], vocs = p['vocs_']})
elseif (type_ == 'vocation') then
if index == 0 then
table.insert(spells, {types = p['types'], name = p['name'], words = p['words'], level = p['level'], mana = p['mana'], vocs = p['vocs']})
p['vocs'] = ''
p['vocs'] = p1 -- id
elseif index > 0 then
p['vocs'] = p['vocs']..', '..p1
end
index = index + 1
end
end
end
end
end
fileEx = io.open(fileEx, "w+")
fileEx:write("\tlocal spells = {\n")
for x = 1, #spells do
if spells[x].types == 'rune' and spells[x].vocs ~= nil and spells[x].maglvl ~= nil then
text = text.. "\t\t{ type_ = \""..spells[x].types.."\", name = \""..spells[x].name.."\", id = "..spells[x].id..", allowfaruse = "..spells[x].allowfaruse..", charges = "..spells[x].charges..", level = "..spells[x].lvl..", exhaust = "..spells[x].exhaust..", maglvl = "..spells[x].maglvl..", vocs = {"..spells[x].vocs.."} },\n"
elseif spells[x].types == 'conjure' or spells[x].types == 'instant' then
text = text.. "\t\t{ type_ = \""..spells[x].types.."\", name = \""..spells[x].name.."\", words = \""..spells[x].words.."\", level = "..spells[x].level..", mana = "..spells[x].mana..", vocs = {"..spells[x].vocs.."} },\n"
end
end
text = string.sub(text, 1, string.len(text)-2) -- this just removes the last comma in the table
text = text .. "\n\t}"
fileEx:write(text)
fileEx:close()
end
parseSpells()
Last edited: